From http://www.jwz.org/xscreensaver/xscreensaver-5.35.tar.gz
[xscreensaver] / driver / demo-Xm.c
index aadbd0b9658e242f6ea61e145b3879a386876b36..149e7c5154169ea73669f36d15c5354fc7bd1a33 100644 (file)
@@ -1,5 +1,5 @@
 /* demo-Xm.c --- implements the interactive demo-mode and options dialogs.
- * xscreensaver, Copyright (c) 1993-1999 Jamie Zawinski <jwz@jwz.org>
+ * xscreensaver, Copyright (c) 1993-2003, 2005 Jamie Zawinski <jwz@jwz.org>
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
 #include <Xm/RowColumn.h>
 #include <Xm/MessageB.h>
 
+#ifdef HAVE_XMCOMBOBOX         /* a Motif 2.0 widget */
+# include <Xm/ComboBox.h>
+# ifndef XmNtextField          /* Lesstif 0.89.4 bug */
+#  undef HAVE_XMCOMBOBOX
+# endif
+# if (XmVersion < 2001)                /* Lesstif has two personalities these days */
+#  undef HAVE_XMCOMBOBOX
+# endif
+#endif /* HAVE_XMCOMBOBOX */
+
 #include "version.h"
 #include "prefs.h"
 #include "resources.h"         /* for parse_time() */
@@ -111,6 +121,7 @@ static void populate_demo_window (Widget toplevel,
 static void populate_prefs_page (Widget top, prefs_pair *pair);
 static int apply_changes_and_save (Widget widget);
 static int maybe_reload_init_file (Widget widget, prefs_pair *pair);
+static void await_xscreensaver (Widget widget);
 
 \f
 /* Some random utility functions
@@ -146,7 +157,7 @@ ensure_selected_item_visible (Widget list)
       XtVaGetValues (list,
                     XmNtopItemPosition, &top,
                     XmNvisibleItemCount, &visible,
-                    0);
+                    NULL);
       if (pos_list[0] >= top + visible)
        {
          int pos = pos_list[0] - visible + 1;
@@ -343,8 +354,13 @@ about_menu_cb (Widget button, XtPointer client_data, XtPointer ignored)
   *s2 = 0;
   s2 += 2;
 
-  sprintf (buf, "%s\n%s\n\n"
-           "For updates, check http://www.jwz.org/xscreensaver/",
+  sprintf (buf, "%s\n%s\n"
+           "\n"
+           "This is the Motif version of \"xscreensaver-demo\".  The Motif\n"
+           "version is no longer maintained.  Please use the GTK version\n"
+           "instead, which has many more features.\n"
+           "\n"
+           "For xscreensaver updates, check https://www.jwz.org/xscreensaver/",
            s, s2);
   free (s);
 
@@ -369,10 +385,11 @@ doc_menu_cb (Widget button, XtPointer client_data, XtPointer ignored)
     }
 
   help_command = (char *) malloc (strlen (p->load_url_command) +
-                                 (strlen (p->help_url) * 2) + 20);
+                                 (strlen (p->help_url) * 4) + 20);
   strcpy (help_command, "( ");
   sprintf (help_command + strlen(help_command),
-           p->load_url_command, p->help_url, p->help_url);
+           p->load_url_command,
+           p->help_url, p->help_url, p->help_url, p->help_url);
   strcat (help_command, " ) &");
   system (help_command);
   free (help_command);
@@ -412,6 +429,71 @@ restart_menu_cb (Widget button, XtPointer client_data, XtPointer ignored)
   sleep (1);
   system ("xscreensaver -nosplash &");
 #endif
+
+  await_xscreensaver (button);
+}
+
+static void
+await_xscreensaver (Widget widget)
+{
+  int countdown = 5;
+
+  Display *dpy = XtDisplay (widget);
+  char *rversion = 0;
+
+  while (!rversion && (--countdown > 0))
+    {
+      /* Check for the version of the running xscreensaver... */
+      server_xscreensaver_version (dpy, &rversion, 0, 0);
+
+      /* If it's not there yet, wait a second... */
+      sleep (1);
+    }
+
+  if (rversion)
+    {
+      /* Got it. */
+      free (rversion);
+    }
+  else
+    {
+      /* Timed out, no screensaver running. */
+
+      char buf [1024];
+      Bool root_p = (geteuid () == 0);
+      
+      strcpy (buf, 
+              "Error:\n\n"
+              "The xscreensaver daemon did not start up properly.\n"
+              "\n");
+
+      if (root_p)
+# ifdef __GNUC__
+        __extension__     /* don't warn about "string length is greater than
+                             the length ISO C89 compilers are required to
+                             support" in the following expression... */
+# endif
+        strcat (buf,
+            "You are running as root.  This usually means that xscreensaver\n"
+            "was unable to contact your X server because access control is\n"
+            "turned on.  Try running this command:\n"
+            "\n"
+            "                        xhost +localhost\n"
+            "\n"
+            "and then selecting `File / Restart Daemon'.\n"
+            "\n"
+            "Note that turning off access control will allow anyone logged\n"
+            "on to this machine to access your screen, which might be\n"
+            "considered a security problem.  Please read the xscreensaver\n"
+            "manual and FAQ for more information.\n"
+            "\n"
+            "You shouldn't run X as root. Instead, you should log in as a\n"
+            "normal user, and `su' as necessary.");
+      else
+        strcat (buf, "Please check your $PATH and permissions.");
+
+      warning_dialog (XtParent (widget), buf, 1);
+    }
 }
 
 
