? stamp-h1
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/metacity/ChangeLog,v
retrieving revision 1.821.2.2
diff -u -r1.821.2.2 ChangeLog
--- ChangeLog	24 Jun 2004 20:47:53 -0000	1.821.2.2
+++ ChangeLog	24 Aug 2004 00:54:09 -0000
@@ -1,3 +1,29 @@
+2004-08-23  Federico Mena Quintero  <federico@ximian.com>
+
+	* src/metacity.schemas.in: New schema for
+	"/apps/metacity/general/enable_windows_keys"
+
+	* src/prefs.h (MetaPreference): Add a
+	META_PREF_ENABLE_WINDOWS_KEYS value.
+	Add prototype for meta_prefs_get_enable_windows_keys().
+
+	* src/prefs.c (KEY_ENABLE_WINDOWS_KEYS): New macro, set to
+	"/apps/metacity/general/enable_windows_keys"
+	(enable_windows_keys): New pref variable.
+	(meta_prefs_init): Read the gconf settings for
+	enable_windows_keys.
+	(change_notify): Pick up changes to the enable_windows_keys value.
+	(update_enable_windows_keys): New function.
+	(meta_preference_to_string): Add case for META_PREF_ENABLE_WINDOWS_KEYS.
+	(meta_prefs_get_enable_windows_keys): New function.
+
+	* src/keybindings.c (meta_screen_grab_windows_keys): New function.
+	(meta_screen_grab_keys): Call meta_screen_grab_windows_keys().
+	(handle_panel_keybinding): Use handle_panel_action().
+	(handle_panel_action): New function; code moved over from
+	handle_panel_keybinding().
+	(meta_display_process_key_event): Handle the Windows flag keys.
+
 2004-06-24  Elijah Newren  <newren@math.utah.edu>
 
 	* src/keybindings.c: (handle_toggle_desktop): Choose correct
Index: src/keybindings.c
===================================================================
RCS file: /cvs/gnome/metacity/src/keybindings.c,v
retrieving revision 1.97.2.1
diff -u -r1.97.2.1 keybindings.c
--- src/keybindings.c	24 Jun 2004 20:47:53 -0000	1.97.2.1
+++ src/keybindings.c	24 Aug 2004 00:54:09 -0000
@@ -185,6 +185,12 @@
                                        XEvent         *event,
                                        MetaKeyBinding *binding);
 
+static void handle_panel_action (MetaDisplay         *display,
+				 MetaScreen          *screen,
+				 MetaWindow          *window,
+				 XEvent              *event,
+				 MetaKeyBindingAction action);
+
 /* debug */
 static void handle_spew_mark          (MetaDisplay *display,
                                        MetaScreen  *screen,
@@ -1065,6 +1071,21 @@
     meta_error_trap_pop (display, FALSE);
 }
 
