http://ftp.x.org/contrib/applications/xscreensaver-2.34.tar.gz
[xscreensaver] / driver / xscreensaver.h
1 /* xscreensaver, Copyright (c) 1993-1998 Jamie Zawinski <jwz@jwz.org>
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 typedef struct passwd_dialog_data passwd_dialog_data;
30 typedef struct splash_dialog_data splash_dialog_data;
31
32 #undef countof
33 #define countof(x) (sizeof((x))/sizeof((*x)))
34
35
36
37 /* This structure holds all the user-specified parameters, read from the
38    command line, the resource database, or entered through a dialog box.
39  */
40 struct saver_preferences {
41   Bool verbose_p;               /* whether to print out lots of status info */
42   Bool timestamp_p;             /* whether to mark messages with a timestamp */
43   Bool debug_p;                 /* pay no mind to the man behind the curtain */
44   Bool xsync_p;                 /* whether XSynchronize has been called */
45
46   Bool lock_p;                  /* whether to lock as well as save */
47   Bool lock_vt_p;               /* whether to lock VTs too, if possible */
48   Bool fade_p;                  /* whether to fade to black, if possible */
49   Bool unfade_p;                /* whether to fade from black, if possible */
50   int fade_seconds;             /* how long that should take */
51   int fade_ticks;               /* how many ticks should be used */
52
53   Bool install_cmap_p;          /* whether we should use our own colormap
54                                    when using the screen's default visual. */
55
56   char **screenhacks;           /* the programs to run */
57   int screenhacks_count;
58
59   int nice_inferior;            /* nice value for subprocs */
60
61   Time initial_delay;           /* how long to sleep after launch */
62   Time splash_duration;         /* how long the splash screen stays up */
63   Time timeout;                 /* how much idle time before activation */
64   Time lock_timeout;            /* how long after activation locking starts */
65   Time cycle;                   /* how long each hack should run */
66   Time passwd_timeout;          /* how much time before pw dialog goes down */
67   Time pointer_timeout;         /* how often to check mouse position */
68   Time notice_events_timeout;   /* how long after window creation to select */
69   Time watchdog_timeout;        /* how often to re-raise and re-blank screen */
70
71   Bool use_xidle_extension;     /* which extension to use, if possible */
72   Bool use_mit_saver_extension;
73   Bool use_sgi_saver_extension;
74
75   char *shell;                  /* where to find /bin/sh */
76
77   char *help_url;               /* Where the help document resides. */
78   char *load_url_command;       /* How one loads URLs. */
79 };
80
81
82 /* This structure holds all the data that applies to the program as a whole,
83    or to the non-screen-specific parts of the display connection.
84  */
85 struct saver_info {
86   char *version;
87   saver_preferences prefs;
88
89   int nscreens;
90   saver_screen_info *screens;
91   saver_screen_info *default_screen;    /* ...on which dialogs will appear. */
92
93   time_t init_file_date;        /* The date (from stat()) of the .xscreensaver
94                                    file the last time this process read or
95                                    wrote it. */
96
97   /* =======================================================================
98      global connection info
99      ======================================================================= */
100
101   XtAppContext app;
102   Display *dpy;
103   XrmDatabase db;
104
105   /* =======================================================================
106      server extension info
107      ======================================================================= */
108
109 # ifdef HAVE_MIT_SAVER_EXTENSION
110   int mit_saver_ext_event_number;
111   int mit_saver_ext_error_number;
112 # endif
113 # ifdef HAVE_SGI_SAVER_EXTENSION
114   int sgi_saver_ext_event_number;
115   int sgi_saver_ext_error_number;
116 # endif
117
118
119   /* =======================================================================
120      blanking
121      ======================================================================= */
122
123   Bool screen_blanked_p;        /* Whether the saver is currently active. */
124   Window mouse_grab_window;     /* Window holding our mouse grab */
125   Window keyboard_grab_window;  /* Window holding our keyboard grab */
126   Bool fading_possible_p;       /* Whether fading to/from black is possible. */
127
128
129   /* =======================================================================
130      locking and runtime privileges
131      ======================================================================= */
132
133   Bool locked_p;                /* Whether the screen is currently locked. */
134   Bool dbox_up_p;               /* Whether the demo-mode or passwd dialogs
135                                    are currently visible */
136
137   Bool locking_disabled_p;      /* Sometimes locking is impossible. */
138   char *nolock_reason;          /* This is why. */
139
140   char *orig_uid;               /* What uid/gid we had at startup, before
141                                    discarding privileges. */
142   char *uid_message;            /* Any diagnostics from our attempt to
143                                    discard privileges (printed only in
144                                    -verbose mode.) */
145   Bool dangerous_uid_p;         /* Set to true if we're running as a user id
146                                    which is known to not be a normal, non-
147                                    privileged user. */
148
149   Window passwd_dialog;         /* The password dialog, if its up. */
150   passwd_dialog_data *pw_data;  /* Other info necessary to draw it. */
151
152
153   /* =======================================================================
154      demoing
155      ======================================================================= */
156
157   Bool demo_mode_p;             /* Whether demo-mode is active */
158   char *demo_hack;              /* The hack that has been selected from the
159                                    dialog box, which should be run next. */
160
161   Window splash_dialog;         /* The splash dialog, if its up. */
162   splash_dialog_data *sp_data;  /* Other info necessary to draw it. */
163
164
165   /* =======================================================================
166      timers
167      ======================================================================= */
168
169   XtIntervalId lock_id;         /* Timer to implement `prefs.lock_timeout' */
170   XtIntervalId cycle_id;        /* Timer to implement `prefs.cycle' */
171   XtIntervalId timer_id;        /* Timer to implement `prefs.timeout' */
172   XtIntervalId watchdog_id;     /* Timer to implement `prefs.watchdog */
173   XtIntervalId check_pointer_timer_id;  /* `prefs.pointer_timeout' */
174
175   time_t last_activity_time;               /* Used only when no server exts. */
176   saver_screen_info *last_activity_screen;
177
178
179   /* =======================================================================
180      remote control
181      ======================================================================= */
182
183   int selection_mode;           /* Set to -1 if the NEXT ClientMessage has just
184                                    been received; set to -2 if PREV has just
185                                    been received; set to N if SELECT has
186                                    been received.  (This is kind of nasty.) */
187
188   /* =======================================================================
189      subprocs
190      ======================================================================= */
191
192   XtIntervalId stderr_popup_timer;
193
194 };
195
196
197 /* This structure holds all the data that applies to the screen-specific parts
198    of the display connection; if the display has multiple screens, there will
199    be one of these for each screen.
200  */
201 struct saver_screen_info {
202   saver_info *global;
203
204   Screen *screen;
205   Widget toplevel_shell;
206
207   /* =======================================================================
208      blanking
209      ======================================================================= */
210
211   Window screensaver_window;    /* The window that will impersonate the root,
212                                    when the screensaver activates.  Note that
213                                    the window stored here may change, as we
214                                    destroy and recreate it on different
215                                    visuals. */
216   Colormap cmap;                /* The colormap that goes with the window. */
217   Bool install_cmap_p;          /* whether we should use our own colormap.
218                                    This can be overridden on a per-hack basis.
219                                  */
220   Visual *current_visual;       /* The visual of the window. */
221   Visual *default_visual;       /* visual to use when none other specified */
222   int current_depth;            /* How deep the visual (and the window) are. */
223
224   Window real_vroot;            /* The original virtual-root window. */
225   Window real_vroot_value;      /* What was in the __SWM_VROOT property. */
226
227   Cursor cursor;                /* A blank cursor that goes with the
228                                    real root window. */
229   unsigned long black_pixel;    /* Black, allocated from `cmap'. */
230
231 # ifdef HAVE_MIT_SAVER_EXTENSION
232   Window server_mit_saver_window;
233 # endif
234
235
236   /* =======================================================================
237      demoing
238      ======================================================================= */
239
240   Colormap demo_cmap;           /* The colormap that goes with the dialogs:
241                                    this might be the same as `cmap' so care
242                                    must be taken not to free it while it's
243                                    still in use. */
244
245   /* =======================================================================
246      timers
247      ======================================================================= */
248
249   int poll_mouse_last_root_x;           /* Used only when no server exts. */
250   int poll_mouse_last_root_y;
251   Window poll_mouse_last_child;
252   unsigned int poll_mouse_last_mask;
253
254
255   /* =======================================================================
256      subprocs
257      ======================================================================= */
258
259   int current_hack;             /* Index into `prefs.screenhacks' */
260   pid_t pid;
261
262   int stderr_text_x;
263   int stderr_text_y;
264   int stderr_line_height;
265   XFontStruct *stderr_font;
266   GC stderr_gc;
267   Window stderr_overlay_window;    /* Used if the server has overlay planes */
268   Colormap stderr_cmap;
269 };
270
271
272 \f
273
274 /* =======================================================================
275    server extensions and virtual roots
276    ======================================================================= */
277
278 extern void restore_real_vroot (saver_info *si);
279 extern void disable_builtin_screensaver (saver_info *si, Bool turn_off_p);
280 extern Bool ensure_no_screensaver_running (Display *, Screen *);
281
282 #ifdef HAVE_MIT_SAVER_EXTENSION
283 extern Bool query_mit_saver_extension (saver_info *);
284 #endif
285 #ifdef HAVE_SGI_SAVER_EXTENSION
286 extern Bool query_sgi_saver_extension (saver_info *);
287 #endif
288
289 /* Display Power Management System (DPMS) interface. */
290 extern Bool monitor_powered_on_p (saver_info *si);
291 extern void monitor_power_on (saver_info *si);
292
293
294 /* =======================================================================
295    blanking
296    ======================================================================= */
297
298 extern void initialize_screensaver_window (saver_info *si);
299 extern void raise_window (saver_info *si,
300                             Bool inhibit_fade, Bool between_hacks_p,
301                             Bool dont_clear);
302 extern void blank_screen (saver_info *si);
303 extern void unblank_screen (saver_info *si);
304 extern void grab_keyboard_and_mouse (saver_info *si, Window, Cursor);
305 extern void ungrab_keyboard_and_mouse (saver_info *si);
306
307 /* =======================================================================
308    locking
309    ======================================================================= */
310
311 #ifndef NO_LOCKING
312 extern Bool unlock_p (saver_info *si);
313 extern Bool lock_init (int argc, char **argv);
314 extern Bool passwd_valid_p (const char *typed_passwd);
315
316 extern void make_passwd_window (saver_info *si);
317 extern void draw_passwd_window (saver_info *si);
318 extern void update_passwd_window (saver_info *si, const char *printed_passwd,
319                                   float ratio);
320 extern void destroy_passwd_window (saver_info *si);
321
322 #endif /* NO_LOCKING */
323
324 /* =======================================================================
325    runtime privileges
326    ======================================================================= */
327
328 extern void hack_uid (saver_info *si);
329 extern void describe_uids (saver_info *si, FILE *out);
330
331 /* =======================================================================
332    demoing
333    ======================================================================= */
334
335 extern void draw_shaded_rectangle (Display *dpy, Window window,
336                                    int x, int y,
337                                    int width, int height,
338                                    int thickness,
339                                    unsigned long top_color,
340                                    unsigned long bottom_color);
341 extern int string_width (XFontStruct *font, char *s);
342
343
344 #ifndef NO_DEMO_MODE
345 extern void demo_mode (saver_info *si);
346 extern void demo_mode_restart_process (saver_info *si);
347 extern void create_demo_dialog (Widget, Visual *, Colormap);
348 extern void create_resources_dialog (Widget, Visual *, Colormap);
349 #endif
350
351 #if !defined(NO_LOCKING) || !defined(NO_DEMO_MODE)
352 extern void pop_up_dialog_box (Widget dialog, Widget form, int where);
353 extern void format_into_label (Widget label, const char *arg);
354 extern void steal_focus_and_colormap (Widget dialog);
355 #endif
356
357 extern void make_splash_dialog (saver_info *si);
358 extern void handle_splash_event (saver_info *si, XEvent *e);
359 extern void skull (Display *, Window, GC, GC, int, int, int, int);
360
361
362 /* =======================================================================
363    timers
364    ======================================================================= */
365
366 extern void start_notice_events_timer (saver_info *, Window);
367 extern void cycle_timer (XtPointer si, XtIntervalId *id);
368 extern void activate_lock_timer (XtPointer si, XtIntervalId *id);
369 extern void reset_watchdog_timer (saver_info *si, Bool on_p);
370 extern void idle_timer (XtPointer si, XtIntervalId *id);
371 extern void sleep_until_idle (saver_info *si, Bool until_idle_p);
372
373 /* =======================================================================
374    remote control
375    ======================================================================= */
376
377 extern Bool handle_clientmessage (saver_info *, XEvent *, Bool);
378
379 /* =======================================================================
380    subprocs
381    ======================================================================= */
382
383 extern void hack_environment (saver_info *si);
384 extern void init_sigchld (void);
385 extern void spawn_screenhack (saver_info *si, Bool first_time_p);
386 extern void kill_screenhack (saver_info *si);
387 extern void suspend_screenhack (saver_info *si, Bool suspend_p);
388 extern Bool screenhack_running_p (saver_info *si);
389 extern void emergency_kill_subproc (saver_info *si);
390 extern Bool select_visual (saver_screen_info *ssi, const char *visual_name);
391 extern const char *signal_name (int signal);
392
393 /* =======================================================================
394    subprocs diagnostics
395    ======================================================================= */
396
397 extern FILE *real_stderr;
398 extern FILE *real_stdout;
399 extern void initialize_stderr (saver_info *si);
400 extern void reset_stderr (saver_screen_info *ssi);
401 extern void clear_stderr (saver_screen_info *ssi);
402
403 /* =======================================================================
404    the .xscreensaver file
405    ======================================================================= */
406
407 extern int read_init_file (saver_info *si);
408 extern int write_init_file (saver_info *si);
409 extern int maybe_reload_init_file (saver_info *si);
410 extern void get_resources (saver_info *si);
411
412
413 /* =======================================================================
414    misc
415    ======================================================================= */
416
417 extern const char *blurb (void);
418 extern void save_argv (int argc, char **argv);
419 extern void saver_exit (saver_info *si, int status, const char *core_reason);
420 extern void restart_process (saver_info *si);
421
422 extern int saver_ehandler (Display *dpy, XErrorEvent *error);
423 extern int BadWindow_ehandler (Display *dpy, XErrorEvent *error);
424 extern Bool window_exists_p (Display *dpy, Window window);
425 extern char *timestring (void);
426
427 extern Atom XA_VROOT, XA_XSETROOT_ID;
428 extern Atom XA_SCREENSAVER, XA_SCREENSAVER_VERSION, XA_SCREENSAVER_ID;
429 extern Atom XA_SCREENSAVER_TIME;
430 extern Atom XA_DEMO, XA_PREFS;
431
432 #endif /* __XSCREENSAVER_H__ */