Turning compositing on and off at runtime



Hi,

Here's a patch that adds a new /apps/metacity/general/compositing_manager
preference to turn compositing on and off at runtime. If noone sees a problem with
it, I'll commit.


Soren
? 0202metacity.patch
? birnan
? birnan2
? blah
? use-new-extension.metacity.patch
? src/asdf
? src/birnan
? src/blah
? src/candy.c
? src/candy.h
? src/installlog
? src/meta
? src/metacity-comp.patch
? src/metacity0131.patch
? src/metapatch
? src/notify-daemon-0.3.1-xselection.patch
? src/oldcompositor.c
? src/plan
? src/spam
? src/spew
? src/sugar.c
? src/unminimize
Index: src/display.c
===================================================================
RCS file: /cvs/gnome/metacity/src/display.c,v
retrieving revision 1.277
diff -u -p -u -r1.277 display.c
--- src/display.c	3 Feb 2006 18:09:16 -0000	1.277
+++ src/display.c	15 Feb 2006 23:47:46 -0000
@@ -185,6 +185,48 @@ sn_error_trap_pop (SnDisplay *sn_display
 }
 #endif
 
+static void
+enable_compositor (MetaDisplay *display)
+{
+  GSList *list;
+
+  if (!display->compositor)
+      display->compositor = meta_compositor_new (display);
+
+  if (!display->compositor)
+    return;
+  
+  for (list = display->screens; list != NULL; list = list->next)
+    {
+      MetaScreen *screen = list->data;
+      
+      meta_compositor_manage_screen (screen->display->compositor,
+				     screen);
+
+      meta_screen_composite_all_windows (screen);
+    }
+}
+
+static void
+disable_compositor (MetaDisplay *display)
+{
+  GSList *list;
+  
+  if (!display->compositor)
+    return;
+  
+  for (list = display->screens; list != NULL; list = list->next)
+    {
+      MetaScreen *screen = list->data;
+      
+      meta_compositor_unmanage_screen (screen->display->compositor,
+				       screen);
+    }
+  
+  meta_compositor_destroy (display->compositor);
+  display->compositor = NULL;
+}
+
 gboolean
 meta_display_open (const char *name)
 {
@@ -657,7 +699,7 @@ meta_display_open (const char *name)
 
   display->last_focus_time = timestamp;
   display->last_user_time = timestamp;
-  display->compositor = meta_compositor_new (display);
+  display->compositor = NULL;
   
   screens = NULL;
   
@@ -692,18 +734,6 @@ meta_display_open (const char *name)
     {
       MetaScreen *screen = tmp->data;
 	
-      /* The compositing manager opens its own connection to the X server
-       * and uses the XTest extension to ignore grabs. However, it also
-       * uses GL which opens yet another connection to the X server. With
-       * this ungrab/grab we would block indefinitely in XOpenDisplay().
-       */
-      meta_display_ungrab (display);
-      
-      meta_compositor_manage_screen (screen->display->compositor,
-				     screen);
-
-      meta_display_grab (display);
-  
       meta_screen_manage_all_windows (screen);
 
       tmp = tmp->next;
@@ -748,6 +778,9 @@ meta_display_open (const char *name)
   }
   
   meta_display_ungrab (display);  
+
+  if (meta_prefs_get_compositing_manager ())
+    enable_compositor (display);
   
   return TRUE;
 }
@@ -2415,9 +2448,12 @@ event_callback (XEvent   *event,
       break;
     }
 
-  meta_compositor_process_event (display->compositor,
-                                 event,
-                                 window);
+  if (display->compositor)
+    {
+      meta_compositor_process_event (display->compositor,
+				     event,
+				     window);
+    }
   
   display->current_time = CurrentTime;
   return filter_out_event;
