~ubuntu-branches/ubuntu/dapper/xscreensaver/dapper-updates

« back to all changes in this revision

Viewing changes to driver/prefs.c

  • Committer: Bazaar Package Importer
  • Author(s): Ralf Hildebrandt
  • Date: 2005-04-09 00:06:43 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20050409000643-z0abtifbt9s20pcc
Tags: 4.21-3
Patch by Joachim Breitner to check more frequently if DPMS kicked in (closes: #303374, #286664).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* dotfile.c --- management of the ~/.xscreensaver file.
2
 
 * xscreensaver, Copyright (c) 1998 Jamie Zawinski <jwz@jwz.org>
 
2
 * xscreensaver, Copyright (c) 1998-2005 Jamie Zawinski <jwz@jwz.org>
3
3
 *
4
4
 * Permission to use, copy, modify, distribute, and sell this software and its
5
5
 * documentation for any purpose is hereby granted without fee, provided that
26
26
#include <time.h>
27
27
#include <sys/stat.h>
28
28
#include <sys/time.h>
29
 
#include <time.h>
30
29
 
31
30
#include <X11/Xlib.h>
32
31
#include <X11/Xresource.h>
78
77
static char *format_command (const char *cmd, Bool wrap_p);
79
78
static void merge_system_screenhacks (saver_preferences *p,
80
79
                                      screenhack **system_list, int count);
 
80
static void stop_the_insanity (saver_preferences *p);
 
81
 
81
82
 
82
83
static char *
83
84
chase_symlinks (const char *file)
89
90
      if (realpath (file, buf))
90
91
        return strdup (buf);
91
92
 
92
 
      sprintf (buf, "%s: realpath", blurb());
 
93
      sprintf (buf, "%.100s: realpath %.200s", blurb(), file);
93
94
      perror(buf);
94
95
    }
95
96
# endif /* HAVE_REALPATH */
217
218
    LOSE:
218
219
      fprintf (stderr, "%s: %s must be a number of bytes, not \"%s\".\n",
219
220
               progname, name, s);
 
221
      free (s);
220
222
      return 0;
221
223
    }
222
224
  s2++;
224
226
  while (isspace(*s2)) s2++;
225
227
  if (*s2) goto LOSE;
226
228
 
 
229
  free (s);
227
230
  return n;
228
231
}
229
232
 
232
235
  "timeout",
233
236
  "cycle",
234
237
  "lock",
235
 
  "lockVTs",
 
238
  "lockVTs",                    /* not saved */
236
239
  "lockTimeout",
237
240
  "passwdTimeout",
238
241
  "visualID",
241
244
  "timestamp",
242
245
  "splash",
243
246
  "splashDuration",
 
247
  "quad",
244
248
  "demoCommand",
245
249
  "prefsCommand",
246
 
  "helpURL",
247
 
  "loadURL",
 
250
  "newLoginCommand",
 
251
  "helpURL",                    /* not saved */
 
252
  "loadURL",                    /* not saved */
 
253
  "newLoginCommand",            /* not saved */
248
254
  "nice",
249
255
  "memoryLimit",
250
256
  "fade",
253
259
  "fadeTicks",
254
260
  "captureStderr",
255
261
  "captureStdout",              /* not saved -- obsolete */
 
262
  "ignoreUninstalledPrograms",
256
263
  "font",
257
264
  "dpmsEnabled",
258
265
  "dpmsStandby",
262
269
  "grabVideoFrames",
263
270
  "chooseRandomImages",
264
271
  "imageDirectory",
 
272
  "mode",
 
273
  "selected",
 
274
  "textMode",
 
275
  "textLiteral",
 
276
  "textFile",
 
277
  "textProgram",
 
278
  "textURL",
265
279
  "",
266
280
  "programs",
267
281
  "",
268
282
  "pointerPollTime",
 
283
  "pointerHysteresis",
269
284
  "windowCreationTimeout",
270
285
  "initialDelay",
271
286
  "sgiSaverExtension",
272
 
  "mitSaverExtension",
 
287
  "mitSaverExtension",          /* not saved -- obsolete */
273
288
  "xidleExtension",
 
289
  "GetViewPortIsFullOfLies",
274
290
  "procInterrupts",