@@ -427,7 +509,7 @@ selected_hack_number (Widget toplevel)
 static int
 demo_write_init_file (Widget widget, saver_preferences *p)
 {
-  if (!write_init_file (p, short_version, False))
+  if (!write_init_file (XtDisplay (widget), p, short_version, False))
     return 0;
   else
     {
@@ -461,10 +543,10 @@ apply_changes_and_save (Widget widget)
 
   Widget vis = name_to_widget (widget, "combo");
 # ifdef HAVE_XMCOMBOBOX
-  Widget text;
+  Widget text = 0;
 # else /* !HAVE_XMCOMBOBOX */
   Widget menu = 0, *kids = 0, selected_item = 0;
-  Cardinal nkids;
+  Cardinal nkids = 0;
   int i = 0;
 # endif /* !HAVE_XMCOMBOBOX */
 
@@ -478,13 +560,16 @@ apply_changes_and_save (Widget widget)
   if (which < 0) return -1;
 
 # ifdef HAVE_XMCOMBOBOX
-  XtVaGetValues (vis, XmNtextField, &text, 0);
-  XtVaGetValues (text, XmNvalue, &visual, 0);
+  XtVaGetValues (vis, XmNtextField, &text, NULL);
+  if (!text)
+    /* If we can't get at the text field of this combo box, we're screwed. */
+    abort();
+  XtVaGetValues (text, XmNvalue, &visual, NULL);
 
 # else /* !HAVE_XMCOMBOBOX */
-  XtVaGetValues (vis, XmNsubMenuId, &menu, 0);
-  XtVaGetValues (menu, XmNnumChildren, &nkids, XmNchildren, &kids, 0);
-  XtVaGetValues (menu, XmNmenuHistory, &selected_item, 0);
+  XtVaGetValues (vis, XmNsubMenuId, &menu, NULL);
+  XtVaGetValues (menu, XmNnumChildren, &nkids, XmNchildren, &kids, NULL);
+  XtVaGetValues (menu, XmNmenuHistory, &selected_item, NULL);
   if (selected_item)
     for (i = 0; i < nkids; i++)
       if (kids[i] == selected_item)
@@ -493,8 +578,8 @@ apply_changes_and_save (Widget widget)
   visual = visual_menu[i];
 # endif /* !HAVE_XMCOMBOBOX */
 
-  XtVaGetValues (enabled, XmNset, &enabled_p, 0);
-  XtVaGetValues (cmd, XtNvalue, &command, 0);
+  XtVaGetValues (enabled, XmNset, &enabled_p, NULL);
+  XtVaGetValues (cmd, XtNvalue, &command, NULL);
 
   if (maybe_reload_init_file (widget, pair) != 0)
     return 1;
@@ -520,7 +605,7 @@ apply_changes_and_save (Widget widget)
   else if (!strcasecmp (visual, "greyscale"))          visual = "GrayScale";
   else if (!strcasecmp (visual, "pseudocolor"))        visual = "PseudoColor";
   else if (!strcasecmp (visual, "directcolor"))        visual = "DirectColor";
-  else if (1 == sscanf (visual, " %ld %c", &id, &c))   ;
+  else if (1 == sscanf (visual, " %lu %c", &id, &c))   ;
   else if (1 == sscanf (visual, " 0x%lx %c", &id, &c)) ;
   else
     {
@@ -587,10 +672,10 @@ manual_cb (Widget button, XtPointer client_data, XtPointer ignored)
   s = strrchr (name2, '/');
   if (s) name = s+1;
 
-  cmd = get_string_resource ("manualCommand", "ManualCommand");
+  cmd = get_string_resource (XtDisplay (button), "manualCommand", "ManualCommand");
   if (cmd)
     {
-      char *cmd2 = (char *) malloc (strlen (cmd) + strlen (name2) + 100);
+      char *cmd2 = (char *) malloc (strlen (cmd) + (strlen (name2) * 4) + 100);
       strcpy (cmd2, "( ");
       sprintf (cmd2 + strlen (cmd2),
                cmd,
@@ -674,7 +759,7 @@ run_prev_cb (Widget button, XtPointer client_data, XtPointer ignored)
    this parses the text, and does error checking.
  */
 static void 
-hack_time_text (const char *line, Time *store, Bool sec_p)
+hack_time_text (Widget button, const char *line, Time *store, Bool sec_p)
 {
   if (*line)
     {
@@ -682,7 +767,14 @@ hack_time_text (const char *line, Time *store, Bool sec_p)
       value = parse_time ((char *) line, sec_p, True);
       value *= 1000;   /* Time measures in microseconds */
       if (value < 0)
-        /* gdk_beep () */;
+       {
+         char b[255];
+         sprintf (b,
+                  "Error:\n\n"
+                  "Unparsable time format: \"%s\"\n",
+                  line);
+         warning_dialog (XtParent (button), b, 100);
+       }
       else
        *store = value;
     }
@@ -703,28 +795,32 @@ prefs_ok_cb (Widget button, XtPointer client_data, XtPointer ignored)
 
 # define SECONDS(field, name) \
   v = 0; \
-  XtVaGetValues (name_to_widget (button, (name)), XtNvalue, &v, 0); \
-  hack_time_text (v, (field), True)
+  XtVaGetValues (name_to_widget (button, (name)), XtNvalue, &v, NULL); \
+  hack_time_text (button, v, (field), True)
 
 # define MINUTES(field, name) \
   v = 0; \
-  XtVaGetValues (name_to_widget (button, (name)), XtNvalue, &v, 0); \
-  hack_time_text (v, (field), False)
+  XtVaGetValues (name_to_widget (button, (name)), XtNvalue, &v, NULL); \
+  hack_time_text (button, v, (field), False)
 
 # define INTEGER(field, name) do { \
     unsigned int value; \
     char c; \
-    XtVaGetValues (name_to_widget (button, (name)), XtNvalue, &v, 0); \
+    XtVaGetValues (name_to_widget (button, (name)), XtNvalue, &v, NULL); \
     if (! *v) \
       ; \
     else if (sscanf (v, "%u%c", &value, &c) != 1) \
-     XBell(XtDisplay(button), 0); \
+      { \
+       char b[255]; \
+       sprintf (b, "Error:\n\n" "Not an integer: \"%s\"\n", v); \
+       warning_dialog (XtParent (button), b, 100); \
+      } \
    else \
      *(field) = value; \
   } while(0)
 
 # define CHECKBOX(field, name) \
-  XtVaGetValues (name_to_widget (button, (name)), XmNset, &field, 0)
+  XtVaGetValues (name_to_widget (button, (name)), XmNset, &field, NULL)
 
   MINUTES (&p2->timeout,        "timeoutText");
   MINUTES (&p2->cycle,          "cycleText");
@@ -818,48 +914,6 @@ format_time (char *buf, Time time)
 }
 
 
-static char *
-make_pretty_name (const char *shell_command)
-{
-  char *s = strdup (shell_command);
-  char *s2;
-  char res_name[255];
-
-  for (s2 = s; *s2; s2++)      /* truncate at first whitespace */
-    if (isspace (*s2))
-      {
-        *s2 = 0;
-        break;
-      }
-
-  s2 = strrchr (s, '/');       /* if pathname, take last component */
-  if (s2)
-    {
-      s2 = strdup (s2+1);
-      free (s);
-      s = s2;
-    }
-
-  if (strlen (s) > 50)         /* 51 is hereby defined as "unreasonable" */
-    s[50] = 0;
-
-  sprintf (res_name, "hacks.%s.name", s);              /* resource? */
-  s2 = get_string_resource (res_name, res_name);
-  if (s2)
-    return s2;
-
-  for (s2 = s; *s2; s2++)      /* if it has any capitals, return it */
-    if (*s2 >= 'A' && *s2 <= 'Z')
-      return s;
-
-  if (s[0] >= 'a' && s[0] <= 'z')                      /* else cap it */
-    s[0] -= 'a'-'A';
-  if (s[0] == 'X' && s[1] >= 'a' && s[1] <= 'z')       /* (magic leading X) */
-    s[1] -= 'a'-'A';
-  return s;
-}
-
-
 /* Finds the number of the last hack to run, and makes that item be
    selected by default.
  */
@@ -869,7 +923,7 @@ scroll_to_current_hack (Widget toplevel, prefs_pair *pair)
   Atom type;
   int format;
   unsigned long nitems, bytesafter;
-  CARD32 *data = 0;
+  unsigned char *data = 0;
   Display *dpy = XtDisplay (toplevel);
   int which = 0;
   Widget list;
@@ -878,7 +932,7 @@ scroll_to_current_hack (Widget toplevel, prefs_pair *pair)
                           XA_SCREENSAVER_STATUS,
                           0, 3, False, XA_INTEGER,
                           &type, &format, &nitems, &bytesafter,
-                          (unsigned char **) &data)
+                          &data)
       == Success
       && type == XA_INTEGER
       && nitems >= 3
@@ -914,7 +968,7 @@ populate_hack_list (Widget toplevel, prefs_pair *pair)
     {
       char *pretty_name = (h[0]->name
                            ? strdup (h[0]->name)
-                           : make_pretty_name (h[0]->command));
+                           : make_hack_name (XtDisplay (toplevel), h[0]->command));
 
       XmString xmstr = XmStringCreate (pretty_name, XmSTRING_DEFAULT_CHARSET);
       XmListAddItem (list, xmstr, 0);
@@ -933,28 +987,28 @@ populate_prefs_page (Widget top, prefs_pair *pair)
   char s[100];
 
   format_time (s, p->timeout);
-  XtVaSetValues (name_to_widget (top, "timeoutText"),     XmNvalue, s, 0);
+  XtVaSetValues (name_to_widget (top, "timeoutText"),     XmNvalue, s, NULL);
   format_time (s, p->cycle);
-  XtVaSetValues (name_to_widget (top, "cycleText"),       XmNvalue, s, 0);
+  XtVaSetValues (name_to_widget (top, "cycleText"),       XmNvalue, s, NULL);
   format_time (s, p->lock_timeout);
-  XtVaSetValues (name_to_widget (top, "lockText"),        XmNvalue, s, 0);
+  XtVaSetValues (name_to_widget (top, "lockText"),        XmNvalue, s, NULL);
   format_time (s, p->passwd_timeout);
-  XtVaSetValues (name_to_widget (top, "passwdText"),      XmNvalue, s, 0);
+  XtVaSetValues (name_to_widget (top, "passwdText"),      XmNvalue, s, NULL);
   format_time (s, p->fade_seconds);
-  XtVaSetValues (name_to_widget (top, "fadeSecondsText"), XmNvalue, s, 0);
+  XtVaSetValues (name_to_widget (top, "fadeSecondsText"), XmNvalue, s, NULL);
   sprintf (s, "%u", p->fade_ticks);
-  XtVaSetValues (name_to_widget (top, "fadeTicksText"),   XmNvalue, s, 0);
+  XtVaSetValues (name_to_widget (top, "fadeTicksText"),   XmNvalue, s, NULL);
 
   XtVaSetValues (name_to_widget (top, "verboseToggle"),
-                 XmNset, p->verbose_p, 0);
+                 XmNset, p->verbose_p, NULL);
   XtVaSetValues (name_to_widget (top, "cmapToggle"),
-                 XmNset, p->install_cmap_p, 0);
+                 XmNset, p->install_cmap_p, NULL);
   XtVaSetValues (name_to_widget (top, "fadeToggle"),
-                 XmNset, p->fade_p, 0);
+                 XmNset, p->fade_p, NULL);
   XtVaSetValues (name_to_widget (top, "unfadeToggle"),
-                 XmNset, p->unfade_p, 0);
+                 XmNset, p->unfade_p, NULL);
   XtVaSetValues (name_to_widget (top, "lockToggle"),
-                 XmNset, p->lock_p, 0);
+                 XmNset, p->lock_p, NULL);
 
 
   {
@@ -972,20 +1026,24 @@ populate_prefs_page (Widget top, prefs_pair *pair)
          }
       }
 
