Debian Codegraph @

devel/exe-screensaver-info.c

raw symbols SCIP
1 /* Copyright 2011, 2012 Kevin Ryde
2
3 This file is part of X11-Protocol-Other.
4
5 X11-Protocol-Other is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your option) any
8 later version.
9
10 X11-Protocol-Other is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with X11-Protocol-Other. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <X11/Xlib.h>
22 #include <X11/extensions/scrnsaver.h>
23
24 /* cf. ProcScreenSaverQueryInfo()
25 http://cgit.freedesktop.org/xorg/xserver/tree/Xext/saver.c#n719
26 */
27
28 int
29 main (void)
30 {
31 Display *display;
32 Window rootwin;
33 int event_base, error_base;
34 XScreenSaverInfo info;
35
36 char *display_name = getenv("DISPLAY");
37 if (! display_name) {
38 display_name = ":0";
39 }
40
41 display = XOpenDisplay (display_name);
42 if (! display) {
43 printf ("no DISPLAY\n");
44 abort ();
45 }
46 rootwin = DefaultRootWindow (display);
47
48 if (! XScreenSaverQueryExtension (display, &event_base, &error_base)) {
49 printf ("screensaver not available\n");
50 abort ();
51 }
52
53 /* if (! XForceScreenSaver (display, ScreenSaverActive)) { */
54 /* printf ("cannot force screensaver on\n"); */
55 /* abort (); */
56 /* } */
57 /* XFlush (display); */
58 /* sleep(1); */
59
60 if (! XScreenSaverQueryInfo (display, rootwin, &info)) {
61 printf ("cannot QueryInfo\n");
62 abort();
63 }
64
65 printf ("state %d\n", info.state);
66 printf ("til_or_since %lu\n", info.til_or_since);
67 printf ("til_or_since as signed %ld\n", info.til_or_since);
68
69 if (! XForceScreenSaver (display, ScreenSaverReset)) {
70 printf ("cannot force screensaver off again\n");
71 abort ();
72 }
73 XFlush (display);
74
75 return 0;
76 }
77
78