275
291
  "overlayStderr",
276
292
  "overlayTextBackground",      /* not saved -- X resources only */
631
647
 
632
648
  if (n2) name = n2;
633
649
 
 
650
  /* Throttle the various timeouts to reasonable values before writing
 
651
     the file to disk. */
 
652
  stop_the_insanity (p);
 
653
 
 
654
 
634
655
  if (verbose_p)
635
656
    fprintf (stderr, "%s: writing \"%s\".\n", blurb(), name);
636
657
 
700
721
        *ss++ = '\n';
701
722
        *ss = 0;
702
723
      }
 
724
    free (hack_strings);
703
725
  }
704
726
 
705
727
  {
755
777
      CHECK("timestamp")        type = pref_bool, b = p->timestamp_p;
756
778
      CHECK("splash")           type = pref_bool, b = p->splash_p;
757
779
      CHECK("splashDuration")   type = pref_time, t = p->splash_duration;
 
780
      CHECK("quad")             type = pref_bool, b = p->quad_p;
758
781
      CHECK("demoCommand")      type = pref_str,  s = p->demo_command;
759
782
      CHECK("prefsCommand")     type = pref_str,  s = p->prefs_command;
760
 
      CHECK("helpURL")          type = pref_str,  s = p->help_url;
761
 
      CHECK("loadURL")          type = pref_str,  s = p->load_url_command;
 
783
/*    CHECK("helpURL")          type = pref_str,  s = p->help_url; */
 
784
      CHECK("helpURL")          continue;  /* don't save */
 
785
/*    CHECK("loadURL")          type = pref_str,  s = p->load_url_command; */
 
786
      CHECK("loadURL")          continue;  /* don't save */
 
787
/*    CHECK("newLoginCommand")  type = pref_str,  s = p->new_login_command; */
 
788
      CHECK("newLoginCommand")  continue;  /* don't save */
762
789
      CHECK("nice")             type = pref_int,  i = p->nice_inferior;
763
790
      CHECK("memoryLimit")      type = pref_byte, i = p->inferior_memory_limit;
764
791
      CHECK("fade")             type = pref_bool, b = p->fade_p;
767
794
      CHECK("fadeTicks")        type = pref_int,  i = p->fade_ticks;
768
795
      CHECK("captureStderr")    type = pref_bool, b = p->capture_stderr_p;
769
796
      CHECK("captureStdout")    continue;  /* don't save */
 
797
      CHECK("ignoreUninstalledPrograms")
 
798
                                type = pref_bool, b = p->ignore_uninstalled_p;
 
799
 
770
800
      CHECK("font")             type = pref_str,  s =    stderr_font;
771
801
 
772
802
      CHECK("dpmsEnabled")      type = pref_bool, b = p->dpms_enabled_p;
779
809
      CHECK("chooseRandomImages")type =pref_bool, b = p->random_image_p;
780
810
      CHECK("imageDirectory")    type =pref_str,  s = p->image_directory;
781
811
 
 
812
      CHECK("mode")             type = pref_str,
 
813
                                s = (p->mode == ONE_HACK ? "one" :
 
814
                                     p->mode == BLANK_ONLY ? "blank" :
 
815
                                     p->mode == DONT_BLANK ? "off" :
 
816
                                     p->mode == RANDOM_HACKS_SAME
 
817
                                     ? "random-same"
 
818
                                     : "random");
 
819
      CHECK("selected")         type = pref_int,  i = p->selected_hack;
 
820
 
 
821
      CHECK("textMode")         type = pref_str,
 
822
                                s = (p->tmode == TEXT_URL     ? "url" :
 
823
                                     p->tmode == TEXT_LITERAL ? "literal" :
 
824
                                     p->tmode == TEXT_FILE    ? "file" :
 
825
                                     p->tmode == TEXT_PROGRAM ? "program" :
 
826
                                     "date");
 
827
      CHECK("textLiteral")      type = pref_str,  s = p->text_literal;
 
828
      CHECK("textFile")         type = pref_str,  s = p->text_file;
 
829
      CHECK("textProgram")      type = pref_str,  s = p->text_program;
 
830
      CHECK("textURL")          type = pref_str,  s = p->text_url;
 
831
 
782
832
      CHECK("programs")         type = pref_str,  s =    programs;
783
833
      CHECK("pointerPollTime")  type = pref_time, t = p->pointer_timeout;
 
834
      CHECK("pointerHysteresis")type = pref_int,  i = p->pointer_hysteresis;
784
835
      CHECK("windowCreationTimeout")type=pref_time,t= p->notice_events_timeout;
785
836
      CHECK("initialDelay")     type = pref_time, t = p->initial_delay;
786
837
      CHECK("sgiSaverExtension")type = pref_bool, b=p->use_sgi_saver_extension;
787
 
      CHECK("mitSaverExtension")type = pref_bool, b=p->use_mit_saver_extension;
 
838
      CHECK("mitSaverExtension") continue;  /* don't save */
788
839
      CHECK("xidleExtension")   type = pref_bool, b = p->use_xidle_extension;
789
840
      CHECK("procInterrupts")   type = pref_bool, b = p->use_proc_interrupts;
 
841
      CHECK("GetViewPortIsFullOfLies")  type = pref_bool,
 
842
                                        b = p->getviewport_full_of_lies_p;
790
843
      CHECK("overlayStderr")    type = pref_bool, b = overlay_stderr_p;
791
844
      CHECK("overlayTextBackground") continue;  /* don't save */
792
845
      CHECK("overlayTextForeground") continue;  /* don't save */
839
892
          abort();
840
893
          break;
841
894
        }
 
