From http://www.jwz.org/xscreensaver/xscreensaver-5.38.tar.gz
[xscreensaver] / driver / splash.c
index bc830029423ac9c24eeae2ab5119e51c0e14fc9d..e382fa2a58ab42a7911bea4485b6ca41bdc7246c 100644 (file)
@@ -1,4 +1,4 @@
-/* xscreensaver, Copyright (c) 1991-2013 Jamie Zawinski <jwz@netscape.com>
+/* xscreensaver, Copyright (c) 1991-2017 Jamie Zawinski <jwz@netscape.com>
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
@@ -103,6 +103,31 @@ static void do_prefs (saver_screen_info *ssi);
 static void do_help (saver_screen_info *ssi);
 
 
+XFontStruct *
+splash_load_font (Display *dpy, char *name, char *class)
+{
+  /* Try RES, RES2, etc. */
+  int i;
+  for (i = 0; i < 4; i++)
+    {
+      char *name2 = (char *) malloc (strlen(name) + 2);
+      char *s;
+      if (i)
+        sprintf (name2, "%s%d", name, i+1);
+      else
+        strcpy (name2, name);
+      s = get_string_resource (dpy, name2, class);
+      free (name2);
+      if (s && *s)
+        {
+          XFontStruct *f = XLoadQueryFont (dpy, s);
+          if (f) return f;
+        }
+    }
+  return XLoadQueryFont (dpy, "fixed");
+}
+
+
 struct splash_dialog_data {
 
   saver_screen_info *prompt_screen;
@@ -165,9 +190,8 @@ make_splash_dialog (saver_info *si)
   splash_dialog_data *sp;
   saver_screen_info *ssi;
   Colormap cmap;
-  char *f;
 
-  Bool whine = senescent_p ();
+  Bool whine = decrepit_p ();
 
   if (whine)
     {
@@ -246,20 +270,12 @@ make_splash_dialog (saver_info *si)
     sp->heading_label = s;
   }
 
-  f = get_string_resource (si->dpy, "splash.headingFont", "Dialog.Font");
-  sp->heading_font = XLoadQueryFont (si->dpy, (f ? f : "fixed"));
-  if (!sp->heading_font) sp->heading_font = XLoadQueryFont (si->dpy, "fixed");
-  if (f) free (f);
-
-  f = get_string_resource(si->dpy, "splash.bodyFont", "Dialog.Font");
-  sp->body_font = XLoadQueryFont (si->dpy, (f ? f : "fixed"));
-  if (!sp->body_font) sp->body_font = XLoadQueryFont (si->dpy, "fixed");
-  if (f) free (f);
-
-  f = get_string_resource(si->dpy, "splash.buttonFont", "Dialog.Font");
-  sp->button_font = XLoadQueryFont (si->dpy, (f ? f : "fixed"));
-  if (!sp->button_font) sp->button_font = XLoadQueryFont (si->dpy, "fixed");
-  if (f) free (f);
+  sp->heading_font =
+    splash_load_font (si->dpy, "splash.headingFont", "Dialog.Font");
+  sp->body_font =
+    splash_load_font (si->dpy, "splash.bodyFont", "Dialog.Font");
+  sp->button_font =
+    splash_load_font (si->dpy, "splash.buttonFont", "Dialog.Font");
 
   sp->foreground = get_pixel_resource (si->dpy, cmap,
                                        "splash.foreground",
@@ -424,21 +440,6 @@ make_splash_dialog (saver_info *si)
 
   {
     int sx = 0, sy = 0, w, h;
-    int mouse_x = 0, mouse_y = 0;
-
-    {
-      Window pointer_root, pointer_child;
-      int root_x, root_y, win_x, win_y;
-      unsigned int mask;
-      if (XQueryPointer (si->dpy,
-                         RootWindowOfScreen (ssi->screen),
-                         &pointer_root, &pointer_child,
-                         &root_x, &root_y, &win_x, &win_y, &mask))
-        {
-          mouse_x = root_x;
-          mouse_y = root_y;
-        }
-    }
 
     x = ssi->x;
     y = ssi->y;
@@ -493,14 +494,13 @@ draw_splash_window (saver_info *si)
   splash_dialog_data *sp = si->sp_data;
   XGCValues gcv;
   GC gc1, gc2;
-  int hspacing, vspacing, height;
+  int vspacing, height;
   int x1, x2, x3, y1, y2;
   int sw;
 
 #ifdef PREFS_BUTTON
+  int hspacing;
   int nbuttons = 3;
-#else  /* !PREFS_BUTTON */
-  int nbuttons = 2;
 #endif /* !PREFS_BUTTON */
 
   height = (sp->heading_font->ascent + sp->heading_font->descent +
@@ -580,9 +580,11 @@ draw_splash_window (saver_info *si)
               (sp->button_font->ascent + sp->button_font->descent))
              / 2)
        + sp->button_font->ascent);
+#ifdef PREFS_BUTTON
   hspacing = ((sp->width - x1 - (sp->shadow_width * 2) -
               sp->internal_border - (sp->button_width * nbuttons))
              / 2);
+#endif
 
   x2 = x1 + ((sp->button_width - string_width(sp->button_font, sp->demo_label))
             / 2);
@@ -778,9 +780,10 @@ void
 handle_splash_event (saver_info *si, XEvent *event)
 {
   splash_dialog_data *sp = si->sp_data;
-  saver_screen_info *ssi = sp->prompt_screen;
+  saver_screen_info *ssi;
   int which = 0;
   if (!sp) return;
+  ssi = sp->prompt_screen;
 
   switch (event->xany.type)
     {