From http://www.jwz.org/xscreensaver/xscreensaver-5.30.tar.gz
[xscreensaver] / utils / resources.c
index 19b2cb6ccf8149d1750f2ad41272e3fa488a15c3..d95a103cd52e04fb6b6c5ba33e1d261741c5dd80 100644 (file)
@@ -1,5 +1,4 @@
-/* xscreensaver, Copyright (c) 1992, 1997, 1998, 2001, 2003, 2006
- *  Jamie Zawinski <jwz@jwz.org>
+/* xscreensaver, Copyright (c) 1992-2014 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
@@ -172,7 +171,7 @@ get_pixel_resource (Display *dpy, Colormap cmap,
       goto DEFAULT;
     }
   free (s);
-  return color.pixel;
+  return (unsigned int) color.pixel;
  DEFAULT:
   if (s) free (s);
 
@@ -185,7 +184,7 @@ get_pixel_resource (Display *dpy, Colormap cmap,
     color.flags = DoRed|DoGreen|DoBlue;
     color.red = color.green = color.blue = (black_p ? 0 : 0xFFFF);
     if (XAllocColor (dpy, cmap, &color))
-      return color.pixel;
+      return (unsigned int) color.pixel;
     else
       {
         fprintf (stderr, "%s: couldn't allocate %s either!\n", progname,
@@ -263,3 +262,35 @@ get_minutes_resource (Display *dpy, char *res_name, char *res_class)
 {
   return get_time_resource (dpy, res_name, res_class, False);
 }
+
+
+/* A utility function for event-handler functions:
+   Returns True if the event is a simple click, Space, Tab, etc.
+   Returns False otherwise.
+   The idea here is that most hacks interpret to clicks or basic
+   keypresses as "change it up".
+
+   This isn't really the right file for this, but whatever.
+ */
+Bool
+screenhack_event_helper (Display *dpy, Window window, XEvent *event)
+{
+  if (event->xany.type == KeyPress)
+    {
+      KeySym keysym;
+      char c = 0;
+      XLookupString (&event->xkey, &c, 1, &keysym, 0);
+      if (c == ' ' || c == '\t' || c == '\r' || c == '\n' ||
+          keysym == XK_Left || keysym == XK_Right ||
+          keysym == XK_Up || keysym == XK_Down ||
+          keysym == XK_Prior || keysym == XK_Next)
+        return True;
+    }
+  else if (event->xany.type == ButtonPress)
+    {
+      if (event->xbutton.button == 1)
+        return True;
+    }
+
+  return False;
+}