+#ifdef HAVE_XF86VMODE_GAMMA
+    found_any_writable_cells = True;  /* if we can gamma fade, go for it */
+#endif
+
     XtVaSetValues (name_to_widget (top, "fadeSecondsLabel"), XtNsensitive,
-                           found_any_writable_cells, 0);
+                           found_any_writable_cells, NULL);
     XtVaSetValues (name_to_widget (top, "fadeTicksLabel"), XtNsensitive,
-                           found_any_writable_cells, 0);
+                           found_any_writable_cells, NULL);
     XtVaSetValues (name_to_widget (top, "fadeSecondsText"), XtNsensitive,
-                           found_any_writable_cells, 0);
+                           found_any_writable_cells, NULL);
     XtVaSetValues (name_to_widget (top, "fadeTicksText"), XtNsensitive,
-                           found_any_writable_cells, 0);
+                           found_any_writable_cells, NULL);
     XtVaSetValues (name_to_widget (top, "cmapToggle"), XtNsensitive,
-                           found_any_writable_cells, 0);
+                           found_any_writable_cells, NULL);
     XtVaSetValues (name_to_widget (top, "fadeToggle"), XtNsensitive,
-                           found_any_writable_cells, 0);
+                           found_any_writable_cells, NULL);
     XtVaSetValues (name_to_widget (top, "unfadeToggle"), XtNsensitive,
-                           found_any_writable_cells, 0);
+                           found_any_writable_cells, NULL);
   }
 }
 
