http://apple.doit.wisc.edu/mirrors/amug/linux/linuxppc/sources/tarballs/xscreensaver...
[xscreensaver] / hacks / screenhack.c
index 0e1c678e1039dc5451afec54ab5eca1ec7d14140..8a882fcd7b4ddd41426d673f79d387822241abc2 100644 (file)
@@ -38,6 +38,7 @@
 #include <X11/Shell.h>
 #include <X11/StringDefs.h>
 #include <X11/Xutil.h>
+#include <X11/keysym.h>
 
 #ifdef __sgi
 # include <X11/SGIScheme.h>    /* for SgiUseSchemes() */
@@ -58,6 +59,7 @@
 
 char *progname;
 XrmDatabase db;
+XtAppContext app;
 Bool mono_p;
 
 static XrmOptionDescRec default_options [] = {
@@ -159,10 +161,6 @@ MapNotify_event_p (Display *dpy, XEvent *event, XPointer window)
 }
 
 
-#ifdef USE_GL
-extern Visual *get_gl_visual (Screen *, const char *, const char *);
-#endif
-
 #ifdef XLOCKMORE
 extern void pre_merge_options (void);
 #endif
@@ -188,7 +186,10 @@ screenhack_handle_event (Display *dpy, XEvent *event)
             c == 3 ||  /* ^C */
             c == 27)   /* ESC */
           exit (0);
+        else if (! (keysym >= XK_Shift_L && keysym <= XK_Hyper_R))
+          XBell (dpy, 0);  /* beep for non-chord keys */
       }
+      break;
     case ButtonPress:
       XBell (dpy, 0);
       break;
@@ -232,11 +233,38 @@ screenhack_handle_events (Display *dpy)
 }
 
 
+static Visual *
+pick_visual (Screen *screen)
+{
+#ifdef USE_GL
+  /* If we're linking against GL (that is, this is the version of screenhack.o
+     that the GL hacks will use, which is different from the one that the
+     non-GL hacks will use) then try to pick the "best" visual by interrogating
+     the GL library instead of by asking Xlib.  GL knows better.
+   */
+  Visual *v = 0;
+  char *string = get_string_resource ("visualID", "VisualID");
+
+  if (!string || !*string ||
+      !strcmp (string, "gl") ||
+      !strcmp (string, "best") ||
+      !strcmp (string, "color") ||
+      !strcmp (string, "default"))
+    v = get_gl_visual (screen);                /* from ../utils/visual-gl.c */
+
+  if (string)
+    free (string);
+  if (v)
+    return v;
+#endif /* USE_GL */
+
+  return get_visual_resource (screen, "visualID", "VisualID", False);
+}
+
 
 int
 main (int argc, char **argv)
 {
-  XtAppContext app;
   Widget toplevel;
   Display *dpy;
   Window window;
@@ -360,12 +388,7 @@ main (int argc, char **argv)
     {
       Boolean def_visual_p;
       Screen *screen = XtScreen (toplevel);
-
-#ifdef USE_GL
-      visual = get_gl_visual (screen, "visualID", "VisualID");
-#else
-      visual = get_visual_resource (screen, "visualID", "VisualID", False);
-#endif
+      visual = pick_visual (screen);
 
       if (toplevel->core.width <= 0)
        toplevel->core.width = 600;