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