@@ -4752,6 +4788,8 @@ static void
 prefs_changed_callback (MetaPreference pref,
                         void          *data)
 {
+  MetaDisplay *display = data;
+  
   /* It may not be obvious why we regrab on focus mode
    * change; it's because we handle focus clicks a
    * bit differently for the different focus modes.
@@ -4793,8 +4831,16 @@ prefs_changed_callback (MetaPreference p
     }
   else if (pref == META_PREF_AUDIBLE_BELL)
     {
-      MetaDisplay *display = data;
       meta_bell_set_audible (display, meta_prefs_bell_is_audible ());
+    }
+  else if (pref == META_PREF_COMPOSITING_MANAGER)
+    {
+      gboolean cm = meta_prefs_get_compositing_manager ();
+
+      if (cm)
+	enable_compositor (display);
+      else
+	disable_compositor (display);
     }
 }
 
Index: src/metacity.schemas.in
===================================================================
RCS file: /cvs/gnome/metacity/src/metacity.schemas.in,v
retrieving revision 1.47
diff -u -p -u -r1.47 metacity.schemas.in
--- src/metacity.schemas.in	21 Jan 2006 19:18:51 -0000	1.47
+++ src/metacity.schemas.in	15 Feb 2006 23:47:46 -0000
@@ -269,6 +269,20 @@
     </schema>
 
     <schema>
+      <key>/schemas/apps/metacity/general/compositing_manager</key>
+      <applyto>/apps/metacity/general/compositing_manager</applyto>
+      <owner>metacity</owner>
+      <type>boolean</type>
+      <default>FALSE</default>
+      <locale name="C">
+         <short>Compositing Manager</short>
+         <long>
+	Determines whether Metacity is a compositing manager.
+         </long>
+      </locale>
+    </schema>
+
+    <schema>
       <key>/schemas/apps/metacity/workspace_names/name</key>
       <applyto>/apps/metacity/workspace_names/name_1</applyto>
       <applyto>/apps/metacity/workspace_names/name_2</applyto>
Index: src/prefs.c
===================================================================
RCS file: /cvs/gnome/metacity/src/prefs.c,v
retrieving revision 1.60
diff -u -p -u -r1.60 prefs.c
--- src/prefs.c	14 Feb 2006 17:26:40 -0000	1.60
+++ src/prefs.c	15 Feb 2006 23:47:46 -0000
@@ -70,6 +70,7 @@
 #define KEY_VISUAL_BELL_TYPE "/apps/metacity/general/visual_bell_type"
 #define KEY_CURSOR_THEME "/desktop/gnome/peripherals/mouse/cursor_theme"
 #define KEY_CURSOR_SIZE "/desktop/gnome/peripherals/mouse/cursor_size"
+#define KEY_COMPOSITING_MANAGER "/apps/metacity/general/compositing_manager"
 
 #ifdef HAVE_GCONF
 static GConfClient *default_client = NULL;
@@ -97,6 +98,7 @@ static gboolean reduced_resources = FALS
 static gboolean gnome_accessibility = FALSE;
 static char *cursor_theme = NULL;
 static int   cursor_size = 24;
+static gboolean compositing_manager = FALSE;
 
 static MetaVisualBellType visual_bell_type = META_VISUAL_BELL_FULLSCREEN_FLASH;
 static MetaButtonLayout button_layout = {
@@ -150,6 +152,7 @@ static gboolean update_reduced_resources
 static gboolean update_gnome_accessibility  (gboolean     value);
 static gboolean update_cursor_theme       (const char *value);
 static gboolean update_cursor_size        (int size);
+static gboolean update_compositing_manager (gboolean	value);
 
 static void change_notify (GConfClient    *client,
                            guint           cnxn_id,
@@ -443,7 +446,11 @@ meta_prefs_init (void)
   update_audible = get_bool (KEY_AUDIBLE_BELL, &bool_val_2);
   if (update_visual || update_audible)
     update_visual_bell (bool_val, bool_val_2);
-      
+
+  bool_val = compositing_manager;
+  if (get_bool (KEY_COMPOSITING_MANAGER, &bool_val))
+    update_compositing_manager (bool_val);
+  
   str_val = gconf_client_get_string (default_client, KEY_VISUAL_BELL_TYPE,
                                      &err);
   cleanup_error (&err);
@@ -953,6 +960,22 @@ change_notify (GConfClient    *client,
       if (update_cursor_size (d))
 	queue_changed (META_PREF_CURSOR_SIZE);
     }
+  else if (strcmp (key, KEY_COMPOSITING_MANAGER) == 0)
+    {
+      gboolean b;
+
+      if (value && value->type != GCONF_VALUE_BOOL)
+        {
+          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
+                       KEY_COMPOSITING_MANAGER);
+          goto out;
+        }
+
+      b = value ? gconf_value_get_bool (value) : compositing_manager;
+
+      if (update_compositing_manager (b))
+        queue_changed (META_PREF_COMPOSITING_MANAGER);
+    }
   else
     {
       meta_topic (META_DEBUG_PREFS, "Key %s doesn't mean anything to Metacity\n",
@@ -1638,6 +1661,9 @@ meta_preference_to_string (MetaPreferenc
 
     case META_PREF_CURSOR_SIZE:
       return "CURSOR_SIZE";
+
+    case META_PREF_COMPOSITING_MANAGER:
+      return "COMPOSITING_MANAGER";
     }
 
   return "(unknown)";
@@ -2491,4 +2517,22 @@ meta_prefs_get_window_binding (const cha
     }
 
   g_assert_not_reached ();
+}
+
+#ifdef HAVE_GCONF
+static gboolean
+update_compositing_manager (gboolean value)
+{
+  gboolean old = compositing_manager;
+
+  compositing_manager = value;
+  
+  return old != compositing_manager;
+}
+#endif
+
+gboolean
+meta_prefs_get_compositing_manager (void)
+{
+  return compositing_manager;
 }
Index: src/prefs.h
===================================================================
RCS file: /cvs/gnome/metacity/src/prefs.h,v
retrieving revision 1.39
diff -u -p -u -r1.39 prefs.h
--- src/prefs.h	10 Jan 2006 19:43:21 -0000	1.39
+++ src/prefs.h	15 Feb 2006 23:47:46 -0000
@@ -52,7 +52,8 @@ typedef enum
   META_PREF_REDUCED_RESOURCES,
   META_PREF_GNOME_ACCESSIBILITY,
   META_PREF_CURSOR_THEME,
-  META_PREF_CURSOR_SIZE
+  META_PREF_CURSOR_SIZE,
+  META_PREF_COMPOSITING_MANAGER
 } MetaPreference;
 
 typedef void (* MetaPrefsChangedFunc) (MetaPreference pref,
@@ -89,6 +90,7 @@ const char*                 meta_prefs_g
 
 void                        meta_prefs_get_button_layout (MetaButtonLayout *button_layout);
 MetaActionDoubleClickTitlebar meta_prefs_get_action_double_click_titlebar (void);
+gboolean		    meta_prefs_get_composited	      (void);
 
 void meta_prefs_set_num_workspaces (int n_workspaces);
 
@@ -98,6 +100,7 @@ void        meta_prefs_change_workspace_
 
 const char* meta_prefs_get_cursor_theme      (void);
 int         meta_prefs_get_cursor_size       (void);
+gboolean    meta_prefs_get_compositing_manager (void);
 
 /* Screen bindings */
 #define META_KEYBINDING_WORKSPACE_1              "switch_to_workspace_1"
Index: src/screen.c
===================================================================
RCS file: /cvs/gnome/metacity/src/screen.c,v
retrieving revision 1.152
diff -u -p -u -r1.152 screen.c
--- src/screen.c	20 Jan 2006 22:03:55 -0000	1.152
+++ src/screen.c	15 Feb 2006 23:47:47 -0000
@@ -731,62 +731,104 @@ meta_screen_free (MetaScreen *screen)
   meta_display_ungrab (display);
 }
 