+/* Hardcoded keycodes for the Windows flag keys */
+#define WINDOWS_KEY_1_KEYCODE 115
+#define WINDOWS_KEY_2_KEYCODE 116
+
+static void
+meta_screen_grab_windows_keys (MetaScreen *screen)
+{
+  meta_error_trap_push (screen->display);
+
+  meta_grab_key (screen->display, screen->xroot, 0, WINDOWS_KEY_1_KEYCODE, 0);
+  meta_grab_key (screen->display, screen->xroot, 0, WINDOWS_KEY_2_KEYCODE, 0);
+
+  meta_error_trap_pop (screen->display, FALSE);
+}
+
 void
 meta_screen_grab_keys (MetaScreen *screen)
 {
@@ -1074,6 +1095,8 @@
   if (screen->keys_grabbed)
     return;
 
+  meta_screen_grab_windows_keys (screen);
+
   grab_keys (screen->display->screen_bindings,
              screen->display->n_screen_bindings,
              screen->display, screen->xroot);
@@ -1589,6 +1612,13 @@
   all_keys_grabbed = window ? window->all_keys_grabbed : screen->all_keys_grabbed;
   if (!all_keys_grabbed)
     {
+      if (event->type == KeyPress
+	  && meta_prefs_get_enable_windows_keys ()
+	  && (event->xkey.state & ~display->ignored_modifier_mask) == 0
+	  && (event->xkey.keycode == WINDOWS_KEY_1_KEYCODE
+	      || event->xkey.keycode == WINDOWS_KEY_2_KEYCODE))
+	handle_panel_action (display, screen, NULL, event, META_KEYBINDING_ACTION_PANEL_MAIN_MENU);
+
       /* Do the normal keybindings */
       process_event (display->screen_bindings,
                      display->n_screen_bindings,
@@ -2763,18 +2793,15 @@
 }
 
 static void
-handle_panel_keybinding (MetaDisplay    *display,
-                         MetaScreen     *screen,
-                         MetaWindow     *window,
-                         XEvent         *event,
-                         MetaKeyBinding *binding)
+handle_panel_action (MetaDisplay         *display,
+		     MetaScreen          *screen,
+		     MetaWindow          *window,
+		     XEvent              *event,
+		     MetaKeyBindingAction action)
 {
-  MetaKeyBindingAction action;
   Atom action_atom;
   XClientMessageEvent ev;
   
-  action = GPOINTER_TO_INT (binding->handler->data);
-
   action_atom = None;
   switch (action)
     {
@@ -2810,6 +2837,19 @@
 	      (XEvent*) &ev);
 
   meta_error_trap_pop (display, FALSE);
+}
+
+static void
+handle_panel_keybinding (MetaDisplay    *display,
+                         MetaScreen     *screen,
+                         MetaWindow     *window,
+                         XEvent         *event,
+                         MetaKeyBinding *binding)
+{
+  MetaKeyBindingAction action;
+
+  action = GPOINTER_TO_INT (binding->handler->data);
+  handle_panel_action (display, screen, window, event, action);
 }
 
 static void
Index: src/metacity.schemas.in
===================================================================
RCS file: /cvs/gnome/metacity/src/metacity.schemas.in,v
retrieving revision 1.35
diff -u -r1.35 metacity.schemas.in
--- src/metacity.schemas.in	4 Jun 2004 13:55:10 -0000	1.35
+++ src/metacity.schemas.in	24 Aug 2004 00:54:10 -0000
@@ -276,6 +276,22 @@
       </locale>
     </schema>
 
+
+    <schema>
+      <key>/schemas/apps/metacity/general/enable_windows_keys</key>
+      <applyto>/apps/metacity/general/enable_windows_keys</applyto>
+      <owner>metacity</owner>
+      <type>bool</type>
+      <default>true</default>
+      <locale name="C">
+         <short>If true, enables the Windows flag keys to show the panel's main menu</short>
+         <long>
+	   If true, then pressing the Windows flag keys will cause the panel's main
+	   menu to appear.
+         </long>
+      </locale>
+    </schema>
+
     <!-- Window Keybindings -->
 
     <schema>
Index: src/prefs.c
===================================================================
RCS file: /cvs/gnome/metacity/src/prefs.c,v
retrieving revision 1.46
diff -u -r1.46 prefs.c
--- src/prefs.c	30 Apr 2004 00:26:48 -0000	1.46
+++ src/prefs.c	24 Aug 2004 00:54:10 -0000
@@ -52,6 +52,7 @@
 #define KEY_DISABLE_WORKAROUNDS "/apps/metacity/general/disable_workarounds"
 #define KEY_BUTTON_LAYOUT "/apps/metacity/general/button_layout"
 #define KEY_REDUCED_RESOURCES "/apps/metacity/general/reduced_resources"
+#define KEY_ENABLE_WINDOWS_KEYS "/apps/metacity/general/enable_windows_keys"
 
 #define KEY_COMMAND_PREFIX "/apps/metacity/keybinding_commands/command_"
 #define KEY_SCREEN_BINDINGS_PREFIX "/apps/metacity/global_keybindings"
@@ -85,6 +86,7 @@
 static gboolean provide_visual_bell = TRUE;
 static gboolean bell_is_audible = TRUE;
 static gboolean reduced_resources = FALSE;
+static gboolean enable_windows_keys = TRUE;
 
 static MetaVisualBellType visual_bell_type = META_VISUAL_BELL_INVALID;
 static MetaButtonLayout button_layout = {
@@ -133,6 +135,7 @@
 static gboolean update_workspace_name     (const char  *name,
                                            const char  *value);
 static gboolean update_reduced_resources  (gboolean     value);
+static gboolean update_enable_windows_keys (gboolean    value);
 
 static void change_notify (GConfClient    *client,
                            guint           cnxn_id,
@@ -395,6 +398,11 @@
 				    &err);
   cleanup_error (&err);
   update_reduced_resources (bool_val);
+
+  bool_val = gconf_client_get_bool (default_client, KEY_ENABLE_WINDOWS_KEYS,
+				    &err);
+  cleanup_error (&err);
+  update_enable_windows_keys (bool_val);
 #endif /* HAVE_GCONF */
   
   /* Load keybindings prefs */
@@ -772,6 +780,22 @@
       if (update_reduced_resources (b))
         queue_changed (META_PREF_REDUCED_RESOURCES);
     }
+  else if (strcmp (key, KEY_ENABLE_WINDOWS_KEYS) == 0)
+    {
+      gboolean b;
+
+      if (value && value->type != GCONF_VALUE_BOOL)
+	{
+          meta_warning (_("GConf key \"%s\" is set to an invalid type\n"),
+                        KEY_ENABLE_WINDOWS_KEYS);
+          goto out;
+	}
+
+      b = value ? gconf_value_get_bool (value) : enable_windows_keys;
+
+      if (update_enable_windows_keys (b))
+        queue_changed (META_PREF_ENABLE_WINDOWS_KEYS);
+    }
   else
     {
       meta_topic (META_DEBUG_PREFS, "Key %s doesn't mean anything to Metacity\n",
@@ -1288,6 +1312,16 @@
 
   return old != reduced_resources;
 }
+
+static gboolean
+update_enable_windows_keys (gboolean value)
+{
+  gboolean old = enable_windows_keys;
+
+  enable_windows_keys = value;
+
+  return old != enable_windows_keys;
+}
 #endif /* HAVE_GCONF */
 
 #ifdef WITH_VERBOSE_MODE
@@ -1358,6 +1392,10 @@
     case META_PREF_REDUCED_RESOURCES:
       return "REDUCED_RESOURCES";
       break;
+
+    case META_PREF_ENABLE_WINDOWS_KEYS:
+      return "ENABLE_WINDOWS_KEYS";
+      break;
     }
 
   return "(unknown)";
@@ -2031,6 +2069,12 @@
 meta_prefs_get_reduced_resources ()
 {
   return reduced_resources;
+}
+
+gboolean
+meta_prefs_get_enable_windows_keys (void)
+{
+  return enable_windows_keys;
 }
 
 MetaKeyBindingAction
Index: src/prefs.h
===================================================================
RCS file: /cvs/gnome/metacity/src/prefs.h,v
retrieving revision 1.34
diff -u -r1.34 prefs.h
--- src/prefs.h	19 Feb 2004 18:36:14 -0000	1.34
+++ src/prefs.h	24 Aug 2004 00:54:10 -0000
@@ -46,7 +46,8 @@
   META_PREF_VISUAL_BELL,
   META_PREF_AUDIBLE_BELL,
   META_PREF_VISUAL_BELL_TYPE,
-  META_PREF_REDUCED_RESOURCES
+  META_PREF_REDUCED_RESOURCES,
+  META_PREF_ENABLE_WINDOWS_KEYS
 } MetaPreference;
 
 typedef void (* MetaPrefsChangedFunc) (MetaPreference pref,
@@ -71,6 +72,7 @@
 gboolean                    meta_prefs_get_auto_raise         (void);
 int                         meta_prefs_get_auto_raise_delay   (void);
 gboolean                    meta_prefs_get_reduced_resources  (void);
+gboolean                    meta_prefs_get_enable_windows_keys (void);
 
 const char*                 meta_prefs_get_command            (int i);
 
