我正在制作一个需要了解用户闲置时间的应用程序 - 例如,不使用键盘或鼠标.XCB和Xlib都承诺通过各自的屏幕保护程序扩展为我提供空闲时间.这是我在XCB闲暇时间的地方:
#include <stdlib.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_idle_time () {
xcb_screensaver_query_info_cookie_t cookie;
xcb_screensaver_query_info_reply_t *info;
cookie = xcb_screensaver_query_info (connection, screen->root);
info …Run Code Online (Sandbox Code Playgroud)