blob: 95eb062f4006912d31e7b511aa71ecb3eba677b9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
#include <stdio.h>
#include <X11/extensions/scrnsaver.h>
/* Based on getIdleTime.c by falconindy on ArchLinux BBS thread ID
121863. This function connects to the display in the DISPLAY
environment variable and returns the idle time. So the Haskell
code is responsible for determining and setting DISPLAY if
e.g. running from cron. */
int GetXIdleTime ()
{
Display *dpy = XOpenDisplay(NULL);
if (!dpy)
{
return(-1);
}
XScreenSaverInfo *info = XScreenSaverAllocInfo();
XScreenSaverQueryInfo(dpy, DefaultRootWindow(dpy), info);
return (info->idle);
}
/* int main (void)
{
int idletime;
idletime = GetXIdleTime();
printf("%u", idletime);
return 0;
} */
|