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