ftp://ftp.uni-heidelberg.de/pub/X11/contrib/applications/xscreensaver-2.07.tar.gz
[xscreensaver] / driver / xscreensaver.h
1 /* xscreensaver, Copyright (c) 1993-1997 Jamie Zawinski <jwz@netscape.com>
2  *
3  * Permission to use, copy, modify, distribute, and sell this software and its
4  * documentation for any purpose is hereby granted without fee, provided that
5  * the above copyright notice appear in all copies and that both that
6  * copyright notice and this permission notice appear in supporting
7  * documentation.  No representations are made about the suitability of this
8  * software for any purpose.  It is provided "as is" without express or 
9  * implied warranty.
10  */
11
12 #ifndef __XSCREENSAVER_H__
13 #define __XSCREENSAVER_H__
14
15 #include <stdlib.h>
16 #ifdef HAVE_UNISTD_H
17 # include <unistd.h>
18 #endif
19
20 #include <string.h>
21 #include <stdio.h>
22
23 extern char *progname;
24 extern char *progclass;
25
26 typedef struct saver_preferences saver_preferences;
27 typedef struct saver_info saver_info;
28 typedef struct saver_screen_info saver_screen_info;
29
30
31 #undef countof
32 #define countof(x) (sizeof((x))/sizeof((*x)))
33
34
35
36 /* This structure holds all the user-specified parameters, read from the
37    command line, the resource database, or entered through a dialog box.
38  */
39 struct saver_preferences {
40   Bool verbose_p;
41   Bool lock_p;                  /* whether to lock as well as save */
42
43   Bool debug_p;
44   Bool fade_p;                  /* whether to fade to black */
45   Bool unfade_p;                /* whether to fade from black */
46   int fade_seconds;             /* how long that should take */
47   int fade_ticks;               /* how many ticks should be used */
48
49   Bool install_cmap_p;          /* whether we should use our own colormap
50                                    when using the screen's default visual. */
51
52   char **screenhacks;           /* the programs to run */
53   int screenhacks_count;
54
55   int nice_inferior;            /* nice value for subprocs */
56
57   int initial_delay;            /* how long to sleep after launch */
58   Time timeout;                 /* how much idle time before activation */
59   Time lock_timeout;            /* how long after activation locking starts */
60   Time cycle;                   /* how long each hack should run */
61 #ifndef NO_LOCKING
62   Time passwd_timeout;          /* how much time before pw dialog goes down */
63 #endif
64   Time pointer_timeout;         /* how often to check mouse position */
65   Time notice_events_timeout;   /* how long after window creation to select */
66   Time watchdog_timeout;        /* how often to re-raise and re-blank screen */
67
68   Bool use_xidle_extension;     /* which extension to use, if possible */
69   Bool use_mit_saver_extension;
70   Bool use_sgi_saver_extension;
71
72   char *shell;                  /* where to find /bin/sh */
73
74 };
75
76
77 /* This structure holds all the data that applies to the program as a whole,
78    or to the non-screen-specific parts of the display connection.
79  */
80 struct saver_info {
81   char *version;
82   saver_preferences prefs;
83
84   int nscreens;
85   saver_screen_info *screens;
86   saver_screen_info *default_screen;    /* ...on which dialogs will appear. */
87
88   /* =======================================================================
89      global connection info
90      ======================================================================= */
91
92   XtAppContext app;
93   Display *dpy;
94   XrmDatabase db;
95
96   /* =======================================================================
97      server extension info
98      ======================================================================= */
99
100 # ifdef HAVE_MIT_SAVER_EXTENSION
101   int mit_saver_ext_event_number;
102   int mit_saver_ext_error_number;
103 # endif
104 # ifdef HAVE_SGI_SAVER_EXTENSION
105   int sgi_saver_ext_event_number;
106   int sgi_saver_ext_error_number;
107 # endif
108
109
110   /* =======================================================================
111      blanking
112      ======================================================================= */
113
114   Bool screen_blanked_p;        /* Whether the saver is currently active. */
115
116
117   /* =======================================================================
118      locking
119      ======================================================================= */
120
121   Bool locking_disabled_p;      /* Sometimes locking is impossible. */
122   char *nolock_reason;          /* This is why. */
123   Bool locked_p;                /* Whether the screen is currently locked. */
124   Bool dbox_up_p;               /* Whether the demo-mode or passwd dialogs
125                                    are currently visible */
126
127
128   /* =======================================================================
129      demoing
130      ======================================================================= */
131
132   Bool demo_mode_p;             /* Whether demo-mode is active */
133   char *demo_hack;              /* The hack that has been selected from the
134                                    dialog box, which should be run next. */
135
136
137   /* =======================================================================
138      timers
139      ======================================================================= */
140
141   XtIntervalId lock_id;         /* Timer to implement `prefs.lock_timeout' */
142   XtIntervalId cycle_id;        /* Timer to implement `prefs.cycle' */
143   XtIntervalId timer_id;        /* Timer to implement `prefs.timeout' */
144   XtIntervalId watchdog_id;     /* Timer to implement `prefs.watchdog */
145   XtIntervalId check_pointer_timer_id;  /* `prefs.pointer_timeout' */
146
147   time_t last_activity_time;               /* Used only when no server exts. */
148   saver_screen_info *last_activity_screen;
149
150
151   /* =======================================================================
152      remote control
153      ======================================================================= */
154
155   int next_mode_p;              /* Set to 1 if the NEXT ClientMessage has just
156                                    been received; set to 2 if PREV has just
157                                    been received.  (#### This is nasty.) */
158
159   /* =======================================================================
160      subprocs
161      ======================================================================= */
162
163   XtIntervalId stderr_popup_timer;
164
165 };
166
167
168 /* This structure holds all the data that applies to the screen-specific parts
169    of the display connection; if the display has multiple screens, there will
170    be one of these for each screen.
171  */
172 struct saver_screen_info {
173   saver_info *global;
174
175   Screen *screen;
176   Widget toplevel_shell;
177
178   /* =======================================================================
179      blanking
180      ======================================================================= */
181
182   Window screensaver_window;    /* The window that will impersonate the root,
183                                    when the screensaver activates.  Note that
184                                    the window stored here may change, as we
185                                    destroy and recreate it on different
186                                    visuals. */
187   Colormap cmap;                /* The colormap that goes with the window. */
188   Visual *current_visual;       /* The visual of the window. */
189   Visual *default_visual;       /* visual to use when none other specified */
190   int current_depth;            /* How deep the visual (and the window) are. */
191
192   Window real_vroot;            /* The original virtual-root window. */
193   Window real_vroot_value;      /* What was in the __SWM_VROOT property. */
194
195   Cursor cursor;                /* A blank cursor that goes with the
196                                    real root window. */
197   unsigned long black_pixel;    /* Black, allocated from `cmap'. */
198
199 # ifdef HAVE_MIT_SAVER_EXTENSION
200   Window server_mit_saver_window;
201 # endif
202
203
204   /* =======================================================================
205      demoing
206      ======================================================================= */
207
208   Colormap demo_cmap;           /* The colormap that goes with the dialogs:
209                                    this might be the same as `cmap' so care
210                                    must be taken not to free it while it's
211                                    still in use. */
212
213   /* =======================================================================
214      timers
215      ======================================================================= */
216
217   int poll_mouse_last_root_x;           /* Used only when no server exts. */
218   int poll_mouse_last_root_y;
219   Window poll_mouse_last_child;
220   unsigned int poll_mouse_last_mask;
221
222
223   /* =======================================================================
224      subprocs
225      ======================================================================= */
226
227   int current_hack;             /* Index into `prefs.screenhacks' */
228   pid_t pid;
229
230   int stderr_text_x;
231   int stderr_text_y;
232   int stderr_line_height;
233   XFontStruct *stderr_font;
234   GC stderr_gc;
235   Window stderr_overlay_window;    /* Used if the server has overlay planes */
236   Colormap stderr_cmap;
237 };
238
239
240 \f
241
242 /* =======================================================================
243    server extensions and virtual roots
244    ======================================================================= */
245
246 extern void restore_real_vroot (saver_info *si);
247 extern void disable_builtin_screensaver (saver_info *si, Bool turn_off_p);
248 extern void ensure_no_screensaver_running (Display *, Screen *);
249
250 #ifdef HAVE_MIT_SAVER_EXTENSION
251 extern Bool query_mit_saver_extension (saver_info *);
252 #endif
253 #ifdef HAVE_SGI_SAVER_EXTENSION
254 extern Bool query_sgi_saver_extension (saver_info *);
255 #endif
256
257
258 /* =======================================================================
259    blanking
260    ======================================================================= */
261
262 extern void initialize_screensaver_window (saver_info *si);
263 extern void raise_window (saver_info *si,
264                             Bool inhibit_fade, Bool between_hacks_p,
265                             Bool dont_clear);
266 extern void blank_screen (saver_info *si);
267 extern void unblank_screen (saver_info *si);
268 extern void grab_keyboard_and_mouse (Display *, Window, Cursor);
269 extern void ungrab_keyboard_and_mouse (Display *dpy);
270
271 /* =======================================================================
272    locking
273    ======================================================================= */
274
275 #ifndef NO_LOCKING
276 extern Bool unlock_p (saver_info *si);
277 extern create_passwd_dialog (Widget, Visual *, Colormap);
278 extern Bool lock_init (int argc, char **argv);
279 extern Bool passwd_valid_p (const char *typed_passwd);
280 #endif
281
282 /* =======================================================================
283    demoing
284    ======================================================================= */
285
286 #ifndef NO_DEMO_MODE
287 extern void demo_mode (saver_info *si);
288 extern void demo_mode_restart_process (saver_info *si);
289 extern create_demo_dialog (Widget, Visual *, Colormap);
290 extern create_resources_dialog (Widget, Visual *, Colormap);
291 #endif
292
293 #if !defined(NO_LOCKING) || !defined(NO_DEMO_MODE)
294 extern void pop_up_dialog_box (Widget dialog, Widget form, int where);
295 extern void format_into_label (Widget label, const char *arg);
296 extern void steal_focus_and_colormap (Widget dialog);
297 #endif
298
299 /* =======================================================================
300    timers
301    ======================================================================= */
302
303 extern void start_notice_events_timer (saver_info *, Window);
304 extern void cycle_timer (XtPointer si, XtIntervalId *id);
305 extern void activate_lock_timer (XtPointer si, XtIntervalId *id);
306 extern void reset_watchdog_timer (saver_info *si, Bool on_p);
307 extern void idle_timer (XtPointer si, XtIntervalId *id);
308 extern void sleep_until_idle (saver_info *si, Bool until_idle_p);
309
310 /* =======================================================================
311    remote control
312    ======================================================================= */
313
314 extern Bool handle_clientmessage (saver_info *, XEvent *, Bool);
315
316 /* =======================================================================
317    subprocs
318    ======================================================================= */
319
320 extern void init_sigchld (void);
321 extern void spawn_screenhack (saver_info *si, Bool first_time_p);
322 extern void kill_screenhack (saver_info *si);
323 extern void suspend_screenhack (saver_info *si, Bool suspend_p);
324 extern Bool screenhack_running_p (saver_info *si);
325 extern void emergency_kill_subproc (saver_info *si);
326 extern Bool select_visual (saver_screen_info *ssi, const char *visual_name);
327 extern const char *signal_name (int signal);
328
329 /* =======================================================================
330    subprocs security
331    ======================================================================= */
332
333 #ifdef NO_SETUID
334 # define hack_uid()
335 # define hack_uid_warn()
336 #else /* !NO_SETUID */
337  extern void hack_uid (saver_info *si);
338  extern void hack_uid_warn (saver_info *si);
339 #endif /* NO_SETUID */
340
341 /* =======================================================================
342    subprocs diagnostics
343    ======================================================================= */
344
345 extern FILE *real_stderr;
346 extern FILE *real_stdout;
347 extern void initialize_stderr (saver_info *si);
348 extern void reset_stderr (saver_screen_info *ssi);
349 extern void clear_stderr (saver_screen_info *ssi);
350
351 /* =======================================================================
352    misc
353    ======================================================================= */
354
355 extern void save_argv (int argc, char **argv);
356 extern void saver_exit (saver_info *si, int status);
357 extern void restart_process (saver_info *si);
358
359 extern int saver_ehandler (Display *dpy, XErrorEvent *error);
360 extern int BadWindow_ehandler (Display *dpy, XErrorEvent *error);
361 extern Bool window_exists_p (Display *dpy, Window window);
362 extern char *timestring (void);
363
364 extern Atom XA_VROOT, XA_XSETROOT_ID;
365 extern Atom XA_SCREENSAVER_VERSION, XA_SCREENSAVER_ID;
366 extern Atom XA_SCREENSAVER_TIME;
367
368 #endif /* __XSCREENSAVER_H__ */