http://www.jwz.org/xscreensaver/xscreensaver-5.12.tar.gz
[xscreensaver] / driver / types.h
1 /* xscreensaver, Copyright (c) 1993-2008 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_TYPES_H__
13 #define __XSCREENSAVER_TYPES_H__
14
15 typedef struct saver_info saver_info;
16
17 typedef enum {
18   ul_read,              /* reading input or ready to do so */
19   ul_success,           /* auth success, unlock */
20   ul_fail,              /* auth fail */
21   ul_cancel,            /* user cancelled auth (pw_cancel or pw_null) */
22   ul_time,              /* timed out */
23   ul_finished           /* user pressed enter */
24 } unlock_state;
25
26 typedef struct screenhack screenhack;
27 struct screenhack {
28   Bool enabled_p;
29   char *visual;
30   char *name;
31   char *command;
32 };
33
34 typedef enum {
35   RANDOM_HACKS, ONE_HACK, BLANK_ONLY, DONT_BLANK, RANDOM_HACKS_SAME
36 } saver_mode;
37
38 typedef enum {
39   TEXT_DATE, TEXT_LITERAL, TEXT_FILE, TEXT_PROGRAM, TEXT_URL
40 } text_mode;
41
42 struct auth_message;
43 struct auth_response;
44
45 typedef int (*auth_conv_cb_t) (
46   int num_msg,
47   const struct auth_message *msg,
48   struct auth_response **resp,
49   saver_info *si);
50
51 typedef struct saver_preferences saver_preferences;
52 typedef struct saver_screen_info saver_screen_info;
53 typedef struct passwd_dialog_data passwd_dialog_data;
54 typedef struct splash_dialog_data splash_dialog_data;
55 typedef struct _monitor monitor;
56
57
58 /* This structure holds all the user-specified parameters, read from the
59    command line, the resource database, or entered through a dialog box.
60  */
61 struct saver_preferences {
62
63   XrmDatabase db;               /* The resource database into which the
64                                    init file is merged, and out of which the
65                                    preferences are parsed. */
66
67   time_t init_file_date;        /* The date (from stat()) of the .xscreensaver
68                                    file the last time this process read or
69                                    wrote it. */
70
71   Bool verbose_p;               /* whether to print out lots of status info */
72   Bool timestamp_p;             /* whether to mark messages with a timestamp */
73   Bool capture_stderr_p;        /* whether to redirect stdout/stderr  */
74   Bool ignore_uninstalled_p;    /* whether to avoid displaying or complaining
75                                    about hacks that are not on $PATH */
76   Bool debug_p;                 /* pay no mind to the man behind the curtain */
77   Bool xsync_p;                 /* whether XSynchronize has been called */
78
79   Bool lock_p;                  /* whether to lock as well as save */
80
81   Bool fade_p;                  /* whether to fade to black, if possible */
82   Bool unfade_p;                /* whether to fade from black, if possible */
83   Time fade_seconds;            /* how long that should take */
84   int fade_ticks;               /* how many ticks should be used */
85   Bool splash_p;                /* whether to do a splash screen at startup */
86
87   Bool install_cmap_p;          /* whether we should use our own colormap
88                                    when using the screen's default visual. */
89
90 # ifdef QUAD_MODE
91   Bool quad_p;                  /* whether to run four savers per monitor */
92 # endif
93
94   screenhack **screenhacks;     /* the programs to run */
95   int screenhacks_count;
96
97   saver_mode mode;              /* hack-selection mode */
98   int selected_hack;            /* in one_hack mode, this is the one */
99
100   int nice_inferior;            /* nice value for subprocs */
101   int inferior_memory_limit;    /* setrlimit(LIMIT_AS) value for subprocs */
102
103   Time initial_delay;           /* how long to sleep after launch */
104   Time splash_duration;         /* how long the splash screen stays up */
105   Time timeout;                 /* how much idle time before activation */
106   Time lock_timeout;            /* how long after activation locking starts */
107   Time cycle;                   /* how long each hack should run */
108   Time passwd_timeout;          /* how much time before pw dialog goes down */
109   Time pointer_timeout;         /* how often to check mouse position */
110   Time notice_events_timeout;   /* how long after window creation to select */
111   Time watchdog_timeout;        /* how often to re-raise and re-blank screen */
112   int pointer_hysteresis;       /* mouse motions less than N/sec are ignored */
113
114   Bool dpms_enabled_p;          /* Whether to power down the monitor */
115   Time dpms_standby;            /* how long until monitor goes black */
116   Time dpms_suspend;            /* how long until monitor power-saves */
117   Time dpms_off;                /* how long until monitor powers down */
118
119   Bool grab_desktop_p;          /* These are not used by "xscreensaver" */
120   Bool grab_video_p;            /*  itself: they are used by the external */
121   Bool random_image_p;          /*  "xscreensaver-getimage" program, and set */
122   char *image_directory;        /*  by the "xscreensaver-demo" configurator. */
123
124   text_mode tmode;              /* How we generate text to display. */
125   char *text_literal;           /* used when tmode is TEXT_LITERAL. */
126   char *text_file;              /* used when tmode is TEXT_FILE.    */
127   char *text_program;           /* used when tmode is TEXT_PROGRAM. */
128   char *text_url;               /* used when tmode is TEXT_URL.     */
129
130   Bool use_xidle_extension;     /* which extension to use, if possible */
131   Bool use_mit_saver_extension;
132   Bool use_sgi_saver_extension;
133   Bool use_proc_interrupts;
134   Bool use_xinput_extension;
135
136   Bool getviewport_full_of_lies_p; /* XFree86 bug #421 */
137
138   char *shell;                  /* where to find /bin/sh */
139
140   char *demo_command;           /* How to enter demo mode. */
141   char *prefs_command;          /* How to edit preferences. */
142   char *help_url;               /* Where the help document resides. */
143   char *load_url_command;       /* How one loads URLs. */
144   char *new_login_command;      /* Command for the "New Login" button. */
145 };
146
147 /* This structure holds all the data that applies to the program as a whole,
148    or to the non-screen-specific parts of the display connection.
149
150    The saver_preferences structure (prefs.h) holds all the user-specified
151    parameters, read from the command line, the resource database, or entered
152    through a dialog box.
153  */
154 struct saver_info {
155   char *version;
156   saver_preferences prefs;
157
158   int nscreens;
159   int ssi_count;
160   saver_screen_info *screens;
161   saver_screen_info *default_screen;    /* ...on which dialogs will appear. */
162   monitor **monitor_layout;             /* private to screens.c */
163   Visual **best_gl_visuals;             /* visuals for GL hacks on screen N */
164
165   /* =======================================================================
166      global connection info
167      ======================================================================= */
168
169   XtAppContext app;
170   Display *dpy;
171
172   /* =======================================================================
173      server extension info
174      ======================================================================= */
175
176   Bool using_xidle_extension;      /* which extension is being used.         */
177   Bool using_mit_saver_extension;  /* Note that `p->use_*' is the *request*, */
178   Bool using_sgi_saver_extension;  /* and `si->using_*' is the *reality*.    */
179   Bool using_proc_interrupts;
180
181 # ifdef HAVE_MIT_SAVER_EXTENSION
182   int mit_saver_ext_event_number;
183   int mit_saver_ext_error_number;
184 # endif
185 # ifdef HAVE_SGI_SAVER_EXTENSION
186   int sgi_saver_ext_event_number;
187   int sgi_saver_ext_error_number;
188 # endif
189 # ifdef HAVE_RANDR
190   int randr_event_number;
191   int randr_error_number;
192   Bool using_randr_extension;
193 # endif
194
195   Bool using_xinput_extension;     /* Note that `p->use_*' is the *request*, */
196                                    /* and `si->using_*' is the *reality*.    */
197 #ifdef HAVE_XINPUT
198   int xinput_ext_event_number;     /* may not be used */
199   int xinput_ext_error_number;
200   int xinput_DeviceButtonPress;    /* Extension device event codes.          */
201   int xinput_DeviceButtonRelease;  /* Assigned by server at runtime          */
202   int xinput_DeviceMotionNotify;
203   struct xinput_dev_info *xinput_devices;
204   int num_xinput_devices;
205 # endif
206
207   /* =======================================================================
208      blanking
209      ======================================================================= */
210
211   Bool screen_blanked_p;        /* Whether the saver is currently active. */
212   Window mouse_grab_window;     /* Window holding our mouse grab */
213   Window keyboard_grab_window;  /* Window holding our keyboard grab */
214   int mouse_grab_screen;        /* The screen number the mouse grab is on */
215   int keyboard_grab_screen;     /* The screen number the keyboard grab is on */
216   Bool fading_possible_p;       /* Whether fading to/from black is possible. */
217   Bool throttled_p;             /* Whether we should temporarily just blank
218                                    the screen, not run hacks. (Deprecated:
219                                    users should use "xset dpms force off"
220                                    instead.) */
221   time_t blank_time;            /* The time at which the screen was blanked
222                                    (if currently blanked) or unblanked (if
223                                    not blanked.) */
224
225
226   /* =======================================================================
227      locking and runtime privileges
228      ======================================================================= */
229
230   Bool locked_p;                /* Whether the screen is currently locked. */
231   Bool dbox_up_p;               /* Whether the demo-mode or passwd dialogs
232                                    are currently visible */
233
234   Bool locking_disabled_p;      /* Sometimes locking is impossible. */
235   char *nolock_reason;          /* This is why. */
236
237   char *orig_uid;               /* What uid/gid we had at startup, before
238                                    discarding privileges. */
239   char *uid_message;            /* Any diagnostics from our attempt to
240                                    discard privileges (printed only in
241                                    -verbose mode.) */
242   Bool dangerous_uid_p;         /* Set to true if we're running as a user id
243                                    which is known to not be a normal, non-
244                                    privileged user. */
245
246   Window passwd_dialog;         /* The password dialog, if it's up. */
247   passwd_dialog_data *pw_data;  /* Other info necessary to draw it. */
248
249   int unlock_failures;          /* Counts failed login attempts while the
250                                    screen is locked. */
251
252   char *unlock_typeahead;       /* If the screen is locked, and the user types
253                                    a character, we assume that it is the first
254                                    character of the password.  It's stored here
255                                    for the password dialog to use to populate
256                                    itself. */
257
258   char *user;                   /* The user whose session is locked. */
259   char *cached_passwd;          /* Cached password, used to avoid multiple
260                                    prompts for password-only auth mechanisms.*/
261   unlock_state unlock_state;
262
263   auth_conv_cb_t unlock_cb;     /* The function used to prompt for creds. */
264   void (*auth_finished_cb) (saver_info *si);
265                                 /* Called when authentication has finished,
266                                    regardless of success or failure.
267                                    May be NULL. */
268
269
270   /* =======================================================================
271      demoing
272      ======================================================================= */
273
274   Bool demoing_p;               /* Whether we are demoing a single hack
275                                    (without UI.) */
276
277   Window splash_dialog;         /* The splash dialog, if its up. */
278   splash_dialog_data *sp_data;  /* Other info necessary to draw it. */
279
280
281   /* =======================================================================
282      timers
283      ======================================================================= */
284
285   XtIntervalId lock_id;         /* Timer to implement `prefs.lock_timeout' */
286   XtIntervalId cycle_id;        /* Timer to implement `prefs.cycle' */
287   XtIntervalId timer_id;        /* Timer to implement `prefs.timeout' */
288   XtIntervalId watchdog_id;     /* Timer to implement `prefs.watchdog */
289   XtIntervalId check_pointer_timer_id;  /* `prefs.pointer_timeout' */
290
291   XtIntervalId de_race_id;      /* Timer to make sure screen un-blanks */
292   int de_race_ticks;
293
294   time_t last_activity_time;               /* Used only when no server exts. */
295   time_t last_wall_clock_time;             /* Used to detect laptop suspend. */
296   saver_screen_info *last_activity_screen;
297
298   Bool emergency_lock_p;        /* Set when the wall clock has jumped
299                                    (presumably due to laptop suspend) and we
300                                    need to lock down right away instead of
301                                    waiting for the lock timer to go off. */
302
303
304   /* =======================================================================
305      remote control
306      ======================================================================= */
307
308   int selection_mode;           /* Set to -1 if the NEXT ClientMessage has just
309                                    been received; set to -2 if PREV has just
310                                    been received; set to N if SELECT or DEMO N
311                                    has been received.  (This is kind of nasty.)
312                                  */
313
314   /* =======================================================================
315      subprocs
316      ======================================================================= */
317
318   XtIntervalId stderr_popup_timer;
319
320 };
321
322 /* This structure holds all the data that applies to the screen-specific parts
323    of the display connection; if the display has multiple screens, there will
324    be one of these for each screen.
325  */
326 struct saver_screen_info {
327   saver_info *global;
328
329   int number;                   /* The internal ordinal of this screen,
330                                    counting Xinerama rectangles as separate
331                                    screens. */
332   int real_screen_number;       /* The number of the underlying X screen on
333                                    which this rectangle lies. */
334   Screen *screen;               /* The X screen in question. */
335
336   int x, y, width, height;      /* The size and position of this rectangle
337                                    on its underlying X screen. */
338
339   Bool real_screen_p;           /* This will be true of exactly one ssi per
340                                    X screen. */
341
342   Widget toplevel_shell;
343
344   /* =======================================================================
345      blanking
346      ======================================================================= */
347
348   Window screensaver_window;    /* The window that will impersonate the root,
349                                    when the screensaver activates.  Note that
350                                    the window stored here may change, as we
351                                    destroy and recreate it on different
352                                    visuals. */
353   Colormap cmap;                /* The colormap that goes with the window. */
354   Bool install_cmap_p;          /* Whether this screen should have its own
355                                    colormap installed, for whichever of several
356                                    reasons.  This is definitive (even a false
357                                    value here overrides prefs->install_cmap_p.)
358                                  */
359   Visual *current_visual;       /* The visual of the window. */
360   int current_depth;            /* How deep the visual (and the window) are. */
361
362   Visual *default_visual;       /* visual to use when none other specified */
363
364   Window real_vroot;            /* The original virtual-root window. */
365   Window real_vroot_value;      /* What was in the __SWM_VROOT property. */
366
367   Cursor cursor;                /* A blank cursor that goes with the
368                                    real root window. */
369   unsigned long black_pixel;    /* Black, allocated from `cmap'. */
370
371   int blank_vp_x, blank_vp_y;   /* Where the virtual-scrolling viewport was
372                                    when the screen went blank.  We need to
373                                    prevent the X server from letting the mouse
374                                    bump the edges to scroll while the screen
375                                    is locked, so we reset to this when it has
376                                    moved, and the lock dialog is up... */
377
378 # ifdef HAVE_MIT_SAVER_EXTENSION
379   Window server_mit_saver_window;
380 # endif
381
382
383   /* =======================================================================
384      demoing
385      ======================================================================= */
386
387   Colormap demo_cmap;           /* The colormap that goes with the dialogs:
388                                    this might be the same as `cmap' so care
389                                    must be taken not to free it while it's
390                                    still in use. */
391
392   /* =======================================================================
393      timers
394      ======================================================================= */
395
396   int poll_mouse_last_root_x;           /* Used only when no server exts. */
397   int poll_mouse_last_root_y;
398   Window poll_mouse_last_child;
399   unsigned int poll_mouse_last_mask;
400   time_t poll_mouse_last_time;
401
402
403   /* =======================================================================
404      subprocs
405      ======================================================================= */
406
407   int current_hack;             /* Index into `prefs.screenhacks' */
408   pid_t pid;
409
410   int stderr_text_x;
411   int stderr_text_y;
412   int stderr_line_height;
413   XFontStruct *stderr_font;
414   GC stderr_gc;
415   Window stderr_overlay_window;    /* Used if the server has overlay planes */
416   Colormap stderr_cmap;
417 };
418
419
420 #endif /* __XSCREENSAVER_TYPES_H__ */