Detect running screensaver using xlib

I am trying to determine if the screen saver works or not.

Here is the code that I still have:

/* LDFLAGS='-L/usr/X11R6/lib/ -lX11 -lXext -lXss' make xidle */ #include <stdio.h> #include <X11/Xlib.h> #include <X11/Xutil.h> #include <X11/extensions/scrnsaver.h> int main(int argc, char *argv[]) { XScreenSaverInfo info; Display *dpy = XOpenDisplay(NULL); if(NULL == dpy) { fprintf(stderr, "failed to open display\n"); return 1; } int a = 0; int b = 0; XScreenSaverQueryExtension(dpy, &a, &b); printf("%d %d\n", a, b); XScreenSaverQueryInfo(dpy, RootWindow(dpy, DefaultScreen(dpy)), &info); printf("%d %d %d %d\n", info.state, info.til_or_since, info.idle, info.kind); return 0; } 

But info.state is always 3 (ScreenSaverDisabled). I checked this with xscreensaver and gnome-screensaver.

Here is an example output:

 92 0 3 0 9903 0 

The same with or without a screensaver (except, of course, info.idle).

Additional Information:

 $ X -version X.Org X Server 1.13.0 Release Date: 2012-09-05 X Protocol Version 11, Revision 0 

Window Manager: i3

Distribution: Arch Linux

EDIT: Using [this] [1] I created a version of xcb that also does not work. To eliminate errors in my testing procedure, here it is: For me, this code runs in an endless loop, while my xscreensaver runs in the background. And to actually activate the screensaver, I use the xscreensaver-command --activate command

 #include <stdlib.h> #include <stdio.h> #include <xcb/xcb.h> #include <xcb/screensaver.h> static xcb_connection_t * connection; static xcb_screen_t * screen; /** * Connects to the X server (via xcb) and gets the screen */ void magic_begin () { connection = xcb_connect (NULL, NULL); screen = xcb_setup_roots_iterator (xcb_get_setup (connection)).data; } /** * Asks X for the time the user has been idle * @returns idle time in milliseconds */ unsigned long magic_get_state () { xcb_screensaver_query_info_cookie_t cookie; xcb_screensaver_query_info_reply_t *info; cookie = xcb_screensaver_query_info (connection, screen->root); info = xcb_screensaver_query_info_reply (connection, cookie, NULL); int state = info->state; return state; } int main(int arc, char *argv[]) { magic_begin(); int state = magic_get_state(); printf("state: %d\n", state); } [1]: http://stackoverflow.com/questions/9049087/with-x11-how-can-i-get-the-users-time-away-from-keyboard-while-ignoring-cert 
+4
source share
1 answer

I went to the xorg irc channel and said that at least xscreensaver does not use the extension that I use.

+2
source

All Articles