@@ -999,7 +1057,7 @@ sensitize_demo_widgets (Widget toplevel, Bool sensitive_p)
   for (i = 0; i < sizeof(names)/countof(*names); i++)
     {
       Widget w = name_to_widget (toplevel, names[i]);
-      XtVaSetValues (w, XtNsensitive, sensitive_p, 0);
+      XtVaSetValues (w, XtNsensitive, sensitive_p, NULL);
     }
 
   /* I don't know how to handle these yet... */
@@ -1008,7 +1066,7 @@ sensitize_demo_widgets (Widget toplevel, Bool sensitive_p)
     for (i = 0; i < sizeof(names2)/countof(*names2); i++)
       {
         Widget w = name_to_widget (toplevel, names2[i]);
-        XtVaSetValues (w, XtNsensitive, FALSE, 0);
+        XtVaSetValues (w, XtNsensitive, FALSE, NULL);
       }
   }
 }
@@ -1098,7 +1156,7 @@ pixmapify_buttons (Widget toplevel)
   symbols[0].name = "background";
   symbols[0].pixel = 0;
   symbols[1].name = 0;
-  XtVaGetValues (up, XmNbackground, &xc, 0);
+  XtVaGetValues (up, XmNbackground, &xc, NULL);
   XQueryColor (dpy, xgwa.colormap, &xc);
   sprintf (color, "#%04X%04X%04X", xc.red, xc.green, xc.blue);
   symbols[0].value = color;