895
 
 
896
      if (pr && (!strcmp(pr, "mode") || !strcmp(pr, "textMode")))
 
897
        fprintf(out, "\n");
 
898
 
842
899
      write_entry (out, pr, s);
843
900
    }
844
901
 
928
985
}
929
986
 
930
987
 
 
988
 
931
989
/* Populate `saver_preferences' with the contents of the resource database.
932
990
   Note that this may be called multiple times -- it is re-run each time
933
991
   the ~/.xscreensaver file is reloaded.
976
1034
  p->nice_inferior  = get_integer_resource ("nice", "Nice");
977
1035
  p->inferior_memory_limit = get_byte_resource ("memoryLimit", "MemoryLimit");
978
1036
  p->splash_p       = get_boolean_resource ("splash", "Boolean");
 
1037
  p->quad_p         = get_boolean_resource ("quad", "Boolean");
979
1038
  p->capture_stderr_p = get_boolean_resource ("captureStderr", "Boolean");
 
1039
  p->ignore_uninstalled_p = get_boolean_resource ("ignoreUninstalledPrograms",
 
1040
                                                  "Boolean");
980
1041
 
981
1042
  p->initial_delay   = 1000 * get_seconds_resource ("initialDelay", "Time");
982
1043
  p->splash_duration = 1000 * get_seconds_resource ("splashDuration", "Time");
985
1046
  p->cycle           = 1000 * get_minutes_resource ("cycle", "Time");
986
1047
  p->passwd_timeout  = 1000 * get_seconds_resource ("passwdTimeout", "Time");
987
1048
  p->pointer_timeout = 1000 * get_seconds_resource ("pointerPollTime", "Time");
 
1049
  p->pointer_hysteresis = get_integer_resource ("pointerHysteresis","Integer");
988
1050
  p->notice_events_timeout = 1000*get_seconds_resource("windowCreationTimeout",
989
1051
                                                       "Time");
990
1052
 
999
1061
  p->image_directory = get_string_resource  ("imageDirectory",
1000
1062
                                             "ImageDirectory");
1001
1063
 
 
1064
  p->text_literal = get_string_resource ("textLiteral", "TextLiteral");
 
1065
  p->text_file    = get_string_resource ("textFile",    "TextFile");
 
1066
  p->text_program = get_string_resource ("textProgram", "TextProgram");
 
1067
  p->text_url     = get_string_resource ("textURL",     "TextURL");
 
1068
 
1002
1069
  p->shell = get_string_resource ("bourneShell", "BourneShell");
1003
1070
 
1004
1071
  p->demo_command = get_string_resource("demoCommand", "URL");
1005
1072
  p->prefs_command = get_string_resource("prefsCommand", "URL");
1006
1073
  p->help_url = get_string_resource("helpURL", "URL");
1007
1074
  p->load_url_command = get_string_resource("loadURL", "LoadURL");
1008
 
 
 
1075
  p->new_login_command = get_string_resource("newLoginCommand",
 
1076
                                             "NewLoginCommand");
1009
1077
 
1010
1078
  /* If "*splash" is unset, default to true. */
1011
1079
  {
1026
1094
  }
1027
1095
 
1028
1096
  p->use_xidle_extension = get_boolean_resource ("xidleExtension","Boolean");
 
1097
#if 0 /* ignore this, it is evil. */
1029
1098
  p->use_mit_saver_extension = get_boolean_resource ("mitSaverExtension",
1030
1099
                                                     "Boolean");
 
1100
#endif
1031
1101
  p->use_sgi_saver_extension = get_boolean_resource ("sgiSaverExtension",
1032
1102
                                                     "Boolean");
1033
1103
  p->use_proc_interrupts = get_boolean_resource ("procInterrupts", "Boolean");
1034
1104
 
1035
 
  /* Throttle the various timeouts to reasonable values.
1036
 
   */
1037
 
  if (p->passwd_timeout <= 0) p->passwd_timeout = 30000;         /* 30 secs */
1038
 
  if (p->timeout < 10000) p->timeout = 10000;                    /* 10 secs */
1039
 
  if (p->cycle != 0 && p->cycle < 2000) p->cycle = 2000;         /*  2 secs */
1040
 
  if (p->pointer_timeout <= 0) p->pointer_timeout = 5000;        /*  5 secs */
1041
 
  if (p->notice_events_timeout <= 0)
1042
 
    p->notice_events_timeout = 10000;                            /* 10 secs */
1043
 
  if (p->fade_seconds <= 0 || p->fade_ticks <= 0)
1044
 
    p->fade_p = False;
1045
 
  if (! p->fade_p) p->unfade_p = False;
1046
 
 
1047
 
  /* The DPMS settings may have the value 0.
1048
 
     But if they are negative, or are a range less than 10 seconds,
1049
 
     reset them to sensible defaults.  (Since that must be a mistake.)
1050
 
   */
1051
 
  if (p->dpms_standby != 0 &&
1052
 
      p->dpms_standby < 10 * 1000)
1053
 
    p->dpms_standby =  2 * 60 * 60 * 1000;                       /* 2 hours */
1054
 
  if (p->dpms_suspend != 0 &&
1055
 
      p->dpms_suspend < 10 * 1000)
1056
 
    p->dpms_suspend =  2 * 60 * 60 * 1000;                       /* 2 hours */
1057
 
  if (p->dpms_off != 0 &&
1058
 
      p->dpms_off < 10 * 1000)
1059
 
    p->dpms_off      = 4 * 60 * 60 * 1000;                       /* 4 hours */
1060
 
 
1061
 
  if (p->dpms_standby == 0 &&      /* if *all* are 0, then DPMS is disabled */
1062
 
      p->dpms_suspend == 0 &&
1063
 
      p->dpms_off     == 0)
1064
 
    p->dpms_enabled_p = False;
1065
 
 
1066
 
 
1067
 
  p->watchdog_timeout = p->cycle * 0.6;
1068
 
  if (p->watchdog_timeout < 30000) p->watchdog_timeout = 30000;   /* 30 secs */
1069
 
  if (p->watchdog_timeout > 3600000) p->watchdog_timeout = 3600000; /*  1 hr */
1070
 
 
1071
 
  get_screenhacks (p);
 
1105
  p->getviewport_full_of_lies_p =
 
1106
    get_boolean_resource ("GetViewPortIsFullOfLies", "Boolean");
 
1107
 
 
1108
  get_screenhacks (p);                /* Parse the "programs" resource. */
 
1109
 
 
1110
  {
 
1111
    char *s = get_string_resource ("selected", "Integer");
 
1112
    if (!s || !*s)
 
1113
      p->selected_hack = -1;
 
1114
    else
 
1115
      p->selected_hack = get_integer_resource ("selected", "Integer");
 
1116
    if (s) free (s);
 
1117
    if (p->selected_hack < 0 || p->selected_hack >= p->screenhacks_count)
 
1118
      p->selected_hack = -1;
 
1119
  }
 
1120
 
 
1121
  {
 
1122
    char *s = get_string_resource ("mode", "Mode");
 
1123
    if      (s && !strcasecmp (s, "one"))         p->mode = ONE_HACK;
 
1124
    else if (s && !strcasecmp (s, "blank"))       p->mode = BLANK_ONLY;
 
1125
    else if (s && !strcasecmp (s, "off"))         p->mode = DONT_BLANK;
 
1126
    else if (s && !strcasecmp (s, "random-same")) p->mode = RANDOM_HACKS_SAME;
 
1127
    else                                          p->mode = RANDOM_HACKS;
 
1128
    if (s) free (s);
 
1129
  }
 
1130
 
 
1131
  {
 
1132
    char *s = get_string_resource ("textMode", "TextMode");
 
1133
    if      (s && !strcasecmp (s, "url"))         p->tmode = TEXT_URL;
 
1134
    else if (s && !strcasecmp (s, "literal"))     p->tmode = TEXT_LITERAL;
 
1135
    else if (s && !strcasecmp (s, "file"))        p->tmode = TEXT_FILE;
 
1136
    else if (s && !strcasecmp (s, "program"))     p->tmode = TEXT_PROGRAM;
 
1137
    else                                          p->tmode = TEXT_DATE;
 
1138
    if (s) free (s);
 
1139
  }
1072
1140
 
1073
1141
  if (system_default_screenhack_count)  /* note: first_time is also true */
1074
1142
    {
1087
1155
      p->timestamp_p = True;
1088
1156
      p->initial_delay = 0;
1089
1157
    }
 
1158
 
 
1159
  /* Throttle the various timeouts to reasonable values after reading the
 
1160
     disk file. */
 
1161
  stop_the_insanity (p);
1090
1162
}
1091
1163
 
1092
1164
 
1296
1368
  sprintf (res_name, "hacks.%s.name", s);               /* resource? */
1297
1369
  s2 = get_string_resource (res_name, res_name);
1298
1370
  if (s2)
1299
 
    return s2;
 
1371
    {
 
1372
      free (s);
 
1373
      return s2;
 
1374
    }
1300
1375
 
1301
1376
  for (s2 = s; *s2; s2++)       /* if it has any capitals, return it */
1302
1377
    if (*s2 >= 'A' && *s2 <= 'Z')
1306
1381
    s[0] -= 'a'-'A';
1307
1382
  if (s[0] == 'X' && s[1] >= 'a' && s[1] <= 'z')        /* (magic leading X) */
1308
1383
    s[1] -= 'a'-'A';
 
1384
  if (s[0] == 'G' && s[1] == 'l' && 
 
1385
      s[2] >= 'a' && s[2] <= 'z')                      /* (magic leading GL) */
 
1386
    s[1] -= 'a'-'A',
 
1387
    s[2] -= 'a'-'A';
1309
1388
  return s;
1310
1389
}
1311
1390
 
1314
1393
format_hack (screenhack *hack, Bool wrap_p)
1315
1394
{
1316
1395
  int tab = 32;
1317
 
  int size = (2 * (strlen(hack->command) +
1318
 
                   (hack->visual ? strlen(hack->visual) : 0) +
1319
 
                   (hack->name ? strlen(hack->name) : 0) +
1320
 
                   tab));
1321
 
  char *h2 = (char *) malloc (size);
1322
 
  char *out = h2;
1323
 
  char *s;
 
1396
  int size;
 
1397
  char *h2, *out, *s;
1324
1398
  int col = 0;
1325
1399
 
 
1400
  char *def_name = make_hack_name (hack->command);
 
1401
 
 
1402
  /* Don't ever write out a name for a hack if it's the same as the default.
 
1403
   */
 
1404
  if (hack->name && !strcmp (hack->name, def_name))
 
1405
    {
 
1406
      free (hack->name);
 
1407
      hack->name = 0;
 
1408
    }
 
1409
  free (def_name);
 
1410
 
 
1411
  size = (2 * (strlen(hack->command) +
 
1412
               (hack->visual ? strlen(hack->visual) : 0) +
 
1413
               (hack->name ? strlen(hack->name) : 0) +
 
1414
               tab));
 
1415
  h2 = (char *) malloc (size);
 
1416
  out = h2;
 
1417
 
1326
1418
  if (!hack->enabled_p) *out++ = '-';           /* write disabled flag */
1327
1419
 
1328
1420
  if (hack->visual && *hack->visual)            /* write visual name */
1445
1537
      start = end+1;
1446
1538
    }
