ftp://ftp.swin.edu.au/slackware/slackware-9.1/source/xap/xscreensaver/xscreensaver...
[xscreensaver] / driver / test-xinerama.c
1 /* test-xinerama.c --- playing with the Xinerama extension.
2  * xscreensaver, Copyright (c) 2003 Jamie Zawinski <jwz@jwz.org>
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and its
5  * documentation for any purpose is hereby granted without fee, provided that
6  * the above copyright notice appear in all copies and that both that
7  * copyright notice and this permission notice appear in supporting
8  * documentation.  No representations are made about the suitability of this
9  * software for any purpose.  It is provided "as is" without express or 
10  * implied warranty.
11  */
12
13 #ifdef HAVE_CONFIG_H
14 # include "config.h"
15 #endif
16
17 #include <stdlib.h>
18 #ifdef HAVE_UNISTD_H
19 # include <unistd.h>
20 #endif
21
22 #include <stdio.h>
23 #include <time.h>
24 #include <sys/time.h>
25
26 #include <X11/Xlib.h>
27 #include <X11/Xatom.h>
28 #include <X11/Intrinsic.h>
29
30 #include <X11/Xproto.h>
31 #include <X11/extensions/Xinerama.h>
32
33 char *progname = 0;
34 char *progclass = "XScreenSaver";
35
36 static const char *
37 blurb (void)
38 {
39   static char buf[255];
40   time_t now = time ((time_t *) 0);
41   char *ct = (char *) ctime (&now);
42   int n = strlen(progname);
43   if (n > 100) n = 99;
44   strncpy(buf, progname, n);
45   buf[n++] = ':';
46   buf[n++] = ' ';
47   strncpy(buf+n, ct+11, 8);
48   strcpy(buf+n+9, ": ");
49   return buf;
50 }
51
52
53 int
54 main (int argc, char **argv)
55 {
56   int event_number, error_number;
57   int major, minor;
58   int nscreens = 0;
59   XineramaScreenInfo *xsi;
60   int i;
61
62   XtAppContext app;
63   Widget toplevel_shell = XtAppInitialize (&app, progclass, 0, 0,
64                                            &argc, argv, 0, 0, 0);
65   Display *dpy = XtDisplay (toplevel_shell);
66   XtGetApplicationNameAndClass (dpy, &progname, &progclass);
67
68   if (!XineramaQueryExtension(dpy, &event_number, &error_number))
69     {
70       fprintf(stderr, "%s: XineramaQueryExtension(dpy, ...) ==> False\n",
71               blurb());
72       fprintf(stderr, "%s: server does not support the Xinerama extension.\n",
73               blurb());
74       exit(1);
75     }
76   else
77     fprintf(stderr, "%s: XineramaQueryExtension(dpy, ...) ==> %d, %d\n",
78             blurb(), event_number, error_number);
79
80   if (!XineramaIsActive(dpy))
81     {
82       fprintf(stderr, "%s: XineramaIsActive(dpy) ==> False\n", blurb());
83       fprintf(stderr, "%s: server says Xinerama is turned off.\n", blurb());
84       exit(1);
85     }
86   else
87     fprintf(stderr, "%s: XineramaIsActive(dpy) ==> True\n", blurb());
88
89   if (!XineramaQueryVersion(dpy, &major, &minor))
90     {
91       fprintf(stderr, "%s: XineramaQueryVersion(dpy, ...) ==> False\n",
92               blurb());
93       fprintf(stderr, "%s: server didn't report Xinerama version numbers?\n",
94               blurb());
95     }
96   else
97     fprintf(stderr, "%s: XineramaQueryVersion(dpy, ...) ==> %d, %d\n", blurb(),
98             major, minor);
99
100   xsi = XineramaQueryScreens (dpy, &nscreens);
101   fprintf(stderr, "%s: %d Xinerama screens\n", blurb(), nscreens);
102   
103   for (i = 0; i < nscreens; i++)
104     fprintf (stderr, "%s:   screen %d: %dx%d+%d+%d\n",
105              blurb(),
106              xsi[i].screen_number,
107              xsi[i].width, xsi[i].height,
108              xsi[i].x_org, xsi[i].y_org);
109   XFree (xsi);
110   XSync (dpy, False);
111   exit (0);
112 }