diff options
-rw-r--r-- | scrsaver_test.c | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/scrsaver_test.c b/scrsaver_test.c new file mode 100644 index 0000000..452c375 --- /dev/null +++ b/scrsaver_test.c @@ -0,0 +1,136 @@ +/* gcc -g -Wall -L/usr/X11R6/lib/ -lXss -o test test.c */ + +#include <stdio.h> +#include <stdlib.h> +#include <X11/Xlib.h> +#include <X11/Xproto.h> +#include <X11/Xutil.h> +#include <X11/extensions/scrnsaver.h> + + + +Display *dpy; + +void elock_open_display(int argc, char *argv[]) +{ + char *display; + + display = getenv("DISPLAY"); + + if (!(dpy = XOpenDisplay(display))) + { + perror("Cannot open display\n"); + exit(1); + } + fprintf(stdout,"DISPLAY OPENDED\n"); +} + +int fatal(char *s) +{ + printf ("fatal: %s\n", s); + exit (1); +} + +void ignoreError (Display *dpy, XErrorEvent *error) +{ + printf ("ignoring error\n"); +} + +char *stateNames[] = { "Off", "On", "Cycle", "Disable" }; +char *kindNames[] = { "Blanked", "Internal", "External" }; + +int main(int argc, char **argv) +{ + XEvent pe; + XScreenSaverNotifyEvent *se; + Window root, saver; + int screen; + int majorVersion, minorVersion; + int error_base, event_base; + XScreenSaverInfo *info; + XSetWindowAttributes attr; + unsigned long mask; + GC gc; + + /*_Xdebug = 1;*/ /* turn on synchronization */ + + elock_open_display(argc, argv); + + if (!XScreenSaverQueryExtension (dpy, &event_base, &error_base)) + fatal ("QueryExtension failed"); + + printf ("event_base %d, error_base %d\n", event_base, error_base); + + if (!XScreenSaverQueryVersion (dpy, &majorVersion, &minorVersion)) + fatal ("QueryVersion failed"); + + printf ("majorVersion: %d, minorVersion: %d\n", majorVersion, minorVersion); + + root = DefaultRootWindow (dpy); + + info = XScreenSaverAllocInfo (); + if (!XScreenSaverQueryInfo (dpy, root, info)) + fatal ("QueryInfo"); + + + if ( stateNames[info->state] == "Disable" ) + printf("YOU YOU YOU YOU ICI"); + + printf ("|| window: 0lx%lx\n", info->window); + printf ("|| state: %s\n", stateNames[info->state]); + printf ("|| kind: %s\n", kindNames[info->kind]); + printf ("|| til_or_since: %ld\n", info->til_or_since); + printf ("|| idle: %ld\n", info->idle); + printf ("|| eventMask: 0lx%lx\n\n", info->eventMask); + saver = info->window; + XFree (info); + XScreenSaverSelectInput (dpy, root, ScreenSaverNotifyMask|ScreenSaverCycleMask); + screen = DefaultScreen(dpy); + attr.background_pixel = BlackPixel (dpy, screen); + mask = CWBackPixel; + + XScreenSaverSetAttributes (dpy, root, 0, 0, + DisplayWidth(dpy, screen), + DisplayHeight (dpy, screen), + 0, + CopyFromParent, + CopyFromParent, + CopyFromParent, + mask, &attr); + + gc = DefaultGC (dpy, screen); + XSetForeground (dpy, gc, WhitePixel(dpy, screen)); + while (1) + { + if ( ! XNextEvent(dpy, &pe)); + fprintf(stdout,"ERROR\n"); + fprintf(stdout,"DEBUG pe.type:%s\n",pe.type); + + if (pe.type == event_base) + { + se = (XScreenSaverNotifyEvent *) &pe; + printf ("ScreenSaverNotifyEvent\n"); + printf ("serial: %ld\n", se->serial); + printf ("send_event: %d\n", se->send_event); + printf ("window: %ld\n", se->window); + printf ("root: %ld\n", se->root); + printf ("state: %s\n", stateNames[se->state]); + printf ("kind: %s\n", kindNames[se->kind]); + printf ("forced: %d\n", se->forced); + printf ("time: %ld\n", se->time); + if (se->state == ScreenSaverOn && + se->kind == ScreenSaverExternal) + { +/* XSetErrorHandler (ignoreError); */ + XDrawString (dpy, saver, gc, 100, 100, "Screen Saver Test", 17); + XSync (dpy, False); +/* XSetErrorHandler (NULL); */ + } + } + else + { + printf ("unexpected event %d\n", pe.type); + } + } +} + |