http://svn.poeml.de/viewvc/ppc/src-unpacked/xscreensaver/xscreensaver-4.12.tar.bz2...
[xscreensaver] / driver / xscreensaver.h
1 /* xscreensaver, Copyright (c) 1993-2003 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 #ifdef HAVE_SIGACTION
24 # include <signal.h>    /* for sigset_t */
25 #endif
26
27 #include "prefs.h"
28
29 extern char *progname;
30 extern char *progclass;
31
32 typedef struct saver_info saver_info;
33 typedef struct saver_screen_info saver_screen_info;
34 typedef struct passwd_dialog_data passwd_dialog_data;
35 typedef struct splash_dialog_data splash_dialog_data;
36
37 #undef countof
38 #define countof(x) (sizeof((x))/sizeof((*x)))
39
40
41
42 /* This structure holds all the data that applies to the program as a whole,
43    or to the non-screen-specific parts of the display connection.
44
45    The saver_preferences structure (prefs.h) holds all the user-specified
46    parameters, read from the command line, the resource database, or entered
47    through a dialog box.
48  */
49 struct saver_info {
50   char *version;
51   saver_preferences prefs;
52
53   int nscreens;
54   saver_screen_info *screens;
55   saver_screen_info *default_screen;    /* ...on which dialogs will appear. */
56
57
58   /* =======================================================================
59      global connection info
60      ======================================================================= */
61
62   XtAppContext app;
63   Display *dpy;
64
65   /* =======================================================================
66      server extension info
67      ======================================================================= */
68
69   Bool using_xidle_extension;      /* which extension is being used.         */
70   Bool using_mit_saver_extension;  /* Note that `p->use_*' is the *request*, */
71   Bool using_sgi_saver_extension;  /* and `si->using_*' is the *reality*.    */
72   Bool using_proc_interrupts;
73
74 # ifdef HAVE_MIT_SAVER_EXTENSION
75   int mit_saver_ext_event_number;
76   int mit_saver_ext_error_number;
77 # endif
78 # ifdef HAVE_SGI_SAVER_EXTENSION
79   int sgi_saver_ext_event_number;
80   int sgi_saver_ext_error_number;
81 # endif
82
83
84   /* =======================================================================
85      blanking
86      ======================================================================= */
87
88   Bool screen_blanked_p;        /* Whether the saver is currently active. */
89   Window mouse_grab_window;     /* Window holding our mouse grab */
90   Window keyboard_grab_window;  /* Window holding our keyboard grab */
91   int mouse_grab_screen;        /* The screen number the mouse grab is on */
92   int keyboard_grab_screen;     /* The screen number the keyboard grab is on */
93   Bool fading_possible_p;       /* Whether fading to/from black is possible. */
94   Bool throttled_p;             /* Whether we should temporarily just blank
95                                    the screen, not run hacks. */
96   time_t blank_time;            /* The time at which the screen was blanked
97                                    (if currently blanked) or unblanked (if
98                                    not blanked.) */
99
100
101   /* =======================================================================
102      locking and runtime privileges
103      ======================================================================= */
104
105   Bool locked_p;                /* Whether the screen is currently locked. */
106   Bool dbox_up_p;               /* Whether the demo-mode or passwd dialogs
107                                    are currently visible */
108
109   Bool locking_disabled_p;      /* Sometimes locking is impossible. */
110   char *nolock_reason;          /* This is why. */
111
112   char *orig_uid;               /* What uid/gid we had at startup, before
113                                    discarding privileges. */
114   char *uid_message;            /* Any diagnostics from our attempt to
115                                    discard privileges (printed only in
116                                    -verbose mode.) */
117   Bool dangerous_uid_p;         /* Set to true if we're running as a user id
118                                    which is known to not be a normal, non-
119                                    privileged user. */
120
121   Window passwd_dialog;         /* The password dialog, if its up. */
122   passwd_dialog_data *pw_data;  /* Other info necessary to draw it. */
123
124   int unlock_failures;          /* Counts failed login attempts while the
125                                    screen is locked. */
126
127   char *unlock_typeahead;       /* If the screen is locked, and the user types
128                                    a character, we assume that it is the first
129                                    character of the password.  It's stored here
130                                    for the password dialog to use to populate
131                                    itself. */
132
133
134   /* =======================================================================
135      demoing
136      ======================================================================= */
137
138   Bool demoing_p;               /* Whether we are demoing a single hack
139                                    (without UI.) */
140
141   Window splash_dialog;         /* The splash dialog, if its up. */
142   splash_dialog_data *sp_data;  /* Other info necessary to draw it. */
143
144
145   /* =======================================================================
146      timers
147      ======================================================================= */
148
149   XtIntervalId lock_id;         /* Timer to implement `prefs.lock_timeout' */
150   XtIntervalId cycle_id;        /* Timer to implement `prefs.cycle' */
151   XtIntervalId timer_id;        /* Timer to implement `prefs.timeout' */
152   XtIntervalId watchdog_id;     /* Timer to implement `prefs.watchdog */
153   XtIntervalId check_pointer_timer_id;  /* `prefs.pointer_timeout' */
154
155   time_t last_activity_time;               /* Used only when no server exts. */
156   time_t last_wall_clock_time;             /* Used to detect laptop suspend. */
157   saver_screen_info *last_activity_screen;
158
159   Bool emergency_lock_p;        /* Set when the wall clock has jumped
160                                    (presumably due to laptop suspend) and we
161                                    need to lock down right away instead of
162                                    waiting for the lock timer to go off. */
163
164
165   /* =======================================================================
166      remote control
167      ======================================================================= */
168
169   int selection_mode;           /* Set to -1 if the NEXT ClientMessage has just
170                                    been received; set to -2 if PREV has just
171                                    been received; set to N if SELECT or DEMO N
172                                    has been received.  (This is kind of nasty.)
173                                  */
174
175   /* =======================================================================
176      subprocs
177      ======================================================================= */
178
179   XtIntervalId stderr_popup_timer;
180
181 };
182
183
184 /* This structure holds all the data that applies to the screen-specific parts
185    of the display connection; if the display has multiple screens, there will
186    be one of these for each screen.
187  */
188 struct saver_screen_info {
189   saver_info *global;
190
191   int number;
192   Screen *screen;
193   Widget toplevel_shell;
194
195   /* =======================================================================
196      blanking
197      ======================================================================= */
198
199   Window screensaver_window;    /* The window that will impersonate the root,
200                                    when the screensaver activates.  Note that
201                                    the window stored here may change, as we
202                                    destroy and recreate it on different
203                                    visuals. */
204   Colormap cmap;                /* The colormap that goes with the window. */
205   Bool install_cmap_p;          /* Whether this screen should have its own
206                                    colormap installed, for whichever of several
207                                    reasons.  This is definitive (even a false
208                                    value here overrides prefs->install_cmap_p.)
209                                  */
210   Visual *current_visual;       /* The visual of the window. */
211   int current_depth;            /* How deep the visual (and the window) are. */
212
213   Visual *default_visual;       /* visual to use when none other specified */
214   Visual *best_gl_visual;       /* visual to use for GL hacks */
215
216   Window real_vroot;            /* The original virtual-root window. */
217   Window real_vroot_value;      /* What was in the __SWM_VROOT property. */
218
219   Cursor cursor;                /* A blank cursor that goes with the
220                                    real root window. */
221   unsigned long black_pixel;    /* Black, allocated from `cmap'. */
222
223   int blank_vp_x, blank_vp_y;   /* Where the virtual-scrolling viewport was
224                                    when the screen went blank.  We need to
225                                    prevent the X server from letting the mouse
226                                    bump the edges to scroll while the screen
227                                    is locked, so we reset to this when it has
228                                    moved, and the lock dialog is up... */
229
230 # ifdef HAVE_MIT_SAVER_EXTENSION
231   Window server_mit_saver_window;
232 # endif
233
234
235   /* =======================================================================
236      demoing
237      ======================================================================= */
238
239   Colormap demo_cmap;           /* The colormap that goes with the dialogs:
240                                    this might be the same as `cmap' so care
241                                    must be taken not to free it while it's
242                                    still in use. */
243
244   /* =======================================================================
245      timers
246      ======================================================================= */
247
248   int poll_mouse_last_root_x;           /* Used only when no server exts. */
249   int poll_mouse_last_root_y;
250   Window poll_mouse_last_child;
251   unsigned int poll_mouse_last_mask;
252
253
254   /* =======================================================================
255      subprocs
256      ======================================================================= */
257
258   int current_hack;             /* Index into `prefs.screenhacks' */
259   pid_t pid;
260
261   int stderr_text_x;
262   int stderr_text_y;
263   int stderr_line_height;
264   XFontStruct *stderr_font;
265   GC stderr_gc;
266   Window stderr_overlay_window;    /* Used if the server has overlay planes */
267   Colormap stderr_cmap;
268 };
269
270
271 \f
272
273 /* =======================================================================
274    server extensions and virtual roots
275    ======================================================================= */
276
277 extern Bool restore_real_vroot (saver_info *si);
278 extern void disable_builtin_screensaver (saver_info *, Bool unblank_screen_p);
279 extern Bool ensure_no_screensaver_running (Display *, Screen *);
280
281 #ifdef HAVE_MIT_SAVER_EXTENSION
282 extern Bool query_mit_saver_extension (saver_info *);
283 #endif
284 #ifdef HAVE_SGI_SAVER_EXTENSION
285 extern Bool query_sgi_saver_extension (saver_info *);
286 #endif
287 #ifdef HAVE_XIDLE_EXTENSION
288 extern Bool query_xidle_extension (saver_info *);
289 #endif
290 #ifdef HAVE_PROC_INTERRUPTS
291 extern Bool query_proc_interrupts_available (saver_info *, const char **why);
292 #endif
293
294 /* Display Power Management System (DPMS) interface. */
295 extern Bool monitor_powered_on_p (saver_info *si);
296 extern void monitor_power_on (saver_info *si);
297
298
299 /* =======================================================================
300    blanking
301    ======================================================================= */
302
303 extern void initialize_screensaver_window (saver_info *si);
304 extern void raise_window (saver_info *si,
305                             Bool inhibit_fade, Bool between_hacks_p,
306                             Bool dont_clear);
307 extern Bool blank_screen (saver_info *si);
308 extern void unblank_screen (saver_info *si);
309
310 extern void get_screen_viewport (saver_screen_info *ssi,
311                                  int *x_ret, int *y_ret,
312                                  int *w_ret, int *h_ret,
313                                  int target_x, int target_y,
314                                  Bool verbose_p);
315
316
317 /* =======================================================================
318    locking
319    ======================================================================= */
320
321 #ifndef NO_LOCKING
322 extern Bool unlock_p (saver_info *si);
323 extern Bool lock_priv_init (int argc, char **argv, Bool verbose_p);
324 extern Bool lock_init (int argc, char **argv, Bool verbose_p);
325 extern Bool passwd_valid_p (const char *typed_passwd, Bool verbose_p);
326 #endif /* NO_LOCKING */
327
328 extern void set_locked_p (saver_info *si, Bool locked_p);
329 extern int move_mouse_grab (saver_info *si, Window to, Cursor cursor,
330                             int to_screen_no);
331 extern int mouse_screen (saver_info *si);
332
333
334 /* =======================================================================
335    runtime privileges
336    ======================================================================= */
337
338 extern void hack_uid (saver_info *si);
339 extern void describe_uids (saver_info *si, FILE *out);
340
341 /* =======================================================================
342    demoing
343    ======================================================================= */
344
345 extern void draw_shaded_rectangle (Display *dpy, Window window,
346                                    int x, int y,
347                                    int width, int height,
348                                    int thickness,
349                                    unsigned long top_color,
350                                    unsigned long bottom_color);
351 extern int string_width (XFontStruct *font, char *s);
352
353 extern void make_splash_dialog (saver_info *si);
354 extern void handle_splash_event (saver_info *si, XEvent *e);
355
356
357 /* =======================================================================
358    timers
359    ======================================================================= */
360
361 extern void start_notice_events_timer (saver_info *, Window, Bool verbose_p);
362 extern void cycle_timer (XtPointer si, XtIntervalId *id);
363 extern void activate_lock_timer (XtPointer si, XtIntervalId *id);
364 extern void reset_watchdog_timer (saver_info *si, Bool on_p);
365 extern void idle_timer (XtPointer si, XtIntervalId *id);
366 extern void sleep_until_idle (saver_info *si, Bool until_idle_p);
367 extern void reset_timers (saver_info *si);
368
369 /* =======================================================================
370    remote control
371    ======================================================================= */
372
373 extern Bool handle_clientmessage (saver_info *, XEvent *, Bool);
374 extern void maybe_reload_init_file (saver_info *);
375
376 /* =======================================================================
377    subprocs
378    ======================================================================= */
379
380 extern void handle_signals (saver_info *si);
381 #ifdef HAVE_SIGACTION
382  extern sigset_t block_sigchld (void);
383 #else  /* !HAVE_SIGACTION */
384  extern int block_sigchld (void);
385 #endif /* !HAVE_SIGACTION */
386 extern void unblock_sigchld (void);
387 extern void hack_environment (saver_info *si);
388 extern void hack_subproc_environment (saver_screen_info *ssi);
389 extern void init_sigchld (void);
390 extern void spawn_screenhack (saver_info *si, Bool first_time_p);
391 extern void kill_screenhack (saver_info *si);
392 extern void suspend_screenhack (saver_info *si, Bool suspend_p);
393 extern Bool screenhack_running_p (saver_info *si);
394 extern void emergency_kill_subproc (saver_info *si);
395 extern Bool select_visual (saver_screen_info *ssi, const char *visual_name);
396 extern void store_saver_status (saver_info *si);
397 extern const char *signal_name (int signal);
398 extern void exec_command (const char *shell, const char *command,
399                           int nice_level);
400
401 /* =======================================================================
402    subprocs diagnostics
403    ======================================================================= */
404
405 extern FILE *real_stderr;
406 extern FILE *real_stdout;
407 extern void initialize_stderr (saver_info *si);
408 extern void reset_stderr (saver_screen_info *ssi);
409 extern void clear_stderr (saver_screen_info *ssi);
410 extern void shutdown_stderr (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 extern Bool display_is_on_console_p (saver_info *si);
427 extern Visual *get_best_gl_visual (saver_screen_info *ssi);
428 extern void check_for_leaks (const char *where);
429
430 extern Atom XA_VROOT, XA_XSETROOT_ID, XA_ESETROOT_PMAP_ID, XA_XROOTPMAP_ID;
431 extern Atom XA_SCREENSAVER, XA_SCREENSAVER_VERSION, XA_SCREENSAVER_ID;
432 extern Atom XA_SCREENSAVER_STATUS, XA_LOCK, XA_BLANK;
433 extern Atom XA_DEMO, XA_PREFS;
434
435 #endif /* __XSCREENSAVER_H__ */