1 /* xscreensaver, Copyright (c) 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 /* This is a kludgy test harness for debugging the password dialog box.
13 It's somewhat easier to debug it here than in the xscreensaver executable
26 #include <X11/Xatom.h>
27 #include <X11/Intrinsic.h>
28 #include <X11/StringDefs.h>
29 #include <X11/Shell.h>
31 #include "xscreensaver.h"
32 #include "resources.h"
38 saver_info *global_si_kludge;
40 FILE *real_stderr, *real_stdout;
42 void reset_stderr(saver_screen_info *ssi) {}
43 void clear_stderr(saver_screen_info *ssi) {}
44 void reset_watchdog_timer(saver_info *si, Bool on_p) {}
45 void monitor_power_on (saver_info *si) {}
46 void grab_keyboard_and_mouse (saver_info *si, Window w, Cursor c) {}
47 void ungrab_keyboard_and_mouse (saver_info *si) {}
48 Bool select_visual (saver_screen_info *ssi, const char *v) { return False; }
49 void raise_window (saver_info *si, Bool i, Bool b, Bool d) {}
50 void restore_real_vroot (saver_info *si) {}
51 void saver_exit (saver_info *si, int status, const char *core) { exit(status);}
52 const char * signal_name(int signal) { return "???"; }
53 Bool monitor_powered_on_p (saver_info *si) { return True; }
54 void start_notice_events_timer (saver_info *si, Window w) {}
55 void initialize_screensaver_window (saver_info *si) {}
56 void blank_screen (saver_info *si) {}
57 void unblank_screen (saver_info *si) {}
58 Bool handle_clientmessage (saver_info *si, XEvent *e, Bool u) { return False; }
59 int BadWindow_ehandler (Display *dpy, XErrorEvent *error) { exit(1); }
60 int write_init_file (saver_info *si) { return 0;}
61 Bool window_exists_p (Display *dpy, Window window) {return True;}
63 const char *blurb(void) { return progname; }
64 Atom XA_SCREENSAVER, XA_DEMO, XA_PREFS;
68 idle_timer (XtPointer closure, XtIntervalId *id)
70 saver_info *si = (saver_info *) closure;
72 fake_event.type = 0; /* XAnyEvent type, ignored. */
73 fake_event.xany.display = si->dpy;
74 fake_event.xany.window = 0;
75 XPutBackEvent (si->dpy, &fake_event);
80 reformat_hack (const char *hack)
83 const char *in = hack;
85 char *h2 = (char *) malloc(strlen(in) + indent + 2);
88 while (isspace(*in)) in++; /* skip whitespace */
89 while (*in && !isspace(*in) && *in != ':')
90 *out++ = *in++; /* snarf first token */
91 while (isspace(*in)) in++; /* skip whitespace */
94 *out++ = *in++; /* copy colon */
98 out = h2; /* reset to beginning */
103 while (isspace(*in)) in++; /* skip whitespace */
104 for (i = strlen(h2); i < indent; i++) /* indent */
107 /* copy the rest of the line. */
110 /* shrink all whitespace to one space, for the benefit of the "demo"
111 mode display. We only do this when we can easily tell that the
112 whitespace is not significant (no shell metachars).
116 case '\'': case '"': case '`': case '\\':
118 /* Metachars are scary. Copy the rest of the line unchanged. */
125 while (*in == ' ' || *in == '\t')
137 /* strip trailing whitespace. */
139 while (out > h2 && (*out == ' ' || *out == '\t' || *out == '\n'))
147 get_screenhacks (saver_info *si)
149 saver_preferences *p = &si->prefs;
156 d = get_string_resource ("monoPrograms", "MonoPrograms");
157 if (d && !*d) { free(d); d = 0; }
159 d = get_string_resource ("colorPrograms", "ColorPrograms");
160 if (d && !*d) { free(d); d = 0; }
165 "%s: the `monoPrograms' and `colorPrograms' resources are obsolete;\n\
166 see the manual for details.\n", blurb());
170 d = get_string_resource ("programs", "Programs");
174 for (i = 0; i < p->screenhacks_count; i++)
175 if (p->screenhacks[i])
176 free (p->screenhacks[i]);
177 free(p->screenhacks);
183 p->screenhacks_count = 0;
191 /* Count up the number of newlines (which will be equal to or larger than
192 the number of hacks.)
195 for (i = 0; d[i]; i++)
200 p->screenhacks = (char **) calloc (sizeof (char *), i+1);
202 /* Iterate over the lines in `d' (the string with newlines)
203 and make new strings to stuff into the `screenhacks' array.
205 p->screenhacks_count = 0;
208 /* skip forward over whitespace. */
209 while (d[start] == ' ' || d[start] == '\t' || d[start] == '\n')
212 /* skip forward to newline or end of string. */
214 while (d[end] != 0 && d[end] != '\n')
217 /* null terminate. */
220 p->screenhacks[p->screenhacks_count++] = reformat_hack (d + start);
221 if (p->screenhacks_count >= i)
227 if (p->screenhacks_count == 0)
229 free (p->screenhacks);
236 static char *fallback[] = {
237 #include "XScreenSaver_ad.h"
242 main (int argc, char **argv)
244 Widget toplevel_shell;
245 saver_screen_info ssip;
247 saver_info *si = &sip;
248 saver_preferences *p = &si->prefs;
250 memset(&sip, 0, sizeof(sip));
251 memset(&ssip, 0, sizeof(ssip));
254 si->screens = si->default_screen = &ssip;
257 global_si_kludge = si;
258 real_stderr = stderr;
259 real_stdout = stdout;
261 si->version = (char *) malloc (5);
262 memcpy (si->version, screensaver_id + 17, 4);
266 set_auth_parameters(argc, argv);
269 if (! lock_init (argc, argv)) /* before hack_uid() for proper permissions */
271 si->locking_disabled_p = True;
272 si->nolock_reason = "error getting password";
277 progclass = "XScreenSaver";
279 toplevel_shell = XtAppInitialize (&si->app, progclass, 0, 0,
280 &argc, argv, fallback,
283 si->dpy = XtDisplay (toplevel_shell);
284 si->db = XtDatabase (si->dpy);
285 si->default_screen->toplevel_shell = toplevel_shell;
286 si->default_screen->screen = XtScreen(toplevel_shell);
287 si->default_screen->default_visual =
288 si->default_screen->current_visual =
289 DefaultVisualOfScreen(si->default_screen->screen);
290 si->default_screen->screensaver_window =
291 RootWindowOfScreen(si->default_screen->screen);
294 XtGetApplicationNameAndClass (si->dpy, &progname, &progclass);
298 p->timestamp_p = True;
301 p->fade_p = get_boolean_resource ("fade", "Boolean");
302 p->unfade_p = get_boolean_resource ("unfade", "Boolean");
303 p->fade_seconds = 1000 * get_seconds_resource ("fadeSeconds", "Time");
304 p->fade_ticks = get_integer_resource ("fadeTicks", "Integer");
305 p->install_cmap_p = get_boolean_resource ("installColormap", "Boolean");
306 p->nice_inferior = get_integer_resource ("nice", "Nice");
308 p->initial_delay = 1000 * get_seconds_resource ("initialDelay", "Time");
309 p->splash_duration = 1000 * get_seconds_resource ("splashDuration", "Time");
310 p->timeout = 1000 * get_minutes_resource ("timeout", "Time");
311 p->lock_timeout = 1000 * get_minutes_resource ("lockTimeout", "Time");
312 p->cycle = 1000 * get_minutes_resource ("cycle", "Time");
313 p->passwd_timeout = 1000 * get_seconds_resource ("passwdTimeout", "Time");
314 p->passwd_timeout = 1000 * get_seconds_resource ("passwdTimeout", "Time");
315 p->splash_duration = 1000 * get_seconds_resource ("splashDuration", "Time");
316 p->shell = get_string_resource ("bourneShell", "BourneShell");
317 p->help_url = get_string_resource("helpURL", "URL");
318 p->load_url_command = get_string_resource("loadURL", "LoadURL");
326 fprintf (stderr, "%s: password correct\n", progname);
328 fprintf (stderr, "%s: password INCORRECT!\n", progname);
330 XSync(si->dpy, False);
335 make_splash_dialog (si);
336 XtAppAddTimeOut (si->app, p->splash_duration + 1000,
337 idle_timer, (XtPointer) si);
338 while (si->splash_dialog)
340 XtAppNextEvent (si->app, &event);
341 if (event.xany.window == si->splash_dialog)
342 handle_splash_event (si, &event);
343 XtDispatchEvent (&event);
345 XSync (si->dpy, False);
349 si->demo_mode_p = True;
350 make_screenhack_dialog (si);
351 XtAppMainLoop(si->app);