-void
-meta_screen_manage_all_windows (MetaScreen *screen)
+typedef struct
+{
+  Window		xwindow;
+  XWindowAttributes	attrs;
+} WindowInfo;
+
+static GList *
+list_windows (MetaScreen *screen)
 {
   Window ignored1, ignored2;
   Window *children;
-  int n_children;
-  int i;
-
-  /* Must grab server to avoid obvious race condition */
-  meta_display_grab (screen->display);
+  guint n_children, i;
+  GList *result;
 
-  meta_error_trap_push_with_return (screen->display);
-  
   XQueryTree (screen->display->xdisplay,
               screen->xroot,
               &ignored1, &ignored2, &children, &n_children);
 
-  if (meta_error_trap_pop_with_return (screen->display, TRUE) != Success)
+  result = NULL;
+  for (i = 0; i < n_children; ++i)
     {
-      meta_display_ungrab (screen->display);
-      return;
-    }
+      WindowInfo *info = g_new0 (WindowInfo, 1);
 
-  meta_stack_freeze (screen->stack);
-  i = 0;
-  while (i < n_children)
-    {
-      XWindowAttributes attrs;
-      
       meta_error_trap_push_with_return (screen->display);
       
       XGetWindowAttributes (screen->display->xdisplay,
-                            children[i], &attrs);
-      
-      if (meta_error_trap_pop_with_return (screen->display, TRUE) != Success)
-        {
+                            children[i], &info->attrs);
+
+      if (meta_error_trap_pop_with_return (screen->display, TRUE))
+	{
           meta_verbose ("Failed to get attributes for window 0x%lx\n",
                         children[i]);
+	  g_free (info);
         }
       else
         {
-          meta_window_new_with_attrs (screen->display, children[i], TRUE,
-                                      &attrs);
+	  info->xwindow = children[i];
+	}
 
-          meta_compositor_add_window (screen->display->compositor,
-                                      children[i], &attrs);
-        }
+      result = g_list_prepend (result, info);
+    }
+
+  if (children)
+    XFree (children);
+
+  return g_list_reverse (result);
+}
+
+void
+meta_screen_manage_all_windows (MetaScreen *screen)
+{
+  GList *windows;
+  GList *list;
+
+  meta_display_grab (screen->display);
+  
+  windows = list_windows (screen);
+
+  meta_stack_freeze (screen->stack);
+  for (list = windows; list != NULL; list = list->next)
+    {
+      WindowInfo *info = list->data;
 
-      ++i;
+      meta_window_new_with_attrs (screen->display, info->xwindow, TRUE,
+				  &info->attrs);
     }
   meta_stack_thaw (screen->stack);
 
+  g_list_foreach (windows, (GFunc)g_free, NULL);
+  g_list_free (windows);
+
   meta_display_ungrab (screen->display);
+}
+
+void
+meta_screen_composite_all_windows (MetaScreen *screen)
+{
+  GList *windows, *list;
+
+  if (!screen->display->compositor)
+    return;
   
-  if (children)
-    XFree (children);
+  windows = list_windows (screen);
+
+  meta_stack_freeze (screen->stack);
+
+  for (list = windows; list != NULL; list = list->next)
+    {
+      WindowInfo *info = list->data;
+
+      meta_compositor_add_window (screen->display->compositor,
+				  info->xwindow, &info->attrs);
+    }
+
+  meta_stack_thaw (screen->stack);
+
+  g_list_foreach (windows, (GFunc)g_free, NULL);
+  g_list_free (windows);
 }
 
 MetaScreen*
Index: src/screen.h
===================================================================
RCS file: /cvs/gnome/metacity/src/screen.h,v
retrieving revision 1.69
diff -u -p -u -r1.69 screen.h
--- src/screen.h	13 Jan 2006 19:41:01 -0000	1.69
+++ src/screen.h	15 Feb 2006 23:47:47 -0000
@@ -205,6 +205,6 @@ void     meta_screen_update_showing_desk
 
 void     meta_screen_apply_startup_properties (MetaScreen *screen,
                                                MetaWindow *window);
-
+void	 meta_screen_composite_all_windows (MetaScreen *screen);
 
 #endif


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]