Patch to add click-to-raise option to Metacity



Hi, all,

Here is a trivial patch to add a click-to-raise option to Metacity. 
L33t haxx0rs may find it useful; I certainly do :)

You can still raise windows by clicking on the title bar or on the
window frame.

I've put this patch in bug #115753 so that it doesn't get lost.

  Federico
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/metacity/ChangeLog,v
retrieving revision 1.600.4.2
diff -u -r1.600.4.2 ChangeLog
--- ChangeLog	5 Feb 2003 04:44:41 -0000	1.600.4.2
+++ ChangeLog	22 Jun 2003 23:16:22 -0000
@@ -1,3 +1,17 @@
+2003-06-22  Federico Mena Quintero  <federico ximian com>
+
+	* src/display.c (event_callback): Use
+	meta_prefs_get_raise_on_click() to decide whether we should raise
+	windows.
+
+	* src/prefs.c (meta_prefs_get_raise_on_click): New function.
+	(change_notify): Added the case for raise_on_click.
+	(meta_preference_to_string): Likewise.
+
+	* src/prefs.h (MetaPreference): Added META_PREF_RAISE_ON_CLICK.
+
+	* src/metacity.schemas.in: Added schema for general/raise_on_click.
+
 2003-02-04  Havoc Pennington  <hp redhat com>
 
 	* src/tools/Makefile.am: fix to get metacity-properties.c in the 
Index: src/display.c
===================================================================
RCS file: /cvs/gnome/metacity/src/display.c,v
retrieving revision 1.174
diff -u -r1.174 display.c
--- src/display.c	5 Jan 2003 07:51:02 -0000	1.174
+++ src/display.c	22 Jun 2003 23:16:30 -0000
@@ -1311,7 +1311,8 @@
                    * frames.c or special-cased if the click was on a
                    * minimize/close button.
                    */
-                  meta_window_raise (window);
+		  if (meta_prefs_get_raise_on_click ())
+		    meta_window_raise (window);
                   
                   meta_topic (META_DEBUG_FOCUS,
                               "Focusing %s due to unmodified button %d press (display.c)\n",
Index: src/metacity.schemas.in
===================================================================
RCS file: /cvs/gnome/metacity/src/metacity.schemas.in,v
retrieving revision 1.24.4.1
diff -u -r1.24.4.1 metacity.schemas.in
--- src/metacity.schemas.in	5 Feb 2003 04:30:48 -0000	1.24.4.1
+++ src/metacity.schemas.in	22 Jun 2003 23:16:31 -0000
@@ -110,6 +110,22 @@
     </schema>
 
     <schema>
+      <key>/schemas/apps/metacity/general/raise_on_click</key>
+      <applyto>/apps/metacity/general/raise_on_click</applyto>
+      <owner>metacity</owner>
+      <type>bool</type>
+      <default>true</default>
+      <locale name="C">
+         <short>Raise windows when a mouse button is pressed on them</short>
+         <long>
+           If true, pressing a mouse button on a window will cause it
+           to be raised to the top of the stack.  If false, windows
+           must be raised explicitly by clicking on their title bar.
+         </long>
+      </locale>
+    </schema>
+
+    <schema>
       <key>/schemas/apps/metacity/general/theme</key>
       <applyto>/apps/metacity/general/theme</applyto>
       <owner>metacity</owner>
Index: src/prefs.c
===================================================================
RCS file: /cvs/gnome/metacity/src/prefs.c,v
retrieving revision 1.39
diff -u -r1.39 prefs.c
--- src/prefs.c	15 Jan 2003 02:39:07 -0000	1.39
+++ src/prefs.c	22 Jun 2003 23:16:34 -0000
@@ -40,6 +40,7 @@
 #define KEY_ACTION_DOUBLE_CLICK_TITLEBAR "/apps/metacity/general/action_double_click_titlebar"
 #define KEY_AUTO_RAISE "/apps/metacity/general/auto_raise"
 #define KEY_AUTO_RAISE_DELAY "/apps/metacity/general/auto_raise_delay"
+#define KEY_RAISE_ON_CLICK "/apps/metacity/general/raise_on_click"
 #define KEY_THEME "/apps/metacity/general/theme"
 #define KEY_USE_SYSTEM_FONT  "/apps/metacity/general/titlebar_uses_system_font"
 #define KEY_TITLEBAR_FONT "/apps/metacity/general/titlebar_font"
@@ -73,6 +74,8 @@
 static gboolean disable_workarounds = FALSE;
 static gboolean auto_raise = FALSE;
 static gboolean auto_raise_delay = 500;
+static gboolean raise_on_click = TRUE;
+
 static MetaButtonLayout button_layout = {
   {
     META_BUTTON_FUNCTION_MENU,
@@ -104,6 +107,7 @@
 static gboolean update_action_double_click_titlebar (const char *value);
 static gboolean update_auto_raise          (gboolean   value);
 static gboolean update_auto_raise_delay    (int        value);
+static gboolean update_raise_on_click     (gboolean    value);
 static gboolean update_button_layout      (const char *value);
 static gboolean update_window_binding     (const char *name,
                                            const char *value);
@@ -314,7 +318,11 @@
 				  &err);
   cleanup_error (&err);
   update_auto_raise_delay (int_val);
-  
+
+  bool_val = gconf_client_get_bool (default_client, KEY_RAISE_ON_CLICK,
+				    &err);
+  cleanup_error (&err);
+  update_raise_on_click (bool_val);
 
   str_val = gconf_client_get_string (default_client, KEY_THEME,
                                      &err);
@@ -626,6 +634,22 @@
         queue_changed (META_PREF_AUTO_RAISE_DELAY);
     
     }
+  else if (strcmp (key, KEY_RAISE_ON_CLICK) == 0)
+    {
+      gboolean b;
+
+      if (value && value->type != GCONF_VALUE_BOOL)
+        {
+          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
+                        KEY_RAISE_ON_CLICK);
+          goto out;
+        }
+
+      b = value ? gconf_value_get_bool (value) : raise_on_click;
+
+      if (update_raise_on_click (b))
+        queue_changed (META_PREF_RAISE_ON_CLICK);
+    }
   else if (str_has_prefix (key, KEY_COMMAND_PREFIX))
     {
       const char *str;
@@ -1137,6 +1161,16 @@
 
   return old != auto_raise_delay;
 }
