http://packetstormsecurity.org/UNIX/admin/xscreensaver-4.16.tar.gz
[xscreensaver] / driver / test-fade.c
1 /* test-fade.c --- playing with colormap and/or gamma fading.
2  * xscreensaver, Copyright (c) 2001, 2004 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
24 #include <X11/Intrinsic.h>
25 #include "xscreensaver.h"
26 #include "fade.h"
27
28 #ifdef HAVE_SGI_VC_EXTENSION
29 # include <X11/extensions/XSGIvc.h>
30 #endif
31 #ifdef HAVE_XF86VMODE_GAMMA
32 # include <X11/extensions/xf86vmode.h>
33 #endif
34
35 XrmDatabase db = 0;
36 char *progname = 0;
37 char *progclass = "XScreenSaver";
38
39 #define SGI_VC_NAME "SGI-VIDEO-CONTROL"
40 #define XF86_VIDMODE_NAME "XFree86-VidModeExtension"
41
42 int
43 main (int argc, char **argv)
44 {
45   int seconds = 3;
46   int ticks = 20;
47   int delay = 1;
48
49   int op, event, error, major, minor;
50
51   XtAppContext app;
52   Widget toplevel_shell = XtAppInitialize (&app, progclass, 0, 0,
53                                            &argc, argv, 0, 0, 0);
54   Display *dpy = XtDisplay (toplevel_shell);
55   Colormap *current_maps;
56   int i;
57
58   XtGetApplicationNameAndClass (dpy, &progname, &progclass);
59   db = XtDatabase (dpy);
60
61   current_maps = (Colormap *) calloc(sizeof(Colormap), ScreenCount(dpy));
62   for (i = 0; i < ScreenCount(dpy); i++)
63     current_maps[i] = DefaultColormap (dpy, i);
64
65   if (!XQueryExtension (dpy, SGI_VC_NAME, &op, &event, &error))
66     fprintf(stderr, "%s: no " SGI_VC_NAME " extension\n", progname);
67   else
68     {
69 # ifdef HAVE_SGI_VC_EXTENSION
70       if (!XSGIvcQueryVersion (dpy, &major, &minor))
71         fprintf(stderr, "%s: unable to get " SGI_VC_NAME " version\n",
72                 progname);
73       else
74         fprintf(stderr, "%s: " SGI_VC_NAME " version %d.%d\n",
75                 progname, major, minor);
76 # else /* !HAVE_SGI_VC_EXTENSION */
77       fprintf(stderr, "%s: no support for display's " SGI_VC_NAME
78               " extension\n", progname);
79 # endif /* !HAVE_SGI_VC_EXTENSION */
80     }
81
82
83   if (!XQueryExtension (dpy, XF86_VIDMODE_NAME, &op, &event, &error))
84     fprintf(stderr, "%s: no " XF86_VIDMODE_NAME " extension\n", progname);
85   else
86     {
87 # ifdef HAVE_XF86VMODE_GAMMA
88       if (!XF86VidModeQueryVersion (dpy, &major, &minor))
89         fprintf(stderr, "%s: unable to get " XF86_VIDMODE_NAME " version\n",
90                 progname);
91       else
92         fprintf(stderr, "%s: " XF86_VIDMODE_NAME " version %d.%d\n",
93                 progname, major, minor);
94 # else /* !HAVE_XF86VMODE_GAMMA */
95       fprintf(stderr, "%s: no support for display's " XF86_VIDMODE_NAME
96               " extension\n", progname);
97 # endif /* !HAVE_XF86VMODE_GAMMA */
98     }
99
100   fprintf (stderr, "%s: fading %d screen%s\n",
101            progname, ScreenCount(dpy), ScreenCount(dpy) == 1 ? "" : "s");
102
103   while (1)
104     {
105       XSync (dpy, False);
106
107       fprintf(stderr, "%s: out...", progname);
108       fflush(stderr);
109       fade_screens (dpy, current_maps, 0, 0, seconds, ticks, True, False);
110       fprintf(stderr, "done.\n");
111       fflush(stderr);
112
113       if (delay) sleep (delay);
114
115       fprintf(stderr,"%s: in...", progname);
116       fflush(stderr);
117       fade_screens (dpy, current_maps, 0, 0, seconds, ticks, False, False);
118       fprintf(stderr, "done.\n");
119       fflush(stderr);
120
121       if (delay) sleep (delay);
122     }
123 }