http://ftp.x.org/contrib/applications/xscreensaver-2.23.tar.gz
[xscreensaver] / hacks / screenhack.c
index 8462d4e792999b6431539f793ad4d5f4f8d399fb..1f99b3ab495302d9d8def8840d93850fd400e02f 100644 (file)
@@ -1,4 +1,4 @@
-/* xscreensaver, Copyright (c) 1992, 1995, 1997
+/* xscreensaver, Copyright (c) 1992, 1995, 1997, 1998
  *  Jamie Zawinski <jwz@netscape.com>
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
 #include <X11/CoreP.h>
 #include <X11/Shell.h>
 #include <X11/StringDefs.h>
+
+#ifdef __sgi
+# include <X11/SGIScheme.h>    /* for SgiUseSchemes() */
+#endif /* __sgi */
+
 #ifdef HAVE_XMU
 # ifndef VMS
 #  include <X11/Xmu/Error.h>
@@ -61,15 +66,17 @@ static XrmOptionDescRec default_options [] = {
   { "-install",        ".installColormap",     XrmoptionNoArg, "True" },
   { "-noinstall",".installColormap",   XrmoptionNoArg, "False" },
   { "-visual", ".visualID",            XrmoptionSepArg, 0 },
+  { "-window-id", ".windowID",         XrmoptionSepArg, 0 },
   { 0, 0, 0, 0 }
 };
 
 static char *default_defaults[] = {
-  "*root:              false",
+  ".root:              false",
   "*geometry:          600x480", /* this should be .geometry, but nooooo... */
   "*mono:              false",
   "*installColormap:   false",
   "*visualID:          default",
+  "*windowID:          ",
   0
 };
 
@@ -108,6 +115,23 @@ merge_options (void)
          def_defaults_size * sizeof(*defaults));
   memcpy (merged_defaults + def_defaults_size, defaults,
          (defaults_size + 1) * sizeof(*defaults));
+
+  /* This totally sucks.  Xt should behave like this by default.
+     If the string in `defaults' looks like ".foo", change that
+     to "Progclass.foo".
+   */
+  {
+    char **s;
+    for (s = merged_defaults; *s; s++)
+      if (**s == '.')
+       {
+         const char *oldr = *s;
+         char *newr = (char *) malloc(strlen(oldr) + strlen(progclass) + 3);
+         strcpy (newr, progclass);
+         strcat (newr, oldr);
+         *s = newr;
+       }
+  }
 }
 
 \f
@@ -154,6 +178,7 @@ main (int argc, char **argv)
   Visual *visual;
   Colormap cmap;
   Bool root_p;
+  Window on_window = 0;
   XEvent event;
   Boolean dont_clear /*, dont_map */;
   char version[255];
@@ -162,6 +187,19 @@ main (int argc, char **argv)
   pre_merge_options ();
 #endif
   merge_options ();
+
+#ifdef __sgi
+  /* We have to do this on SGI to prevent the background color from being
+     overridden by the current desktop color scheme (we'd like our backgrounds
+     to be black, thanks.)  This should be the same as setting the
+     "*useSchemes: none" resource, but it's not -- if that resource is
+     present in the `default_defaults' above, it doesn't work, though it
+     does work when passed as an -xrm arg on the command line.  So screw it,
+     turn them off from C instead.
+   */
+  SgiUseSchemes ("none"); 
+#endif /* __sgi */
+
   toplevel = XtAppInitialize (&app, progclass, merged_options,
                              merged_options_size, &argc, argv,
                              merged_defaults, 0, 0);
@@ -219,7 +257,24 @@ main (int argc, char **argv)
     mono_p = True;
 
   root_p = get_boolean_resource ("root", "Boolean");
-  if (root_p)
+
+  {
+    char *s = get_string_resource ("windowID", "WindowID");
+    if (s && *s)
+      on_window = get_integer_resource ("windowID", "WindowID");
+    if (s) free (s);
+  }
+
+  if (on_window)
+    {
+      XWindowAttributes xgwa;
+      window = (Window) on_window;
+      XtDestroyWidget (toplevel);
+      XGetWindowAttributes (dpy, window, &xgwa);
+      cmap = xgwa.colormap;
+      visual = xgwa.visual;
+    }
+  else if (root_p)
     {
       XWindowAttributes xgwa;
       window = RootWindowOfScreen (XtScreen (toplevel));
@@ -314,7 +369,7 @@ main (int argc, char **argv)
       XClearWindow (dpy, window);
     }
 
-  if (!root_p)
+  if (!root_p && !on_window)
     /* wait for it to be mapped */
     XIfEvent (dpy, &event, MapNotify_event_p, (XPointer) window);