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