1 /* xscreensaver, Copyright (c) 1993-2006 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__
24 # include <signal.h> /* for sigset_t */
29 extern char *progname;
30 extern char *progclass;
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;
38 #define countof(x) (sizeof((x))/sizeof((*x)))
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.
45 The saver_preferences structure (prefs.h) holds all the user-specified
46 parameters, read from the command line, the resource database, or entered
51 saver_preferences prefs;
54 saver_screen_info *screens;
55 saver_screen_info *default_screen; /* ...on which dialogs will appear. */
58 /* =======================================================================
59 global connection info
60 ======================================================================= */
65 /* =======================================================================
67 ======================================================================= */
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;
75 # ifdef HAVE_MIT_SAVER_EXTENSION
76 int mit_saver_ext_event_number;
77 int mit_saver_ext_error_number;
79 # ifdef HAVE_SGI_SAVER_EXTENSION
80 int sgi_saver_ext_event_number;
81 int sgi_saver_ext_error_number;
84 int randr_event_number;
85 int randr_error_number;
89 /* =======================================================================
91 ======================================================================= */
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. (Deprecated:
101 users should use "xset dpms force off"
103 time_t blank_time; /* The time at which the screen was blanked
104 (if currently blanked) or unblanked (if
108 /* =======================================================================
109 locking and runtime privileges
110 ======================================================================= */
112 Bool locked_p; /* Whether the screen is currently locked. */
113 Bool dbox_up_p; /* Whether the demo-mode or passwd dialogs
114 are currently visible */
116 Bool locking_disabled_p; /* Sometimes locking is impossible. */
117 char *nolock_reason; /* This is why. */
119 char *orig_uid; /* What uid/gid we had at startup, before
120 discarding privileges. */
121 char *uid_message; /* Any diagnostics from our attempt to
122 discard privileges (printed only in
124 Bool dangerous_uid_p; /* Set to true if we're running as a user id
125 which is known to not be a normal, non-
128 Window passwd_dialog; /* The password dialog, if its up. */
129 passwd_dialog_data *pw_data; /* Other info necessary to draw it. */
131 int unlock_failures; /* Counts failed login attempts while the
134 char *unlock_typeahead; /* If the screen is locked, and the user types
135 a character, we assume that it is the first
136 character of the password. It's stored here
137 for the password dialog to use to populate
141 /* =======================================================================
143 ======================================================================= */
145 Bool demoing_p; /* Whether we are demoing a single hack
148 Window splash_dialog; /* The splash dialog, if its up. */
149 splash_dialog_data *sp_data; /* Other info necessary to draw it. */
152 /* =======================================================================
154 ======================================================================= */
156 XtIntervalId lock_id; /* Timer to implement `prefs.lock_timeout' */
157 XtIntervalId cycle_id; /* Timer to implement `prefs.cycle' */
158 XtIntervalId timer_id; /* Timer to implement `prefs.timeout' */
159 XtIntervalId watchdog_id; /* Timer to implement `prefs.watchdog */
160 XtIntervalId check_pointer_timer_id; /* `prefs.pointer_timeout' */
162 XtIntervalId de_race_id; /* Timer to make sure screen un-blanks */
165 time_t last_activity_time; /* Used only when no server exts. */
166 time_t last_wall_clock_time; /* Used to detect laptop suspend. */
167 saver_screen_info *last_activity_screen;
169 Bool emergency_lock_p; /* Set when the wall clock has jumped
170 (presumably due to laptop suspend) and we
171 need to lock down right away instead of
172 waiting for the lock timer to go off. */
175 /* =======================================================================
177 ======================================================================= */
179 int selection_mode; /* Set to -1 if the NEXT ClientMessage has just
180 been received; set to -2 if PREV has just
181 been received; set to N if SELECT or DEMO N
182 has been received. (This is kind of nasty.)
185 /* =======================================================================
187 ======================================================================= */
189 XtIntervalId stderr_popup_timer;
194 /* This structure holds all the data that applies to the screen-specific parts
195 of the display connection; if the display has multiple screens, there will
196 be one of these for each screen.
198 struct saver_screen_info {
201 int number; /* The internal ordinal of this screen,
202 counting Xinerama rectangles as separate
204 int real_screen_number; /* The number of the underlying X screen on
205 which this rectangle lies. */
206 Screen *screen; /* The X screen in question. */
208 int x, y, width, height; /* The size and position of this rectangle
209 on its underlying X screen. */
211 Bool real_screen_p; /* This will be true of exactly one ssi per
214 Widget toplevel_shell;
216 /* =======================================================================
218 ======================================================================= */
220 Window screensaver_window; /* The window that will impersonate the root,
221 when the screensaver activates. Note that
222 the window stored here may change, as we
223 destroy and recreate it on different
225 Colormap cmap; /* The colormap that goes with the window. */
226 Bool install_cmap_p; /* Whether this screen should have its own
227 colormap installed, for whichever of several
228 reasons. This is definitive (even a false
229 value here overrides prefs->install_cmap_p.)
231 Visual *current_visual; /* The visual of the window. */
232 int current_depth; /* How deep the visual (and the window) are. */
234 Visual *default_visual; /* visual to use when none other specified */
235 Visual *best_gl_visual; /* visual to use for GL hacks */
237 Window real_vroot; /* The original virtual-root window. */
238 Window real_vroot_value; /* What was in the __SWM_VROOT property. */
240 Cursor cursor; /* A blank cursor that goes with the
242 unsigned long black_pixel; /* Black, allocated from `cmap'. */
244 int blank_vp_x, blank_vp_y; /* Where the virtual-scrolling viewport was
245 when the screen went blank. We need to
246 prevent the X server from letting the mouse
247 bump the edges to scroll while the screen
248 is locked, so we reset to this when it has
249 moved, and the lock dialog is up... */
251 # ifdef HAVE_MIT_SAVER_EXTENSION
252 Window server_mit_saver_window;
256 /* =======================================================================
258 ======================================================================= */
260 Colormap demo_cmap; /* The colormap that goes with the dialogs:
261 this might be the same as `cmap' so care
262 must be taken not to free it while it's
265 /* =======================================================================
267 ======================================================================= */
269 int poll_mouse_last_root_x; /* Used only when no server exts. */
270 int poll_mouse_last_root_y;
271 Window poll_mouse_last_child;
272 unsigned int poll_mouse_last_mask;
273 time_t poll_mouse_last_time;
276 /* =======================================================================
278 ======================================================================= */
280 int current_hack; /* Index into `prefs.screenhacks' */
285 int stderr_line_height;
286 XFontStruct *stderr_font;
288 Window stderr_overlay_window; /* Used if the server has overlay planes */
289 Colormap stderr_cmap;
295 /* =======================================================================
296 server extensions and virtual roots
297 ======================================================================= */
299 extern Bool restore_real_vroot (saver_info *si);
300 extern void disable_builtin_screensaver (saver_info *, Bool unblank_screen_p);
301 extern Bool ensure_no_screensaver_running (Display *, Screen *);
303 #ifdef HAVE_MIT_SAVER_EXTENSION
304 extern Bool query_mit_saver_extension (saver_info *);
306 #ifdef HAVE_SGI_SAVER_EXTENSION
307 extern Bool query_sgi_saver_extension (saver_info *);
309 #ifdef HAVE_XIDLE_EXTENSION
310 extern Bool query_xidle_extension (saver_info *);
313 extern Bool query_randr_extension (saver_info *);
315 #ifdef HAVE_PROC_INTERRUPTS
316 extern Bool query_proc_interrupts_available (saver_info *, const char **why);
319 /* Display Power Management System (DPMS) interface. */
320 extern Bool monitor_powered_on_p (saver_info *si);
321 extern void monitor_power_on (saver_info *si);
324 /* =======================================================================
326 ======================================================================= */
328 extern void initialize_screensaver_window (saver_info *si);
329 extern void raise_window (saver_info *si,
330 Bool inhibit_fade, Bool between_hacks_p,
332 extern Bool blank_screen (saver_info *si);
333 extern void unblank_screen (saver_info *si);
334 extern void resize_screensaver_window (saver_info *si);
336 extern void get_screen_viewport (saver_screen_info *ssi,
337 int *x_ret, int *y_ret,
338 int *w_ret, int *h_ret,
339 int target_x, int target_y,
343 /* =======================================================================
345 ======================================================================= */
348 extern Bool unlock_p (saver_info *si);
349 extern Bool lock_priv_init (int argc, char **argv, Bool verbose_p);
350 extern Bool lock_init (int argc, char **argv, Bool verbose_p);
351 extern Bool passwd_valid_p (const char *typed_passwd, Bool verbose_p);
352 #endif /* NO_LOCKING */
354 extern void set_locked_p (saver_info *si, Bool locked_p);
355 extern int move_mouse_grab (saver_info *si, Window to, Cursor cursor,
357 extern int mouse_screen (saver_info *si);
360 /* =======================================================================
362 ======================================================================= */
364 extern void hack_uid (saver_info *si);
365 extern void describe_uids (saver_info *si, FILE *out);
367 /* =======================================================================
369 ======================================================================= */
371 extern void draw_shaded_rectangle (Display *dpy, Window window,
373 int width, int height,
375 unsigned long top_color,
376 unsigned long bottom_color);
377 extern int string_width (XFontStruct *font, char *s);
379 extern void make_splash_dialog (saver_info *si);
380 extern void handle_splash_event (saver_info *si, XEvent *e);
383 /* =======================================================================
385 ======================================================================= */
387 extern void start_notice_events_timer (saver_info *, Window, Bool verbose_p);
388 extern void cycle_timer (XtPointer si, XtIntervalId *id);
389 extern void activate_lock_timer (XtPointer si, XtIntervalId *id);
390 extern void reset_watchdog_timer (saver_info *si, Bool on_p);
391 extern void idle_timer (XtPointer si, XtIntervalId *id);
392 extern void de_race_timer (XtPointer si, XtIntervalId *id);
393 extern void sleep_until_idle (saver_info *si, Bool until_idle_p);
394 extern void reset_timers (saver_info *si);
395 extern void schedule_wakeup_event (saver_info *si, Time when, Bool verbose_p);
398 /* =======================================================================
400 ======================================================================= */
402 extern Bool handle_clientmessage (saver_info *, XEvent *, Bool);
403 extern void maybe_reload_init_file (saver_info *);
405 /* =======================================================================
407 ======================================================================= */
409 extern void handle_signals (saver_info *si);
410 #ifdef HAVE_SIGACTION
411 extern sigset_t block_sigchld (void);
412 #else /* !HAVE_SIGACTION */
413 extern int block_sigchld (void);
414 #endif /* !HAVE_SIGACTION */
415 extern void unblock_sigchld (void);
416 extern void hack_environment (saver_info *si);
417 extern void hack_subproc_environment (saver_screen_info *ssi);
418 extern void init_sigchld (void);
419 extern void spawn_screenhack (saver_info *si, Bool first_time_p);
420 extern pid_t fork_and_exec (saver_screen_info *ssi, const char *command);
421 extern void kill_screenhack (saver_info *si);
422 extern void suspend_screenhack (saver_info *si, Bool suspend_p);
423 extern Bool screenhack_running_p (saver_info *si);
424 extern void emergency_kill_subproc (saver_info *si);
425 extern Bool select_visual (saver_screen_info *ssi, const char *visual_name);
426 extern void store_saver_status (saver_info *si);
427 extern const char *signal_name (int signal);
429 /* =======================================================================
431 ======================================================================= */
433 extern FILE *real_stderr;
434 extern FILE *real_stdout;
435 extern void initialize_stderr (saver_info *si);
436 extern void reset_stderr (saver_screen_info *ssi);
437 extern void clear_stderr (saver_screen_info *ssi);
438 extern void shutdown_stderr (saver_info *si);
441 /* =======================================================================
443 ======================================================================= */
445 extern const char *blurb (void);
446 extern void save_argv (int argc, char **argv);
447 extern void saver_exit (saver_info *si, int status, const char *core_reason);
448 extern void restart_process (saver_info *si);
450 extern int saver_ehandler (Display *dpy, XErrorEvent *error);
451 extern int BadWindow_ehandler (Display *dpy, XErrorEvent *error);
452 extern Bool window_exists_p (Display *dpy, Window window);
453 extern char *timestring (void);
454 extern Bool display_is_on_console_p (saver_info *si);
455 extern Visual *get_best_gl_visual (saver_screen_info *ssi);
456 extern void check_for_leaks (const char *where);
458 extern Atom XA_VROOT, XA_XSETROOT_ID, XA_ESETROOT_PMAP_ID, XA_XROOTPMAP_ID;
459 extern Atom XA_SCREENSAVER, XA_SCREENSAVER_VERSION, XA_SCREENSAVER_ID;
460 extern Atom XA_SCREENSAVER_STATUS, XA_LOCK, XA_BLANK;
461 extern Atom XA_DEMO, XA_PREFS;
463 #endif /* __XSCREENSAVER_H__ */