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