+
+static gboolean
+update_raise_on_click (gboolean value)
+{
+  gboolean old = raise_on_click;
+
+  raise_on_click = value;
+
+  return old != raise_on_click;
+}
 #endif /* HAVE_GCONF */
 
 #ifdef WITH_VERBOSE_MODE
@@ -1181,6 +1215,9 @@
     case META_PREF_AUTO_RAISE_DELAY:
       return "AUTO_RAISE_DELAY";
 
+    case META_PREF_RAISE_ON_CLICK:
+      return "RAISE_ON_CLICK";
+
     case META_PREF_COMMANDS:
       return "COMMANDS";
 
@@ -1808,6 +1845,21 @@
 meta_prefs_get_auto_raise_delay ()
 {
   return auto_raise_delay;
+}
+
+/**
+ * meta_prefs_get_raise_on_click:
+ *
+ * Queries the preference that determines whether windows should be raised to
+ * the top of the stack when they get clicked.
+ * 
+ * Return value: TRUE if windows should be raised when the user presses a button
+ * on them, FALSE otherwise.
+ **/
+gboolean
+meta_prefs_get_raise_on_click (void)
+{
+  return raise_on_click;
 }
 
 MetaKeyBindingAction
Index: src/prefs.h
===================================================================
RCS file: /cvs/gnome/metacity/src/prefs.h,v
retrieving revision 1.28
diff -u -r1.28 prefs.h
--- src/prefs.h	15 Jan 2003 02:39:07 -0000	1.28
+++ src/prefs.h	22 Jun 2003 23:16:34 -0000
@@ -42,7 +42,8 @@
   META_PREF_DISABLE_WORKAROUNDS,
   META_PREF_COMMANDS,
   META_PREF_BUTTON_LAYOUT,
-  META_PREF_WORKSPACE_NAMES
+  META_PREF_WORKSPACE_NAMES,
+  META_PREF_RAISE_ON_CLICK
 } MetaPreference;
 
 typedef void (* MetaPrefsChangedFunc) (MetaPreference pref,
@@ -66,6 +67,7 @@
 gboolean                    meta_prefs_get_disable_workarounds (void);
 gboolean                    meta_prefs_get_auto_raise         (void);
 int                         meta_prefs_get_auto_raise_delay   (void);
+gboolean                    meta_prefs_get_raise_on_click     (void);
 
 const char*                 meta_prefs_get_command            (int i);
 


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