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