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