@@ -1142,8 +1200,8 @@ pixmapify_buttons (Widget toplevel)
       return;
     }
 
-  XtVaSetValues (up, XmNlabelType, XmPIXMAP, XmNlabelPixmap, up_pixmap, 0);
-  XtVaSetValues (dn, XmNlabelType, XmPIXMAP, XmNlabelPixmap, down_pixmap, 0);
+  XtVaSetValues (up, XmNlabelType, XmPIXMAP, XmNlabelPixmap, up_pixmap, NULL);
+  XtVaSetValues (dn, XmNlabelType, XmPIXMAP, XmNlabelPixmap, down_pixmap,NULL);
 
 #endif /* HAVE_XPM */
 }
@@ -1151,13 +1209,13 @@ pixmapify_buttons (Widget toplevel)
 
 
 char *
-get_hack_blurb (screenhack *hack)
+get_hack_blurb (Display *dpy, screenhack *hack)
 {
   char *doc_string;
   char *prog_name = strdup (hack->command);
   char *pretty_name = (hack->name
                        ? strdup (hack->name)
-                       : make_pretty_name (hack->command));
+                       : make_hack_name (dpy, hack->command));
   char doc_name[255], doc_class[255];
   char *s, *s2;
 
@@ -1172,7 +1230,7 @@ get_hack_blurb (screenhack *hack)
   free (prog_name);
   free (pretty_name);
 
