使用xlib检测正在运行的屏幕保护程序
发布时间:2020-12-16 07:33:42 所属栏目:百科 来源:网络整理
导读:我正试图检测屏幕保护程序是否正在运行. 这是我到目前为止的代码: /* 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.hintmain(int argc,char *
我正试图检测屏幕保护程序是否正在运行.
这是我到目前为止的代码: /* 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 displayn"); return 1; } int a = 0; int b = 0; XScreenSaverQueryExtension(dpy,&a,&b); printf("%d %dn",a,b); XScreenSaverQueryInfo(dpy,RootWindow(dpy,DefaultScreen(dpy)),&info); printf("%d %d %d %dn",info.state,info.til_or_since,info.idle,info.kind); return 0; } 但是info.state总是3(ScreenSaverDisabled).我用xscreensaver和gnome-screensaver对此进行了测试. 这是一些示例输出: 92 0 3 0 9903 0 它与运行的屏幕保护程序相同或没有(当然除了info.idle). 附加信息: $X -version X.Org X Server 1.13.0 Release Date: 2012-09-05 X Protocol Version 11,Revision 0 窗口管理器:i3 发行版:Arch Linux 编辑: #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: %dn",state); } [1]: https://stackoverflow.com/questions/9049087/with-x11-how-can-i-get-the-users-time-away-from-keyboard-while-ignoring-cert 解决方法
我去了xorg irc频道,并被告知至少xscreensaver不使用我使用的扩展名.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |