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*. */
69 # ifdef HAVE_MIT_SAVER_EXTENSION
70 int mit_saver_ext_event_number;
71 int mit_saver_ext_error_number;
73 # ifdef HAVE_SGI_SAVER_EXTENSION
74 int sgi_saver_ext_event_number;
75 int sgi_saver_ext_error_number;
79 /* =======================================================================
81 ======================================================================= */
83 Bool screen_blanked_p; /* Whether the saver is currently active. */
84 Window mouse_grab_window; /* Window holding our mouse grab */
85 Window keyboard_grab_window; /* Window holding our keyboard grab */
88 /* =======================================================================
89 locking and runtime privileges
90 ======================================================================= */
92 Bool locked_p; /* Whether the screen is currently locked. */
93 Bool dbox_up_p; /* Whether the demo-mode or passwd dialogs
94 are currently visible */
96 Bool locking_disabled_p; /* Sometimes locking is impossible. */
97 char *nolock_reason; /* This is why. */
99 char *orig_uid; /* What uid/gid we had at startup, before
100 discarding privileges. */
101 char *uid_message; /* Any diagnostics from our attempt to
102 discard privileges (printed only in
104 Bool dangerous_uid_p; /* Set to true if we're running as a user id
105 which is known to not be a normal, non-
108 Window passwd_dialog; /* The password dialog, if its up. */
109 passwd_dialog_data *pw_data; /* Other info necessary to draw it. */
111 int unlock_failures; /* Counts failed login attempts while the
115 /* =======================================================================
117 ======================================================================= */
119 Bool demoing_p; /* Whether we are demoing a single hack
122 Window splash_dialog; /* The splash dialog, if its up. */
123 splash_dialog_data *sp_data; /* Other info necessary to draw it. */
126 /* =======================================================================
128 ======================================================================= */
130 XtIntervalId lock_id; /* Timer to implement `prefs.lock_timeout' */
131 XtIntervalId cycle_id; /* Timer to implement `prefs.cycle' */
132 XtIntervalId timer_id; /* Timer to implement `prefs.timeout' */
133 XtIntervalId watchdog_id; /* Timer to implement `prefs.watchdog */
134 XtIntervalId check_pointer_timer_id; /* `prefs.pointer_timeout' */
136 time_t last_activity_time; /* Used only when no server exts. */
137 saver_screen_info *last_activity_screen;
140 /* =======================================================================
142 ======================================================================= */
144 int selection_mode; /* Set to -1 if the NEXT ClientMessage has just
145 been received; set to -2 if PREV has just
146 been received; set to N if SELECT or DEMO N
147 has been received. (This is kind of nasty.)
150 /* =======================================================================
152 ======================================================================= */
154 XtIntervalId stderr_popup_timer;
159 /* This structure holds all the data that applies to the screen-specific parts
160 of the display connection; if the display has multiple screens, there will
161 be one of these for each screen.
163 struct saver_screen_info {
167 Widget toplevel_shell;
169 /* =======================================================================
171 ======================================================================= */
173 Window screensaver_window; /* The window that will impersonate the root,
174 when the screensaver activates. Note that
175 the window stored here may change, as we
176 destroy and recreate it on different
178 Colormap cmap; /* The colormap that goes with the window. */
179 Bool install_cmap_p; /* whether we should use our own colormap.
180 This can be overridden on a per-hack basis.
182 Visual *current_visual; /* The visual of the window. */
183 Visual *default_visual; /* visual to use when none other specified */
184 int current_depth; /* How deep the visual (and the window) are. */
186 Window real_vroot; /* The original virtual-root window. */
187 Window real_vroot_value; /* What was in the __SWM_VROOT property. */
189 Cursor cursor; /* A blank cursor that goes with the
191 unsigned long black_pixel; /* Black, allocated from `cmap'. */
193 # ifdef HAVE_MIT_SAVER_EXTENSION
194 Window server_mit_saver_window;
198 /* =======================================================================
200 ======================================================================= */
202 Colormap demo_cmap; /* The colormap that goes with the dialogs:
203 this might be the same as `cmap' so care
204 must be taken not to free it while it's
207 /* =======================================================================
209 ======================================================================= */
211 int poll_mouse_last_root_x; /* Used only when no server exts. */
212 int poll_mouse_last_root_y;
213 Window poll_mouse_last_child;
214 unsigned int poll_mouse_last_mask;
217 /* =======================================================================
219 ======================================================================= */
221 int current_hack; /* Index into `prefs.screenhacks' */
226 int stderr_line_height;
227 XFontStruct *stderr_font;
229 Window stderr_overlay_window; /* Used if the server has overlay planes */
230 Colormap stderr_cmap;
236 /* =======================================================================
237 server extensions and virtual roots
238 ======================================================================= */
240 extern void restore_real_vroot (saver_info *si);
241 extern void disable_builtin_screensaver (saver_info *, Bool unblank_screen_p);
242 extern Bool ensure_no_screensaver_running (Display *, Screen *);
244 #ifdef HAVE_MIT_SAVER_EXTENSION
245 extern Bool query_mit_saver_extension (saver_info *);
247 #ifdef HAVE_SGI_SAVER_EXTENSION
248 extern Bool query_sgi_saver_extension (saver_info *);
250 #ifdef HAVE_XIDLE_EXTENSION
251 extern Bool query_xidle_extension (saver_info *);
254 /* Display Power Management System (DPMS) interface. */
255 extern Bool monitor_powered_on_p (saver_info *si);
256 extern void monitor_power_on (saver_info *si);
259 /* =======================================================================
261 ======================================================================= */
263 extern void initialize_screensaver_window (saver_info *si);
264 extern void raise_window (saver_info *si,
265 Bool inhibit_fade, Bool between_hacks_p,
267 extern void blank_screen (saver_info *si);
268 extern void unblank_screen (saver_info *si);
269 extern Bool grab_keyboard_and_mouse (saver_info *si, Window, Cursor);
270 extern void ungrab_keyboard_and_mouse (saver_info *si);
272 /* =======================================================================
274 ======================================================================= */
277 extern Bool unlock_p (saver_info *si);
278 extern Bool lock_init (int argc, char **argv, Bool verbose_p);
279 extern Bool passwd_valid_p (const char *typed_passwd, Bool verbose_p);
281 extern void make_passwd_window (saver_info *si);
282 extern void draw_passwd_window (saver_info *si);
283 extern void update_passwd_window (saver_info *si, const char *printed_passwd,
285 extern void destroy_passwd_window (saver_info *si);
287 #endif /* NO_LOCKING */
289 /* =======================================================================
291 ======================================================================= */
293 extern void hack_uid (saver_info *si);
294 extern void describe_uids (saver_info *si, FILE *out);
296 /* =======================================================================
298 ======================================================================= */
300 extern void draw_shaded_rectangle (Display *dpy, Window window,
302 int width, int height,
304 unsigned long top_color,
305 unsigned long bottom_color);
306 extern int string_width (XFontStruct *font, char *s);
308 extern void make_splash_dialog (saver_info *si);
309 extern void handle_splash_event (saver_info *si, XEvent *e);
310 extern void skull (Display *, Window, GC, GC, int, int, int, int);
313 /* =======================================================================
315 ======================================================================= */
317 extern void start_notice_events_timer (saver_info *, Window);
318 extern void cycle_timer (XtPointer si, XtIntervalId *id);
319 extern void activate_lock_timer (XtPointer si, XtIntervalId *id);
320 extern void reset_watchdog_timer (saver_info *si, Bool on_p);
321 extern void idle_timer (XtPointer si, XtIntervalId *id);
322 extern void sleep_until_idle (saver_info *si, Bool until_idle_p);
324 /* =======================================================================
326 ======================================================================= */
328 extern Bool handle_clientmessage (saver_info *, XEvent *, Bool);
329 extern void maybe_reload_init_file (saver_info *);
331 /* =======================================================================
333 ======================================================================= */
335 extern void hack_environment (saver_info *si);
336 extern void hack_subproc_environment (saver_screen_info *ssi);
337 extern void init_sigchld (void);
338 extern void spawn_screenhack (saver_info *si, Bool first_time_p);
339 extern void kill_screenhack (saver_info *si);
340 extern void suspend_screenhack (saver_info *si, Bool suspend_p);
341 extern Bool screenhack_running_p (saver_info *si);
342 extern void emergency_kill_subproc (saver_info *si);
343 extern Bool select_visual (saver_screen_info *ssi, const char *visual_name);
344 extern const char *signal_name (int signal);
346 /* =======================================================================
348 ======================================================================= */
350 extern FILE *real_stderr;
351 extern FILE *real_stdout;
352 extern void initialize_stderr (saver_info *si);
353 extern void reset_stderr (saver_screen_info *ssi);
354 extern void clear_stderr (saver_screen_info *ssi);
357 /* =======================================================================
359 ======================================================================= */
361 extern const char *blurb (void);
362 extern void save_argv (int argc, char **argv);
363 extern void saver_exit (saver_info *si, int status, const char *core_reason);
364 extern void restart_process (saver_info *si);
366 extern int saver_ehandler (Display *dpy, XErrorEvent *error);
367 extern int BadWindow_ehandler (Display *dpy, XErrorEvent *error);
368 extern Bool window_exists_p (Display *dpy, Window window);
369 extern char *timestring (void);
371 extern Atom XA_VROOT, XA_XSETROOT_ID;
372 extern Atom XA_SCREENSAVER, XA_SCREENSAVER_VERSION, XA_SCREENSAVER_ID;
373 extern Atom XA_SCREENSAVER_TIME;
374 extern Atom XA_DEMO, XA_PREFS;
376 #endif /* __XSCREENSAVER_H__ */