-  doc_string = get_string_resource (doc_name, doc_class);
+  doc_string = get_string_resource (dpy, doc_name, doc_class);
   if (doc_string)
     {
       for (s = doc_string; *s; s++)
@@ -1219,6 +1277,7 @@ get_hack_blurb (screenhack *hack)
     }
   else
     {
+# if 0
       static int doc_installed = 0;
       if (doc_installed == 0)
         {
@@ -1239,7 +1298,16 @@ get_hack_blurb (screenhack *hack)
                   "To fix this problem, delete that file, or "
                   "install a current version (either will work.)");
       else
-        doc_string = strdup ("");
+# endif /* 0 */
+        doc_string = strdup (
+           "\n"
+           "This is the Motif version of \"xscreensaver-demo\".  The Motif "
+           "version is no longer maintained.  Please use the GTK version "
+           "instead, which has many more features."
+           "\n\n"
+           "If you were running the GTK version, there would be a preview "
+           "of this screen saver mode displayed here, along with graphical "
+           "configuration options.");
     }
 
   return doc_string;
@@ -1261,20 +1329,20 @@ populate_demo_window (Widget toplevel, int which, prefs_pair *pair)
   char *pretty_name = (hack
                        ? (hack->name
                           ? strdup (hack->name)
-                          : make_pretty_name (hack->command))
+                          : make_hack_name (XtDisplay (toplevel), hack->command))
                        : 0);
-  char *doc_string = hack ? get_hack_blurb (hack) : 0;
+  char *doc_string = hack ? get_hack_blurb (XtDisplay (toplevel), hack) : 0;
 
   XmString xmstr;
 
   xmstr = XmStringCreate (pretty_name, XmSTRING_DEFAULT_CHARSET);
