X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=driver%2Fprefs.c;h=6a327ac42ba9d37a0694b9da8b289224787a33da;hb=bbd0773f2adde4927a6196361d4061e70bf48cd9;hp=46b93886211cc1cef9991d06950eeed1fe0e08e5;hpb=a94197e76a5dea5cb60542840809d6c20d0abbf3;p=xscreensaver diff --git a/driver/prefs.c b/driver/prefs.c index 46b93886..6a327ac4 100644 --- a/driver/prefs.c +++ b/driver/prefs.c @@ -1,5 +1,5 @@ /* dotfile.c --- management of the ~/.xscreensaver file. - * xscreensaver, Copyright (c) 1998 Jamie Zawinski + * xscreensaver, Copyright (c) 1998, 2003 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -77,6 +77,8 @@ static void get_screenhacks (saver_preferences *p); static char *format_command (const char *cmd, Bool wrap_p); static void merge_system_screenhacks (saver_preferences *p, screenhack **system_list, int count); +static void stop_the_insanity (saver_preferences *p); + static char * chase_symlinks (const char *file) @@ -88,7 +90,7 @@ chase_symlinks (const char *file) if (realpath (file, buf)) return strdup (buf); - sprintf (buf, "%s: realpath", blurb()); + sprintf (buf, "%.100s: realpath %.200s", blurb(), file); perror(buf); } # endif /* HAVE_REALPATH */ @@ -216,6 +218,7 @@ get_byte_resource (char *name, char *class) LOSE: fprintf (stderr, "%s: %s must be a number of bytes, not \"%s\".\n", progname, name, s); + free (s); return 0; } s2++; @@ -223,6 +226,7 @@ get_byte_resource (char *name, char *class) while (isspace(*s2)) s2++; if (*s2) goto LOSE; + free (s); return n; } @@ -240,6 +244,7 @@ static const char * const prefs[] = { "timestamp", "splash", "splashDuration", + "quad", "demoCommand", "prefsCommand", "helpURL", @@ -252,6 +257,7 @@ static const char * const prefs[] = { "fadeTicks", "captureStderr", "captureStdout", /* not saved -- obsolete */ + "ignoreUninstalledPrograms", "font", "dpmsEnabled", "dpmsStandby", @@ -632,6 +638,11 @@ write_init_file (saver_preferences *p, const char *version_string, if (n2) name = n2; + /* Throttle the various timeouts to reasonable values before writing + the file to disk. */ + stop_the_insanity (p); + + if (verbose_p) fprintf (stderr, "%s: writing \"%s\".\n", blurb(), name); @@ -701,6 +712,7 @@ write_init_file (saver_preferences *p, const char *version_string, *ss++ = '\n'; *ss = 0; } + free (hack_strings); } { @@ -756,10 +768,13 @@ write_init_file (saver_preferences *p, const char *version_string, CHECK("timestamp") type = pref_bool, b = p->timestamp_p; CHECK("splash") type = pref_bool, b = p->splash_p; CHECK("splashDuration") type = pref_time, t = p->splash_duration; + CHECK("quad") type = pref_bool, b = p->quad_p; CHECK("demoCommand") type = pref_str, s = p->demo_command; CHECK("prefsCommand") type = pref_str, s = p->prefs_command; - CHECK("helpURL") type = pref_str, s = p->help_url; - CHECK("loadURL") type = pref_str, s = p->load_url_command; +/* CHECK("helpURL") type = pref_str, s = p->help_url; */ + CHECK("helpURL") continue; /* don't save */ +/* CHECK("loadURL") type = pref_str, s = p->load_url_command; */ + CHECK("loadURL") continue; /* don't save */ CHECK("nice") type = pref_int, i = p->nice_inferior; CHECK("memoryLimit") type = pref_byte, i = p->inferior_memory_limit; CHECK("fade") type = pref_bool, b = p->fade_p; @@ -768,6 +783,9 @@ write_init_file (saver_preferences *p, const char *version_string, CHECK("fadeTicks") type = pref_int, i = p->fade_ticks; CHECK("captureStderr") type = pref_bool, b = p->capture_stderr_p; CHECK("captureStdout") continue; /* don't save */ + CHECK("ignoreUninstalledPrograms") + type = pref_bool, b = p->ignore_uninstalled_p; + CHECK("font") type = pref_str, s = stderr_font; CHECK("dpmsEnabled") type = pref_bool, b = p->dpms_enabled_p; @@ -939,6 +957,7 @@ free_screenhack_list (screenhack **list, int count) } + /* Populate `saver_preferences' with the contents of the resource database. Note that this may be called multiple times -- it is re-run each time the ~/.xscreensaver file is reloaded. @@ -987,7 +1006,10 @@ load_init_file (saver_preferences *p) p->nice_inferior = get_integer_resource ("nice", "Nice"); p->inferior_memory_limit = get_byte_resource ("memoryLimit", "MemoryLimit"); p->splash_p = get_boolean_resource ("splash", "Boolean"); + p->quad_p = get_boolean_resource ("quad", "Boolean"); p->capture_stderr_p = get_boolean_resource ("captureStderr", "Boolean"); + p->ignore_uninstalled_p = get_boolean_resource ("ignoreUninstalledPrograms", + "Boolean"); p->initial_delay = 1000 * get_seconds_resource ("initialDelay", "Time"); p->splash_duration = 1000 * get_seconds_resource ("splashDuration", "Time"); @@ -1043,43 +1065,7 @@ load_init_file (saver_preferences *p) "Boolean"); p->use_proc_interrupts = get_boolean_resource ("procInterrupts", "Boolean"); - /* Throttle the various timeouts to reasonable values. - */ - if (p->passwd_timeout <= 0) p->passwd_timeout = 30000; /* 30 secs */ - if (p->timeout < 10000) p->timeout = 10000; /* 10 secs */ - if (p->cycle != 0 && p->cycle < 2000) p->cycle = 2000; /* 2 secs */ - if (p->pointer_timeout <= 0) p->pointer_timeout = 5000; /* 5 secs */ - if (p->notice_events_timeout <= 0) - p->notice_events_timeout = 10000; /* 10 secs */ - if (p->fade_seconds <= 0 || p->fade_ticks <= 0) - p->fade_p = False; - if (! p->fade_p) p->unfade_p = False; - - /* The DPMS settings may have the value 0. - But if they are negative, or are a range less than 10 seconds, - reset them to sensible defaults. (Since that must be a mistake.) - */ - if (p->dpms_standby != 0 && - p->dpms_standby < 10 * 1000) - p->dpms_standby = 2 * 60 * 60 * 1000; /* 2 hours */ - if (p->dpms_suspend != 0 && - p->dpms_suspend < 10 * 1000) - p->dpms_suspend = 2 * 60 * 60 * 1000; /* 2 hours */ - if (p->dpms_off != 0 && - p->dpms_off < 10 * 1000) - p->dpms_off = 4 * 60 * 60 * 1000; /* 4 hours */ - - if (p->dpms_standby == 0 && /* if *all* are 0, then DPMS is disabled */ - p->dpms_suspend == 0 && - p->dpms_off == 0) - p->dpms_enabled_p = False; - - - p->watchdog_timeout = p->cycle * 0.6; - if (p->watchdog_timeout < 30000) p->watchdog_timeout = 30000; /* 30 secs */ - if (p->watchdog_timeout > 3600000) p->watchdog_timeout = 3600000; /* 1 hr */ - - get_screenhacks (p); + get_screenhacks (p); /* Parse the "programs" resource. */ p->selected_hack = get_integer_resource ("selected", "Integer"); if (p->selected_hack < 0 || p->selected_hack >= p->screenhacks_count) @@ -1091,6 +1077,7 @@ load_init_file (saver_preferences *p) else if (s && !strcasecmp (s, "blank")) p->mode = BLANK_ONLY; else if (s && !strcasecmp (s, "off")) p->mode = DONT_BLANK; else p->mode = RANDOM_HACKS; + if (s) free (s); } if (system_default_screenhack_count) /* note: first_time is also true */ @@ -1110,6 +1097,10 @@ load_init_file (saver_preferences *p) p->timestamp_p = True; p->initial_delay = 0; } + + /* Throttle the various timeouts to reasonable values after reading the + disk file. */ + stop_the_insanity (p); } @@ -1319,7 +1310,10 @@ make_hack_name (const char *shell_command) sprintf (res_name, "hacks.%s.name", s); /* resource? */ s2 = get_string_resource (res_name, res_name); if (s2) - return s2; + { + free (s); + return s2; + } for (s2 = s; *s2; s2++) /* if it has any capitals, return it */ if (*s2 >= 'A' && *s2 <= 'Z') @@ -1329,6 +1323,10 @@ make_hack_name (const char *shell_command) s[0] -= 'a'-'A'; if (s[0] == 'X' && s[1] >= 'a' && s[1] <= 'z') /* (magic leading X) */ s[1] -= 'a'-'A'; + if (s[0] == 'G' && s[1] == 'l' && + s[2] >= 'a' && s[2] <= 'z') /* (magic leading GL) */ + s[1] -= 'a'-'A', + s[2] -= 'a'-'A'; return s; } @@ -1481,9 +1479,51 @@ get_screenhacks (saver_preferences *p) start = end+1; } + free (d); + if (p->screenhacks_count == 0) { free (p->screenhacks); p->screenhacks = 0; } } + + +/* Make sure all the values in the preferences struct are sane. + */ +static void +stop_the_insanity (saver_preferences *p) +{ + if (p->passwd_timeout <= 0) p->passwd_timeout = 30000; /* 30 secs */ + if (p->timeout < 15000) p->timeout = 15000; /* 15 secs */ + if (p->cycle != 0 && p->cycle < 2000) p->cycle = 2000; /* 2 secs */ + if (p->pointer_timeout <= 0) p->pointer_timeout = 5000; /* 5 secs */ + if (p->notice_events_timeout <= 0) + p->notice_events_timeout = 10000; /* 10 secs */ + if (p->fade_seconds <= 0 || p->fade_ticks <= 0) + p->fade_p = False; + if (! p->fade_p) p->unfade_p = False; + + /* The DPMS settings may have the value 0. + But if they are negative, or are a range less than 10 seconds, + reset them to sensible defaults. (Since that must be a mistake.) + */ + if (p->dpms_standby != 0 && + p->dpms_standby < 10 * 1000) + p->dpms_standby = 2 * 60 * 60 * 1000; /* 2 hours */ + if (p->dpms_suspend != 0 && + p->dpms_suspend < 10 * 1000) + p->dpms_suspend = 2 * 60 * 60 * 1000; /* 2 hours */ + if (p->dpms_off != 0 && + p->dpms_off < 10 * 1000) + p->dpms_off = 4 * 60 * 60 * 1000; /* 4 hours */ + + if (p->dpms_standby == 0 && /* if *all* are 0, then DPMS is disabled */ + p->dpms_suspend == 0 && + p->dpms_off == 0) + p->dpms_enabled_p = False; + + p->watchdog_timeout = p->cycle * 0.6; + if (p->watchdog_timeout < 30000) p->watchdog_timeout = 30000; /* 30 secs */ + if (p->watchdog_timeout > 3600000) p->watchdog_timeout = 3600000; /* 1 hr */ +}