http://ftp.x.org/contrib/applications/xscreensaver-3.01.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 # ifdef HAVE_MIT_SAVER_EXTENSION
66   int mit_saver_ext_event_number;
67   int mit_saver_ext_error_number;
68 # endif
69 # ifdef HAVE_SGI_SAVER_EXTENSION
70   int sgi_saver_ext_event_number;
71   int sgi_saver_ext_error_number;
72 # endif
73
74
75   /* =======================================================================
76      blanking
77      ======================================================================= */
78
79   Bool screen_blanked_p;        /* Whether the saver is currently active. */
80   Window mouse_grab_window;     /* Window holding our mouse grab */
81   Window keyboard_grab_window;  /* Window holding our keyboard grab */
82
83
84   /* =======================================================================
85      locking and runtime privileges
86      ======================================================================= */
87
88   Bool locked_p;                /* Whether the screen is currently locked. */
89   Bool dbox_up_p;               /* Whether the demo-mode or passwd dialogs
90                                    are currently visible */
91
92   Bool locking_disabled_p;      /* Sometimes locking is impossible. */
93   char *nolock_reason;          /* This is why. */
94
95   char *orig_uid;               /* What uid/gid we had at startup, before
96                                    discarding privileges. */
97   char *uid_message;            /* Any diagnostics from our attempt to
98                                    discard privileges (printed only in
99                                    -verbose mode.) */
100   Bool dangerous_uid_p;         /* Set to true if we're running as a user id
101                                    which is known to not be a normal, non-
102                                    privileged user. */
103
104   Window passwd_dialog;         /* The password dialog, if its up. */
105   passwd_dialog_data *pw_data;  /* Other info necessary to draw it. */
106
107   int unlock_failures;          /* Counts failed login attempts while the
108                                    screen is locked. */
109
110
111   /* =======================================================================
112      demoing
113      ======================================================================= */
114
115   Bool demoing_p;               /* Whether we are demoing a single hack
116                                    (without UI.) */
117
118   Window splash_dialog;         /* The splash dialog, if its up. */
119   splash_dialog_data *sp_data;  /* Other info necessary to draw it. */
120
121
122   /* =======================================================================
123      timers
124      ======================================================================= */
125
126   XtIntervalId lock_id;         /* Timer to implement `prefs.lock_timeout' */
127   XtIntervalId cycle_id;        /* Timer to implement `prefs.cycle' */
128   XtIntervalId timer_id;        /* Timer to implement `prefs.timeout' */
129   XtIntervalId watchdog_id;     /* Timer to implement `prefs.watchdog */
130   XtIntervalId check_pointer_timer_id;  /* `prefs.pointer_timeout' */
131
132   time_t last_activity_time;               /* Used only when no server exts. */
133   saver_screen_info *last_activity_screen;
134
135
136   /* =======================================================================
137      remote control
138      ======================================================================= */
139
140   int selection_mode;           /* Set to -1 if the NEXT ClientMessage has just
141                                    been received; set to -2 if PREV has just
142                                    been received; set to N if SELECT or DEMO N
143                                    has been received.  (This is kind of nasty.)
144                                  */
145
146   /* =======================================================================
147      subprocs
148      ======================================================================= */
149
150   XtIntervalId stderr_popup_timer;
151
152 };
153
154
155 /* This structure holds all the data that applies to the screen-specific parts
156    of the display connection; if the display has multiple screens, there will
157    be one of these for each screen.
158  */
159 struct saver_screen_info {
160   saver_info *global;
161
162   Screen *screen;
163   Widget toplevel_shell;
164
165   /* =======================================================================
166      blanking
167      ======================================================================= */
168
169   Window screensaver_window;    /* The window that will impersonate the root,
170                                    when the screensaver activates.  Note that
171                                    the window stored here may change, as we
172                                    destroy and recreate it on different
173                                    visuals. */
174   Colormap cmap;                /* The colormap that goes with the window. */
175   Bool install_cmap_p;          /* whether we should use our own colormap.
176                                    This can be overridden on a per-hack basis.
177                                  */
178   Visual *current_visual;       /* The visual of the window. */
179   Visual *default_visual;       /* visual to use when none other specified */
180   int current_depth;            /* How deep the visual (and the window) are. */
181
182   Window real_vroot;            /* The original virtual-root window. */
183   Window real_vroot_value;      /* What was in the __SWM_VROOT property. */
184
185   Cursor cursor;                /* A blank cursor that goes with the
186                                    real root window. */
187   unsigned long black_pixel;    /* Black, allocated from `cmap'. */
188
189 # ifdef HAVE_MIT_SAVER_EXTENSION
190   Window server_mit_saver_window;
191 # endif
192
193
194   /* =======================================================================
195      demoing
196      ======================================================================= */
197
198   Colormap demo_cmap;           /* The colormap that goes with the dialogs:
199                                    this might be the same as `cmap' so care
200                                    must be taken not to free it while it's
201                                    still in use. */
202
203   /* =======================================================================
204      timers
205      ======================================================================= */
206
207   int poll_mouse_last_root_x;           /* Used only when no server exts. */
208   int poll_mouse_last_root_y;
209   Window poll_mouse_last_child;
210   unsigned int poll_mouse_last_mask;
211
212
213   /* =======================================================================
214      subprocs
215      ======================================================================= */
216
217   int current_hack;             /* Index into `prefs.screenhacks' */
218   pid_t pid;
219
220   int stderr_text_x;
221   int stderr_text_y;
222   int stderr_line_height;
223   XFontStruct *stderr_font;
224   GC stderr_gc;
225   Window stderr_overlay_window;    /* Used if the server has overlay planes */
226   Colormap stderr_cmap;
227 };
228
229
230 \f
231
232 /* =======================================================================
233    server extensions and virtual roots
234    ======================================================================= */
235
236 extern void restore_real_vroot (saver_info *si);
237 extern void disable_builtin_screensaver (saver_info *, Bool unblank_screen_p);
238 extern Bool ensure_no_screensaver_running (Display *, Screen *);
239
240 #ifdef HAVE_MIT_SAVER_EXTENSION
241 extern Bool query_mit_saver_extension (saver_info *);
242 #endif
243 #ifdef HAVE_SGI_SAVER_EXTENSION
244 extern Bool query_sgi_saver_extension (saver_info *);
245 #endif
246 #ifdef HAVE_XIDLE_EXTENSION
247 extern Bool query_xidle_extension (saver_info *);
248 #endif
249
250 /* Display Power Management System (DPMS) interface. */
251 extern Bool monitor_powered_on_p (saver_info *si);
252 extern void monitor_power_on (saver_info *si);
253
254
255 /* =======================================================================
256    blanking
257    ======================================================================= */
258
259 extern void initialize_screensaver_window (saver_info *si);
260 extern void raise_window (saver_info *si,
261                             Bool inhibit_fade, Bool between_hacks_p,
262                             Bool dont_clear);
263 extern void blank_screen (saver_info *si);
264 extern void unblank_screen (saver_info *si);
265 extern Bool grab_keyboard_and_mouse (saver_info *si, Window, Cursor);
266 extern void ungrab_keyboard_and_mouse (saver_info *si);
267
268 /* =======================================================================
269    locking
270    ======================================================================= */
271
272 #ifndef NO_LOCKING
273 extern Bool unlock_p (saver_info *si);
274 extern Bool lock_init (int argc, char **argv);
275 extern Bool passwd_valid_p (const char *typed_passwd);
276
277 extern void make_passwd_window (saver_info *si);
278 extern void draw_passwd_window (saver_info *si);
279 extern void update_passwd_window (saver_info *si, const char *printed_passwd,
280                                   float ratio);
281 extern void destroy_passwd_window (saver_info *si);
282
283 #endif /* NO_LOCKING */
284
285 /* =======================================================================
286    runtime privileges
287    ======================================================================= */
288
289 extern void hack_uid (saver_info *si);
290 extern void describe_uids (saver_info *si, FILE *out);
291
292 /* =======================================================================
293    demoing
294    ======================================================================= */
295
296 extern void draw_shaded_rectangle (Display *dpy, Window window,
297                                    int x, int y,
298                                    int width, int height,
299                                    int thickness,
300                                    unsigned long top_color,
301                                    unsigned long bottom_color);
302 extern int string_width (XFontStruct *font, char *s);
303
304 extern void make_splash_dialog (saver_info *si);
305 extern void handle_splash_event (saver_info *si, XEvent *e);
306 extern void skull (Display *, Window, GC, GC, int, int, int, int);
307
308
309 /* =======================================================================
310    timers
311    ======================================================================= */
312
313 extern void start_notice_events_timer (saver_info *, Window);
314 extern void cycle_timer (XtPointer si, XtIntervalId *id);
315 extern void activate_lock_timer (XtPointer si, XtIntervalId *id);
316 extern void reset_watchdog_timer (saver_info *si, Bool on_p);
317 extern void idle_timer (XtPointer si, XtIntervalId *id);
318 extern void sleep_until_idle (saver_info *si, Bool until_idle_p);
319
320 /* =======================================================================
321    remote control
322    ======================================================================= */
323
324 extern Bool handle_clientmessage (saver_info *, XEvent *, Bool);
325 extern void maybe_reload_init_file (saver_info *);
326
327 /* =======================================================================
328    subprocs
329    ======================================================================= */
330
331 extern void hack_environment (saver_info *si);
332 extern void hack_subproc_environment (saver_screen_info *ssi);
333 extern void init_sigchld (void);
334 extern void spawn_screenhack (saver_info *si, Bool first_time_p);
335 extern void kill_screenhack (saver_info *si);
336 extern void suspend_screenhack (saver_info *si, Bool suspend_p);
337 extern Bool screenhack_running_p (saver_info *si);
338 extern void emergency_kill_subproc (saver_info *si);
339 extern Bool select_visual (saver_screen_info *ssi, const char *visual_name);
340 extern const char *signal_name (int signal);
341
342 /* =======================================================================
343    subprocs diagnostics
344    ======================================================================= */
345
346 extern FILE *real_stderr;
347 extern FILE *real_stdout;
348 extern void initialize_stderr (saver_info *si);
349 extern void reset_stderr (saver_screen_info *ssi);
350 extern void clear_stderr (saver_screen_info *ssi);
351
352
353 /* =======================================================================
354    misc
355    ======================================================================= */
356
357 extern const char *blurb (void);
358 extern void save_argv (int argc, char **argv);
359 extern void saver_exit (saver_info *si, int status, const char *core_reason);
360 extern void restart_process (saver_info *si);
361
362 extern int saver_ehandler (Display *dpy, XErrorEvent *error);
363 extern int BadWindow_ehandler (Display *dpy, XErrorEvent *error);
364 extern Bool window_exists_p (Display *dpy, Window window);
365 extern char *timestring (void);
366
367 extern Atom XA_VROOT, XA_XSETROOT_ID;
368 extern Atom XA_SCREENSAVER, XA_SCREENSAVER_VERSION, XA_SCREENSAVER_ID;
369 extern Atom XA_SCREENSAVER_TIME;
370 extern Atom XA_DEMO, XA_PREFS;
371
372 #endif /* __XSCREENSAVER_H__ */