-  XtVaSetValues (frameL, XmNlabelString, xmstr, 0);
+  XtVaSetValues (frameL, XmNlabelString, xmstr, NULL);
   XmStringFree (xmstr);
 
-  XtVaSetValues (doc, XmNvalue, doc_string, 0);
-  XtVaSetValues (cmd, XmNvalue, (hack ? hack->command : ""), 0);
+  XtVaSetValues (doc, XmNvalue, doc_string, NULL);
+  XtVaSetValues (cmd, XmNvalue, (hack ? hack->command : ""), NULL);
 
-  XtVaSetValues (enabled, XmNset, (hack ? hack->enabled_p : False), 0);
+  XtVaSetValues (enabled, XmNset, (hack ? hack->enabled_p : False), NULL);
 
   i = 0;
   if (hack && hack->visual && *hack->visual)
@@ -1286,21 +1354,21 @@ populate_demo_window (Widget toplevel, int which, prefs_pair *pair)
   {
 # ifdef HAVE_XMCOMBOBOX
     Widget text = 0;
-    XtVaGetValues (vis, XmNtextField, &text, 0);
-    XtVaSetValues (vis, XmNselectedPosition, i, 0);
+    XtVaGetValues (vis, XmNtextField, &text, NULL);
+    XtVaSetValues (vis, XmNselectedPosition, i, NULL);
     if (i < 0)
-      XtVaSetValues (text, XmNvalue, hack->visual, 0);
+      XtVaSetValues (text, XmNvalue, hack->visual, NULL);
 # else /* !HAVE_XMCOMBOBOX */
     Cardinal nkids;
     Widget *kids;
     Widget menu;
 
-    XtVaGetValues (vis, XmNsubMenuId, &menu, 0);
+    XtVaGetValues (vis, XmNsubMenuId, &menu, NULL);
     if (!menu) abort ();
-    XtVaGetValues (menu, XmNnumChildren, &nkids, XmNchildren, &kids, 0);
+    XtVaGetValues (menu, XmNnumChildren, &nkids, XmNchildren, &kids, NULL);
     if (!kids) abort();
     if (i < nkids)
-      XtVaSetValues (vis, XmNmenuHistory, kids[i], 0);
+      XtVaSetValues (vis, XmNmenuHistory, kids[i], NULL);
 # endif /* !HAVE_XMCOMBOBOX */
   }
 
@@ -1340,12 +1408,12 @@ maybe_reload_init_file (Widget widget, prefs_pair *pair)
       warning_dialog (widget, b, 100);
       free (b);
 
-      load_init_file (p);
+      load_init_file (XtDisplay (widget), p);
 
       which = selected_hack_number (widget);
       list = name_to_widget (widget, "list");
 
-      XtVaSetValues (list, XmNitemCount, 0, 0);
+      XtVaSetValues (list, XmNitemCount, 0, NULL);
 
       populate_hack_list (widget, pair);
 
@@ -1416,12 +1484,12 @@ sanity_check_resources (Widget toplevel)
       const char *name = XtName(w);
       XmString xm = 0;
       char *label = 0;
-      XtVaGetValues (w, XmNlabelString, &xm, 0);
+      XtVaGetValues (w, XmNlabelString, &xm, NULL);
       if (xm) XmStringGetLtoR (xm, XmSTRING_DEFAULT_CHARSET, &label);
       if (w && (!label || !strcmp (name, label)))
         {
           xm = XmStringCreate ("ERROR", XmSTRING_DEFAULT_CHARSET);
-          XtVaSetValues (w, XmNlabelString, xm, 0);
+          XtVaSetValues (w, XmNlabelString, xm, NULL);
         }
     }
 }
@@ -1439,17 +1507,17 @@ hack_button_sizes (Widget toplevel)
   Widget down = name_to_widget (toplevel, "down");
   Dimension w1, w2;
 
