updated on Thu Jan 5 13:17:10 UTC 2012
[aur-mirror.git] / sinac / sinac.c
blob3b32baa0f7845869a26cccd5a548c4586eb6bde3
1 /*****************************************************************************
3 * xidletime
5 * derived from xautolock supplied by
6 * Authors: Michel Eyckmans (MCE) & Stefan De Troch (SDT)
8 * --------------------------------------------------------------------------
9 *
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
15 * GNU GPL.
17 * sinac.c -L/usr/X11R6/lib -lX11 -lXss -lXext -o sinac
19 *****************************************************************************/
21 #include <X11/Xos.h>
22 #include <X11/Xlib.h>
23 #include <X11/Xutil.h>
24 #include <X11/Xatom.h>
25 #include <X11/Xresource.h>
27 #include <X11/extensions/scrnsaver.h>
29 #include <stdio.h>
31 #define VERSION "0.1.2"
33 static XScreenSaverInfo* xss_info = 0;
35 int
36 seconds_idle(Display *d)
38 if (! xss_info )
39 xss_info = XScreenSaverAllocInfo();
40 XScreenSaverQueryInfo(d, DefaultRootWindow(d), xss_info);
41 return xss_info->idle / 1000;
45 int
46 main (int argc, char* argv[])
48 Display* d;
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)
55 wait = 0;
56 else {
57 fprintf(stderr, "sinac - " VERSION ": %s [-w <seconds>] [-p]\n",
58 argv[0]);
59 return 1;
63 if (!(d = XOpenDisplay (0))) {
64 fprintf (stderr, "Couldn't connect to %s\n", XDisplayName (0));
65 return 1;
67 (void) XSync (d, 0);
69 if (wait)
70 while ((idle = seconds_idle(d)) < wait)
71 sleep(wait - idle - 1);
72 else
73 fprintf(stdout, "%ld\n", seconds_idle(d));
75 return 0;