1447
1539
 
 
1540
  free (d);
 
1541
 
1448
1542
  if (p->screenhacks_count == 0)
1449
1543
    {
1450
1544
      free (p->screenhacks);
1451
1545
      p->screenhacks = 0;
1452
1546
    }
1453
1547
}
 
1548
 
 
1549
 
 
1550
/* Make sure all the values in the preferences struct are sane.
 
1551
 */
 
1552
static void
 
1553
stop_the_insanity (saver_preferences *p)
 
1554
{
 
1555
  if (p->passwd_timeout <= 0) p->passwd_timeout = 30000;         /* 30 secs */
 
1556
  if (p->timeout < 15000) p->timeout = 15000;                    /* 15 secs */
 
1557
  if (p->cycle != 0 && p->cycle < 2000) p->cycle = 2000;         /*  2 secs */
 
1558
  if (p->pointer_timeout <= 0) p->pointer_timeout = 5000;        /*  5 secs */
 
1559
  if (p->notice_events_timeout <= 0)
 
1560
    p->notice_events_timeout = 10000;                            /* 10 secs */
 
1561
  if (p->fade_seconds <= 0 || p->fade_ticks <= 0)
 
1562
    p->fade_p = False;
 
1563
  if (! p->fade_p) p->unfade_p = False;
 
1564
 
 
1565
  /* The DPMS settings may have the value 0.
 
1566
     But if they are negative, or are a range less than 10 seconds,
 
1567
     reset them to sensible defaults.  (Since that must be a mistake.)
 
1568
   */
 
1569
  if (p->dpms_standby != 0 &&
 
1570
      p->dpms_standby < 10 * 1000)
 
1571
    p->dpms_standby =  2 * 60 * 60 * 1000;                       /* 2 hours */
 
1572
  if (p->dpms_suspend != 0 &&
 
1573
      p->dpms_suspend < 10 * 1000)
 
1574
    p->dpms_suspend =  2 * 60 * 60 * 1000;                       /* 2 hours */
 
1575
  if (p->dpms_off != 0 &&
 
1576
      p->dpms_off < 10 * 1000)
 
1577
    p->dpms_off      = 4 * 60 * 60 * 1000;                       /* 4 hours */
 
1578
 
 
1579
  /* standby may not be greater than suspend.
 
1580
     suspend may not be greater than off.
 
1581
   */
 
1582
  if (p->dpms_standby > p->dpms_suspend) p->dpms_standby = p->dpms_suspend;
 
1583
  if (p->dpms_suspend > p->dpms_off)     p->dpms_suspend = p->dpms_off;
 
1584
 
 
1585
 
 
1586
  if (p->dpms_standby == 0 &&      /* if *all* are 0, then DPMS is disabled */
 
1587
      p->dpms_suspend == 0 &&
 
1588
      p->dpms_off     == 0)
 
1589
    p->dpms_enabled_p = False;
 
1590
 
 
1591
 
 
1592
  /* Watchdog timer set to 30s, anything else is too slow to react 
 
1593
   * appropriately on DPMS on battery running laptops (CPU intensive hack
 
1594
   * keeps running for too long
 
1595
   * /
 
1596
   * 
 
1597
  p->watchdog_timeout = 30000;
 
1598
  /* p->watchdog_timeout = p->cycle * 0.6;
 
1599
   * /
 
1600
   
 
1601
  if (p->watchdog_timeout < 30000) p->watchdog_timeout = 30000;   /* 30 secs */
 
1602
  if (p->watchdog_timeout > 3600000) p->watchdog_timeout = 3600000; /*  1 hr */
 
1603
 
 
1604
  if (p->pointer_hysteresis < 0)   p->pointer_hysteresis = 0;
 
1605
  if (p->pointer_hysteresis > 100) p->pointer_hysteresis = 100;
 
1606
}