-  XtVaGetValues (demo, XmNwidth, &w1, 0);
-  XtVaGetValues (man,  XmNwidth, &w2, 0);
-  XtVaSetValues ((w1 > w2 ? man : demo), XmNwidth, (w1 > w2 ? w1 : w2), 0);
+  XtVaGetValues (demo, XmNwidth, &w1, NULL);
+  XtVaGetValues (man,  XmNwidth, &w2, NULL);
+  XtVaSetValues ((w1 > w2 ? man : demo), XmNwidth, (w1 > w2 ? w1 : w2), NULL);
 
-  XtVaGetValues (ok,   XmNwidth, &w1, 0);
-  XtVaGetValues (can,  XmNwidth, &w2, 0);
-  XtVaSetValues ((w1 > w2 ? can : ok), XmNwidth, (w1 > w2 ? w1 : w2), 0);
+  XtVaGetValues (ok,   XmNwidth, &w1, NULL);
+  XtVaGetValues (can,  XmNwidth, &w2, NULL);
+  XtVaSetValues ((w1 > w2 ? can : ok), XmNwidth, (w1 > w2 ? w1 : w2), NULL);
 
-  XtVaGetValues (up,   XmNwidth, &w1, 0);
-  XtVaGetValues (down, XmNwidth, &w2, 0);
-  XtVaSetValues ((w1 > w2 ? down : up), XmNwidth, (w1 > w2 ? w1 : w2), 0);
+  XtVaGetValues (up,   XmNwidth, &w1, NULL);
+  XtVaGetValues (down, XmNwidth, &w2, NULL);
+  XtVaSetValues ((w1 > w2 ? down : up), XmNwidth, (w1 > w2 ? w1 : w2), NULL);
 }
 
 
@@ -1608,17 +1676,22 @@ static int
 demo_ehandler (Display *dpy, XErrorEvent *error)
 {
   fprintf (stderr, "\nX error in %s:\n", progname);
-  if (XmuPrintDefaultErrorMessage (dpy, error, stderr))
-    exit (-1);
-  else
-    fprintf (stderr, " (nonfatal.)\n");
+  XmuPrintDefaultErrorMessage (dpy, error, stderr);
+  exit (-1);
   return 0;
 }
 
 
 
+#ifdef __GNUC__
+ __extension__     /* shut up about "string length is greater than the length
+                      ISO C89 compilers are required to support" when including
+                      the .ad file... */
+#endif
+
 static char *defaults[] = {
 #include "XScreenSaver_ad.h"
+#include "XScreenSaver_Xm_ad.h"
  0
 };
 
@@ -1695,7 +1768,7 @@ main (int argc, char **argv)
      was in argv[0].
    */
   p->db = db;
-  load_init_file (p);
+  load_init_file (dpy, p);
   *p2 = *p;
 
   /* Now that Xt has been initialized, and the resources have been read,
@@ -1748,7 +1821,7 @@ main (int argc, char **argv)
     *s2 = 0;
     *s4 = 0;
     sprintf (title, "%.50s %.50s, %.50s", progclass, s1, s3);
-    XtVaSetValues (toplevel_shell, XtNtitle, title, 0);
+    XtVaSetValues (toplevel_shell, XtNtitle, title, NULL);
     free (v);
   }
 
@@ -1768,7 +1841,7 @@ main (int argc, char **argv)
   ensure_selected_item_visible (name_to_widget (toplevel_shell, "list"));
 
   XSync (dpy, False);
-  XtVaSetValues (toplevel_shell, XmNallowShellResize, False, 0);
+  XtVaSetValues (toplevel_shell, XmNallowShellResize, False, NULL);
 
 
   /* Handle the -prefs command-line argument. */
@@ -1781,7 +1854,7 @@ main (int argc, char **argv)
       Cardinal nkids = 0;
       if (!tabber) abort();
   
-      XtVaGetValues (tabber, XmNnumChildren, &nkids, XmNchildren, &kids, 0);
+      XtVaGetValues (tabber, XmNnumChildren, &nkids, XmNchildren, &kids, NULL);
       if (!kids) abort();
       if (nkids > 0)
         XtUnmanageChildren (kids, nkids);