1 /* xscreensaver, Copyright (c) 1993-1998 Jamie Zawinski <jwz@jwz.org>
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
12 #ifndef __XSCREENSAVER_H__
13 #define __XSCREENSAVER_H__
23 extern char *progname;
24 extern char *progclass;
26 typedef struct saver_preferences saver_preferences;
27 typedef struct saver_info saver_info;
28 typedef struct saver_screen_info saver_screen_info;
29 typedef struct passwd_dialog_data passwd_dialog_data;
30 typedef struct splash_dialog_data splash_dialog_data;
33 #define countof(x) (sizeof((x))/sizeof((*x)))
37 /* This structure holds all the user-specified parameters, read from the
38 command line, the resource database, or entered through a dialog box.
40 struct saver_preferences {
41 Bool verbose_p; /* whether to print out lots of status info */
42 Bool timestamp_p; /* whether to mark messages with a timestamp */
43 Bool debug_p; /* pay no mind to the man behind the curtain */
44 Bool xsync_p; /* whether XSynchronize has been called */
46 Bool lock_p; /* whether to lock as well as save */
47 Bool lock_vt_p; /* whether to lock VTs too, if possible */
48 Bool fade_p; /* whether to fade to black, if possible */
49 Bool unfade_p; /* whether to fade from black, if possible */
50 int fade_seconds; /* how long that should take */
51 int fade_ticks; /* how many ticks should be used */
53 Bool install_cmap_p; /* whether we should use our own colormap
54 when using the screen's default visual. */
56 char **screenhacks; /* the programs to run */
57 int screenhacks_count;
59 int nice_inferior; /* nice value for subprocs */
61 Time initial_delay; /* how long to sleep after launch */
62 Time splash_duration; /* how long the splash screen stays up */
63 Time timeout; /* how much idle time before activation */
64 Time lock_timeout; /* how long after activation locking starts */
65 Time cycle; /* how long each hack should run */
66 Time passwd_timeout; /* how much time before pw dialog goes down */
67 Time pointer_timeout; /* how often to check mouse position */
68 Time notice_events_timeout; /* how long after window creation to select */
69 Time watchdog_timeout; /* how often to re-raise and re-blank screen */
71 Bool use_xidle_extension; /* which extension to use, if possible */
72 Bool use_mit_saver_extension;
73 Bool use_sgi_saver_extension;
75 char *shell; /* where to find /bin/sh */
77 char *help_url; /* Where the help document resides. */
78 char *load_url_command; /* How one loads URLs. */
82 /* This structure holds all the data that applies to the program as a whole,
83 or to the non-screen-specific parts of the display connection.
87 saver_preferences prefs;
90 saver_screen_info *screens;
91 saver_screen_info *default_screen; /* ...on which dialogs will appear. */
93 time_t init_file_date; /* The date (from stat()) of the .xscreensaver
94 file the last time this process read or
97 /* =======================================================================
98 global connection info
99 ======================================================================= */
105 /* =======================================================================
106 server extension info
107 ======================================================================= */
109 # ifdef HAVE_MIT_SAVER_EXTENSION
110 int mit_saver_ext_event_number;
111 int mit_saver_ext_error_number;
113 # ifdef HAVE_SGI_SAVER_EXTENSION
114 int sgi_saver_ext_event_number;
115 int sgi_saver_ext_error_number;
119 /* =======================================================================
121 ======================================================================= */
123 Bool screen_blanked_p; /* Whether the saver is currently active. */
124 Window mouse_grab_window; /* Window holding our mouse grab */
125 Window keyboard_grab_window; /* Window holding our keyboard grab */
126 Bool fading_possible_p; /* Whether fading to/from black is possible. */
129 /* =======================================================================
130 locking and runtime privileges
131 ======================================================================= */
133 Bool locked_p; /* Whether the screen is currently locked. */
134 Bool dbox_up_p; /* Whether the demo-mode or passwd dialogs
135 are currently visible */
137 Bool locking_disabled_p; /* Sometimes locking is impossible. */
138 char *nolock_reason; /* This is why. */
140 char *orig_uid; /* What uid/gid we had at startup, before
141 discarding privileges. */
142 char *uid_message; /* Any diagnostics from our attempt to
143 discard privileges (printed only in
145 Bool dangerous_uid_p; /* Set to true if we're running as a user id
146 which is known to not be a normal, non-
149 Window passwd_dialog; /* The password dialog, if its up. */
150 passwd_dialog_data *pw_data; /* Other info necessary to draw it. */
153 /* =======================================================================
155 ======================================================================= */
157 Bool demo_mode_p; /* Whether demo-mode is active */
158 char *demo_hack; /* The hack that has been selected from the
159 dialog box, which should be run next. */
161 Window splash_dialog; /* The splash dialog, if its up. */
162 splash_dialog_data *sp_data; /* Other info necessary to draw it. */
165 /* =======================================================================
167 ======================================================================= */
169 XtIntervalId lock_id; /* Timer to implement `prefs.lock_timeout' */
170 XtIntervalId cycle_id; /* Timer to implement `prefs.cycle' */
171 XtIntervalId timer_id; /* Timer to implement `prefs.timeout' */
172 XtIntervalId watchdog_id; /* Timer to implement `prefs.watchdog */
173 XtIntervalId check_pointer_timer_id; /* `prefs.pointer_timeout' */
175 time_t last_activity_time; /* Used only when no server exts. */
176 saver_screen_info *last_activity_screen;
179 /* =======================================================================
181 ======================================================================= */
183 int selection_mode; /* Set to -1 if the NEXT ClientMessage has just
184 been received; set to -2 if PREV has just
185 been received; set to N if SELECT has
186 been received. (This is kind of nasty.) */
188 /* =======================================================================
190 ======================================================================= */
192 XtIntervalId stderr_popup_timer;
197 /* This structure holds all the data that applies to the screen-specific parts
198 of the display connection; if the display has multiple screens, there will
199 be one of these for each screen.
201 struct saver_screen_info {
205 Widget toplevel_shell;
207 /* =======================================================================
209 ======================================================================= */
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
216 Colormap cmap; /* The colormap that goes with the window. */
217 Bool install_cmap_p; /* whether we should use our own colormap.
218 This can be overridden on a per-hack basis.
220 Visual *current_visual; /* The visual of the window. */
221 Visual *default_visual; /* visual to use when none other specified */
222 int current_depth; /* How deep the visual (and the window) are. */
224 Window real_vroot; /* The original virtual-root window. */
225 Window real_vroot_value; /* What was in the __SWM_VROOT property. */
227 Cursor cursor; /* A blank cursor that goes with the
229 unsigned long black_pixel; /* Black, allocated from `cmap'. */
231 # ifdef HAVE_MIT_SAVER_EXTENSION
232 Window server_mit_saver_window;
236 /* =======================================================================
238 ======================================================================= */
240 Colormap demo_cmap; /* The colormap that goes with the dialogs:
241 this might be the same as `cmap' so care
242 must be taken not to free it while it's
245 /* =======================================================================
247 ======================================================================= */
249 int poll_mouse_last_root_x; /* Used only when no server exts. */
250 int poll_mouse_last_root_y;
251 Window poll_mouse_last_child;
252 unsigned int poll_mouse_last_mask;
255 /* =======================================================================
257 ======================================================================= */
259 int current_hack; /* Index into `prefs.screenhacks' */
264 int stderr_line_height;
265 XFontStruct *stderr_font;
267 Window stderr_overlay_window; /* Used if the server has overlay planes */
268 Colormap stderr_cmap;
274 /* =======================================================================
275 server extensions and virtual roots
276 ======================================================================= */
278 extern void restore_real_vroot (saver_info *si);
279 extern void disable_builtin_screensaver (saver_info *si, Bool turn_off_p);
280 extern Bool ensure_no_screensaver_running (Display *, Screen *);
282 #ifdef HAVE_MIT_SAVER_EXTENSION
283 extern Bool query_mit_saver_extension (saver_info *);
285 #ifdef HAVE_SGI_SAVER_EXTENSION
286 extern Bool query_sgi_saver_extension (saver_info *);
289 /* Display Power Management System (DPMS) interface. */
290 extern Bool monitor_powered_on_p (saver_info *si);
291 extern void monitor_power_on (saver_info *si);
294 /* =======================================================================
296 ======================================================================= */
298 extern void initialize_screensaver_window (saver_info *si);
299 extern void raise_window (saver_info *si,
300 Bool inhibit_fade, Bool between_hacks_p,
302 extern void blank_screen (saver_info *si);
303 extern void unblank_screen (saver_info *si);
304 extern void grab_keyboard_and_mouse (saver_info *si, Window, Cursor);
305 extern void ungrab_keyboard_and_mouse (saver_info *si);
307 /* =======================================================================
309 ======================================================================= */
312 extern Bool unlock_p (saver_info *si);
313 extern Bool lock_init (int argc, char **argv);
314 extern Bool passwd_valid_p (const char *typed_passwd);
316 extern void make_passwd_window (saver_info *si);
317 extern void draw_passwd_window (saver_info *si);
318 extern void update_passwd_window (saver_info *si, const char *printed_passwd,
320 extern void destroy_passwd_window (saver_info *si);
322 #endif /* NO_LOCKING */
324 /* =======================================================================
326 ======================================================================= */
328 extern void hack_uid (saver_info *si);
329 extern void describe_uids (saver_info *si, FILE *out);
331 /* =======================================================================
333 ======================================================================= */
335 extern void draw_shaded_rectangle (Display *dpy, Window window,
337 int width, int height,
339 unsigned long top_color,
340 unsigned long bottom_color);
341 extern int string_width (XFontStruct *font, char *s);
345 extern void demo_mode (saver_info *si);
346 extern void demo_mode_restart_process (saver_info *si);
347 extern void create_demo_dialog (Widget, Visual *, Colormap);
348 extern void create_resources_dialog (Widget, Visual *, Colormap);
351 #if !defined(NO_LOCKING) || !defined(NO_DEMO_MODE)
352 extern void pop_up_dialog_box (Widget dialog, Widget form, int where);
353 extern void format_into_label (Widget label, const char *arg);
354 extern void steal_focus_and_colormap (Widget dialog);
357 extern void make_splash_dialog (saver_info *si);
358 extern void handle_splash_event (saver_info *si, XEvent *e);
359 extern void skull (Display *, Window, GC, GC, int, int, int, int);
362 /* =======================================================================
364 ======================================================================= */
366 extern void start_notice_events_timer (saver_info *, Window);
367 extern void cycle_timer (XtPointer si, XtIntervalId *id);
368 extern void activate_lock_timer (XtPointer si, XtIntervalId *id);
369 extern void reset_watchdog_timer (saver_info *si, Bool on_p);
370 extern void idle_timer (XtPointer si, XtIntervalId *id);
371 extern void sleep_until_idle (saver_info *si, Bool until_idle_p);
373 /* =======================================================================
375 ======================================================================= */
377 extern Bool handle_clientmessage (saver_info *, XEvent *, Bool);
379 /* =======================================================================
381 ======================================================================= */
383 extern void hack_environment (saver_info *si);
384 extern void init_sigchld (void);
385 extern void spawn_screenhack (saver_info *si, Bool first_time_p);
386 extern void kill_screenhack (saver_info *si);
387 extern void suspend_screenhack (saver_info *si, Bool suspend_p);
388 extern Bool screenhack_running_p (saver_info *si);
389 extern void emergency_kill_subproc (saver_info *si);
390 extern Bool select_visual (saver_screen_info *ssi, const char *visual_name);
391 extern const char *signal_name (int signal);
393 /* =======================================================================
395 ======================================================================= */
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);
403 /* =======================================================================
404 the .xscreensaver file
405 ======================================================================= */
407 extern int read_init_file (saver_info *si);
408 extern int write_init_file (saver_info *si);
409 extern int maybe_reload_init_file (saver_info *si);
410 extern void get_resources (saver_info *si);
413 /* =======================================================================
415 ======================================================================= */
417 extern const char *blurb (void);
418 extern void save_argv (int argc, char **argv);
419 extern void saver_exit (saver_info *si, int status, const char *core_reason);
420 extern void restart_process (saver_info *si);
422 extern int saver_ehandler (Display *dpy, XErrorEvent *error);
423 extern int BadWindow_ehandler (Display *dpy, XErrorEvent *error);
424 extern Bool window_exists_p (Display *dpy, Window window);
425 extern char *timestring (void);
427 extern Atom XA_VROOT, XA_XSETROOT_ID;
428 extern Atom XA_SCREENSAVER, XA_SCREENSAVER_VERSION, XA_SCREENSAVER_ID;
429 extern Atom XA_SCREENSAVER_TIME;
430 extern Atom XA_DEMO, XA_PREFS;
432 #endif /* __XSCREENSAVER_H__ */