1 /*****************************************************************************
5 * derived from xautolock supplied by
6 * Authors: Michel Eyckmans (MCE) & Stefan De Troch (SDT)
8 * --------------------------------------------------------------------------
10 * Copyright 1990,1992-1999,2001-2002 by Stefan De Troch and Michel Eyckmans.
11 * Copyright 2005 by Stefan Siegl <stesie at brokenpipe.de>
12 * Copyright 2007 by Christian Dietrich <stettberger at dokucode.de>
14 * Versions 2.0 and above of xautolock are available under version 2 of the
17 * sinac.c -L/usr/X11R6/lib -lX11 -lXss -lXext -o sinac
19 *****************************************************************************/
23 #include <X11/Xutil.h>
24 #include <X11/Xatom.h>
25 #include <X11/Xresource.h>
27 #include <X11/extensions/scrnsaver.h>
31 #define VERSION "0.1.2"
33 static XScreenSaverInfo
* xss_info
= 0;
36 seconds_idle(Display
*d
)
39 xss_info
= XScreenSaverAllocInfo();
40 XScreenSaverQueryInfo(d
, DefaultRootWindow(d
), xss_info
);
41 return xss_info
->idle
/ 1000;
46 main (int argc
, char* argv
[])
49 int wait
= 0, i
, idle
;
51 for (i
= 1; i
< argc
; i
++) {
52 if ((strcmp(argv
[i
], "-w") == 0) && (i
+1 < argc
))
53 wait
= atoi(argv
[++i
]), idle
;
54 else if (strcmp(argv
[i
], "-p") == 0)
57 fprintf(stderr
, "sinac - " VERSION
": %s [-w <seconds>] [-p]\n",
63 if (!(d
= XOpenDisplay (0))) {
64 fprintf (stderr
, "Couldn't connect to %s\n", XDisplayName (0));
70 while ((idle
= seconds_idle(d
)) < wait
)
71 sleep(wait
- idle
- 1);
73 fprintf(stdout
, "%ld\n", seconds_idle(d
));