http://packetstormsecurity.org/UNIX/admin/xscreensaver-4.14.tar.gz
[xscreensaver] / driver / demo-Gtk.c
index 715ca3934f55a472ed8a2b8300177e391a65d9b3..9c2f0ca8dc9b1dc9666f39527afef4ac4de9a917 100644 (file)
@@ -135,6 +135,8 @@ enum {
 /* from exec.c */
 extern void exec_command (const char *shell, const char *command, int nice);
 
+static void hack_subproc_environment (Window preview_window_id, Bool debug_p);
+
 #undef countof
 #define countof(x) (sizeof((x))/sizeof((*x)))
 
@@ -1576,7 +1578,6 @@ mode_menu_item_cb (GtkWidget *widget, gpointer user_data)
   GList *menu_items = gtk_container_children (GTK_CONTAINER (widget->parent));
   int menu_index = 0;
   saver_mode new_mode;
-  int old_selected = p->selected_hack;
 
   while (menu_items)
     {
@@ -1590,17 +1591,12 @@ mode_menu_item_cb (GtkWidget *widget, gpointer user_data)
   new_mode = mode_menu_order[menu_index];
 
   /* Keep the same list element displayed as before; except if we're
-     switching *to* "one screensaver" mode from any other mode, scroll
-     to and select "the one".
+     switching *to* "one screensaver" mode from any other mode, set
+     "the one" to be that which is currently selected.
    */
-  list_elt = -1;
+  list_elt = selected_list_element (s);
   if (new_mode == ONE_HACK)
-    list_elt = (p->selected_hack >= 0
-                ? s->hack_number_to_list_elt[p->selected_hack]
-                : -1);
-
-  if (list_elt < 0)
-    list_elt = selected_list_element (s);
+    p->selected_hack = s->list_elt_to_hack_number[list_elt];
 
   {
     saver_mode old_mode = p->mode;
@@ -1611,9 +1607,6 @@ mode_menu_item_cb (GtkWidget *widget, gpointer user_data)
   }
 
   pref_changed_cb (widget, user_data);
-
-  if (old_selected != p->selected_hack)
-    abort();    /* dammit, not again... */
 }
 
 
@@ -2372,7 +2365,7 @@ populate_prefs_page (state *s)
 # define THROTTLE(NAME) if (p->NAME != 0 && p->NAME < 60000) p->NAME = 60000
   THROTTLE (timeout);
   THROTTLE (cycle);
-  THROTTLE (passwd_timeout);
+  /* THROTTLE (passwd_timeout); */  /* GUI doesn't set this; leave it alone */
 # undef THROTTLE
 
 # define FMT_MINUTES(NAME,N) \
@@ -3439,6 +3432,8 @@ launch_preview_subproc (state *s)
       {
         close (ConnectionNumber (GDK_DISPLAY()));
 
+        hack_subproc_environment (id, s->debug_p);
+
         usleep (250000);  /* pause for 1/4th second before launching, to give
                              the previous program time to die and flush its X
                              buffer, so we don't get leftover turds on the
@@ -3529,6 +3524,29 @@ hack_environment (state *s)
 }
 
 
+static void
+hack_subproc_environment (Window preview_window_id, Bool debug_p)
+{
+  /* Store a window ID in $XSCREENSAVER_WINDOW -- this isn't strictly
+     necessary yet, but it will make programs work if we had invoked
+     them with "-root" and not with "-window-id" -- which, of course,
+     doesn't happen.
+   */
+  char *nssw = (char *) malloc (40);
+  sprintf (nssw, "XSCREENSAVER_WINDOW=0x%X", (unsigned int) preview_window_id);
+
+  /* Allegedly, BSD 4.3 didn't have putenv(), but nobody runs such systems
+     any more, right?  It's not Posix, but everyone seems to have it. */
+  if (putenv (nssw))
+    abort ();
+
+  if (debug_p)
+    fprintf (stderr, "%s: %s\n", blurb(), nssw);
+
+  /* do not free(nssw) -- see above */
+}
+
+
 /* Called from a timer:
    Launches the currently-chosen subprocess, if it's not already running.
    If there's a different process running, kills it.
@@ -4034,6 +4052,7 @@ main (int argc, char **argv)
   Widget toplevel_shell;
   char *real_progname = argv[0];
   char *window_title;
+  char *geom = 0;
   Bool crapplet_p = False;
   char *str;
 
@@ -4128,6 +4147,21 @@ main (int argc, char **argv)
           argc--;
           i--;
         }
+      else if (argv[i] &&
+               argc > i+1 &&
+               *argv[i+1] &&
+               (!strcmp(argv[i], "-geometry") ||
+                !strcmp(argv[i], "-geom") ||
+                !strcmp(argv[i], "-geo") ||
+                !strcmp(argv[i], "-g")))
+        {
+          int j;
+          geom = argv[i+1];
+          for (j = i; j < argc; j++)  /* remove them from the list */
+            argv[j] = argv[j+2];
+          argc -= 2;
+          i -= 2;
+        }
       else if (argv[i] &&
                argc > i+1 &&
                *argv[i+1] &&
@@ -4285,7 +4319,8 @@ main (int argc, char **argv)
         ;
       else
        {
-         fprintf (stderr, _("%s: unknown option: %s\n"), real_progname, argv[i]);
+         fprintf (stderr, _("%s: unknown option: %s\n"), real_progname,
+                   argv[i]);
           fprintf (stderr, "%s: %s\n", real_progname, usage);
           exit (1);
        }
@@ -4496,6 +4531,11 @@ main (int argc, char **argv)
   free (window_title);
   window_title = 0;
 
+#ifdef HAVE_GTK2
+  /* After picking the default size, allow -geometry to override it. */
+  if (geom)
+    gtk_window_parse_geometry (GTK_WINDOW (s->toplevel_widget), geom);
+#endif
 
   gtk_widget_show (s->toplevel_widget);
   init_icon (GTK_WIDGET (s->toplevel_widget)->window);  /* after `show' */