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__
25 extern char *progname;
26 extern char *progclass;
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;
34 #define countof(x) (sizeof((x))/sizeof((*x)))
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.
41 The saver_preferences structure (prefs.h) holds all the user-specified
42 parameters, read from the command line, the resource database, or entered
47 saver_preferences prefs;
50 saver_screen_info *screens;
51 saver_screen_info *default_screen; /* ...on which dialogs will appear. */
54 /* =======================================================================
55 global connection info
56 ======================================================================= */
61 /* =======================================================================
63 ======================================================================= */
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;
70 # ifdef HAVE_MIT_SAVER_EXTENSION
71 int mit_saver_ext_event_number;
72 int mit_saver_ext_error_number;
74 # ifdef HAVE_SGI_SAVER_EXTENSION
75 int sgi_saver_ext_event_number;
76 int sgi_saver_ext_error_number;
80 /* =======================================================================
82 ======================================================================= */
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. */
92 /* =======================================================================
93 locking and runtime privileges
94 ======================================================================= */
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 */
100 Bool locking_disabled_p; /* Sometimes locking is impossible. */
101 char *nolock_reason; /* This is why. */
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
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-
112 Window passwd_dialog; /* The password dialog, if its up. */
113 passwd_dialog_data *pw_data; /* Other info necessary to draw it. */
115 int unlock_failures; /* Counts failed login attempts while the
119 /* =======================================================================
121 ======================================================================= */
123 Bool demoing_p; /* Whether we are demoing a single hack
126 Window splash_dialog; /* The splash dialog, if its up. */
127 splash_dialog_data *sp_data; /* Other info necessary to draw it. */
130 /* =======================================================================
132 ======================================================================= */
134 XtIntervalId lock_id; /* Timer to implement `prefs.lock_timeout' */
135 XtIntervalId cycle_id; /* Timer to implement `prefs.cycle' */
136 XtIntervalId timer_id; /* Timer to implement `prefs.timeout' */
137 XtIntervalId watchdog_id; /* Timer to implement `prefs.watchdog */
138 XtIntervalId check_pointer_timer_id; /* `prefs.pointer_timeout' */
140 time_t last_activity_time; /* Used only when no server exts. */
141 time_t last_wall_clock_time; /* Used to detect laptop suspend. */
142 saver_screen_info *last_activity_screen;
144 Bool emergency_lock_p; /* Set when the wall clock has jumped
145 (presumably due to laptop suspend) and we
146 need to lock down right away instead of
147 waiting for the lock timer to go off. */
150 /* =======================================================================
152 ======================================================================= */
154 int selection_mode; /* Set to -1 if the NEXT ClientMessage has just
155 been received; set to -2 if PREV has just
156 been received; set to N if SELECT or DEMO N
157 has been received. (This is kind of nasty.)
160 /* =======================================================================
162 ======================================================================= */
164 XtIntervalId stderr_popup_timer;
169 /* This structure holds all the data that applies to the screen-specific parts
170 of the display connection; if the display has multiple screens, there will
171 be one of these for each screen.
173 struct saver_screen_info {
177 Widget toplevel_shell;
179 /* =======================================================================
181 ======================================================================= */
183 Window screensaver_window; /* The window that will impersonate the root,
184 when the screensaver activates. Note that
185 the window stored here may change, as we
186 destroy and recreate it on different
188 Colormap cmap; /* The colormap that goes with the window. */
189 Bool install_cmap_p; /* Whether this screen should have its own
190 colormap installed, for whichever of several
191 reasons. This is definitive (even a false
192 value here overrides prefs->install_cmap_p.)
194 Visual *current_visual; /* The visual of the window. */
195 Visual *default_visual; /* visual to use when none other specified */
196 int current_depth; /* How deep the visual (and the window) are. */
198 Window real_vroot; /* The original virtual-root window. */
199 Window real_vroot_value; /* What was in the __SWM_VROOT property. */
201 Cursor cursor; /* A blank cursor that goes with the
203 unsigned long black_pixel; /* Black, allocated from `cmap'. */
205 int blank_vp_x, blank_vp_y; /* Where the virtual-scrolling viewport was
206 when the screen went blank. We need to
207 prevent the X server from letting the mouse
208 bump the edges to scroll while the screen
209 is locked, so we reset to this when it has
210 moved, and the lock dialog is up... */
212 # ifdef HAVE_MIT_SAVER_EXTENSION
213 Window server_mit_saver_window;
217 /* =======================================================================
219 ======================================================================= */
221 Colormap demo_cmap; /* The colormap that goes with the dialogs:
222 this might be the same as `cmap' so care
223 must be taken not to free it while it's
226 /* =======================================================================
228 ======================================================================= */
230 int poll_mouse_last_root_x; /* Used only when no server exts. */
231 int poll_mouse_last_root_y;
232 Window poll_mouse_last_child;
233 unsigned int poll_mouse_last_mask;
236 /* =======================================================================
238 ======================================================================= */
240 int current_hack; /* Index into `prefs.screenhacks' */
245 int stderr_line_height;
246 XFontStruct *stderr_font;
248 Window stderr_overlay_window; /* Used if the server has overlay planes */
249 Colormap stderr_cmap;
255 /* =======================================================================
256 server extensions and virtual roots
257 ======================================================================= */
259 extern void restore_real_vroot (saver_info *si);
260 extern void disable_builtin_screensaver (saver_info *, Bool unblank_screen_p);
261 extern Bool ensure_no_screensaver_running (Display *, Screen *);
263 #ifdef HAVE_MIT_SAVER_EXTENSION
264 extern Bool query_mit_saver_extension (saver_info *);
266 #ifdef HAVE_SGI_SAVER_EXTENSION
267 extern Bool query_sgi_saver_extension (saver_info *);
269 #ifdef HAVE_XIDLE_EXTENSION
270 extern Bool query_xidle_extension (saver_info *);
272 #ifdef HAVE_PROC_INTERRUPTS
273 extern Bool query_proc_interrupts_available (saver_info *, const char **why);
276 /* Display Power Management System (DPMS) interface. */
277 extern Bool monitor_powered_on_p (saver_info *si);
278 extern void monitor_power_on (saver_info *si);
281 /* =======================================================================
283 ======================================================================= */
285 extern void initialize_screensaver_window (saver_info *si);
286 extern void raise_window (saver_info *si,
287 Bool inhibit_fade, Bool between_hacks_p,
289 extern Bool blank_screen (saver_info *si);
290 extern void unblank_screen (saver_info *si);
292 extern void get_screen_viewport (saver_screen_info *ssi,
293 int *x_ret, int *y_ret,
294 int *w_ret, int *h_ret,
298 /* =======================================================================
300 ======================================================================= */
303 extern Bool unlock_p (saver_info *si);
304 extern Bool lock_priv_init (int argc, char **argv, Bool verbose_p);
305 extern Bool lock_init (int argc, char **argv, Bool verbose_p);
306 extern Bool passwd_valid_p (const char *typed_passwd, Bool verbose_p);
307 extern void set_locked_p (saver_info *si, Bool locked_p);
308 #endif /* NO_LOCKING */
310 extern int move_mouse_grab (saver_info *si, Window to, Cursor cursor);
313 /* =======================================================================
315 ======================================================================= */
317 extern void hack_uid (saver_info *si);
318 extern void describe_uids (saver_info *si, FILE *out);
320 /* =======================================================================
322 ======================================================================= */
324 extern void draw_shaded_rectangle (Display *dpy, Window window,
326 int width, int height,
328 unsigned long top_color,
329 unsigned long bottom_color);
330 extern int string_width (XFontStruct *font, char *s);
332 extern void make_splash_dialog (saver_info *si);
333 extern void handle_splash_event (saver_info *si, XEvent *e);
334 extern void skull (Display *, Window, GC, GC, int, int, int, int);
337 /* =======================================================================
339 ======================================================================= */
341 extern void start_notice_events_timer (saver_info *, Window, Bool verbose_p);
342 extern void cycle_timer (XtPointer si, XtIntervalId *id);
343 extern void activate_lock_timer (XtPointer si, XtIntervalId *id);
344 extern void reset_watchdog_timer (saver_info *si, Bool on_p);
345 extern void idle_timer (XtPointer si, XtIntervalId *id);
346 extern void sleep_until_idle (saver_info *si, Bool until_idle_p);
348 /* =======================================================================
350 ======================================================================= */
352 extern Bool handle_clientmessage (saver_info *, XEvent *, Bool);
353 extern void maybe_reload_init_file (saver_info *);
355 /* =======================================================================
357 ======================================================================= */
359 extern void hack_environment (saver_info *si);
360 extern void hack_subproc_environment (saver_screen_info *ssi);
361 extern void init_sigchld (void);
362 extern void spawn_screenhack (saver_info *si, Bool first_time_p);
363 extern void kill_screenhack (saver_info *si);
364 extern void suspend_screenhack (saver_info *si, Bool suspend_p);
365 extern Bool screenhack_running_p (saver_info *si);
366 extern void emergency_kill_subproc (saver_info *si);
367 extern Bool select_visual (saver_screen_info *ssi, const char *visual_name);
368 extern const char *signal_name (int signal);
370 /* =======================================================================
372 ======================================================================= */
374 extern FILE *real_stderr;
375 extern FILE *real_stdout;
376 extern void initialize_stderr (saver_info *si);
377 extern void reset_stderr (saver_screen_info *ssi);
378 extern void clear_stderr (saver_screen_info *ssi);
381 /* =======================================================================
383 ======================================================================= */
385 extern const char *blurb (void);
386 extern void save_argv (int argc, char **argv);
387 extern void saver_exit (saver_info *si, int status, const char *core_reason);
388 extern void restart_process (saver_info *si);
390 extern int saver_ehandler (Display *dpy, XErrorEvent *error);
391 extern int BadWindow_ehandler (Display *dpy, XErrorEvent *error);
392 extern Bool window_exists_p (Display *dpy, Window window);
393 extern char *timestring (void);
394 extern Bool display_is_on_console_p (saver_info *si);
396 extern Atom XA_VROOT, XA_XSETROOT_ID;
397 extern Atom XA_SCREENSAVER, XA_SCREENSAVER_VERSION, XA_SCREENSAVER_ID;
398 extern Atom XA_SCREENSAVER_TIME;
399 extern Atom XA_DEMO, XA_PREFS;
401 #endif /* __XSCREENSAVER_H__ */