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