[gnome-panel] panel: Show panel context menu only if mouse button modifier is pressed



commit 4654237e4b2b925e2138e6c9f76f0861896b8f52
Author: Vincent Untz <vuntz gnome org>
Date:   Tue Feb 22 20:15:37 2011 +0100

    panel: Show panel context menu only if mouse button modifier is pressed
    
    In the same way we only allow moving the panel when a mouse button
    modifier is used (like in metacity), we only display context menu of the
    panel (which are used to edit it) when the modifier is pressed.
    
    The default setting is Alt.

 gnome-panel/gnome-desktop-item-edit.c |    2 +
 gnome-panel/panel-util.c              |   44 +++++++++++++++++++++++++++-----
 gnome-panel/panel-util.h              |    4 +++
 gnome-panel/panel.c                   |   45 ++++++++++++++++-----------------
 4 files changed, 65 insertions(+), 30 deletions(-)
---
diff --git a/gnome-panel/gnome-desktop-item-edit.c b/gnome-panel/gnome-desktop-item-edit.c
index f37f87d..8fd53a9 100644
--- a/gnome-panel/gnome-desktop-item-edit.c
+++ b/gnome-panel/gnome-desktop-item-edit.c
@@ -22,6 +22,8 @@ gboolean panel_global_config_get_tooltips_enabled (void) { return FALSE; }
 gboolean panel_lockdown_get_disable_lock_screen (void) { return FALSE; }
 #include "panel-bindings.h"
 guint panel_bindings_get_mouse_button_modifier_keymask (void) { return 0; }
+#include "panel-toplevel.h"
+GType panel_toplevel_get_type (void) { return 0; }
 
 static int dialogs = 0;
 static gboolean create_new = FALSE;
diff --git a/gnome-panel/panel-util.c b/gnome-panel/panel-util.c
index f768c81..5ad11dd 100644
--- a/gnome-panel/panel-util.c
+++ b/gnome-panel/panel-util.c
@@ -1225,17 +1225,26 @@ panel_util_get_file_optional_homedir (const char *location)
 	return file;
 }
 
-void
-panel_util_key_event_is_popup (GdkEventKey *event,
-			       gboolean    *is_popup,
-			       gboolean    *is_popup_modifier)
+static void
+panel_util_key_event_is_binding (GdkEventKey *event,
+				 GType        type,
+				 const char  *signal_name,
+				 gboolean    *is_popup,
+				 gboolean    *is_popup_modifier)
 {
 	GtkBindingSet   *binding_set;
 	GtkBindingEntry *binding_entry;
 	gboolean         popup = FALSE;
 	gboolean         popup_modifier = FALSE;
+	char            *signal_dash;
+	char            *signal_underscore;
+
+	signal_dash = g_strdup (signal_name);
+	g_strdelimit (signal_dash, "_", '-');
+	signal_underscore = g_strdup (signal_name);
+	g_strdelimit (signal_underscore, "-", '_');
 
-	binding_set = gtk_binding_set_by_class (g_type_class_peek (GTK_TYPE_WIDGET));
+	binding_set = gtk_binding_set_by_class (g_type_class_peek (type));
 
 	for (binding_entry = binding_set->entries;
 	     binding_entry != NULL;
@@ -1245,8 +1254,8 @@ panel_util_key_event_is_popup (GdkEventKey *event,
 		for (binding_signal = binding_entry->signals;
 		     binding_signal != NULL;
 		     binding_signal = binding_signal->next) {
-			if (g_strcmp0 (binding_signal->signal_name, "popup-menu") == 0 ||
-			    g_strcmp0 (binding_signal->signal_name, "popup_menu") == 0) {
+			if (g_strcmp0 (binding_signal->signal_name, signal_dash) == 0 ||
+			    g_strcmp0 (binding_signal->signal_name, signal_underscore) == 0) {
 				if (binding_entry->keyval != event->keyval)
 					break;
 
@@ -1264,4 +1273,25 @@ panel_util_key_event_is_popup (GdkEventKey *event,
 		*is_popup = popup;
 	if (is_popup_modifier)
 		*is_popup_modifier = popup_modifier;
+
+	g_free (signal_dash);
+	g_free (signal_underscore);
+}
+
+void
+panel_util_key_event_is_popup (GdkEventKey *event,
+			       gboolean    *is_popup,
+			       gboolean    *is_popup_modifier)
+{
+	panel_util_key_event_is_binding (event, GTK_TYPE_WIDGET, "popup-menu",
+					 is_popup, is_popup_modifier);
+}
+
+void
+panel_util_key_event_is_popup_panel (GdkEventKey *event,
+				     gboolean    *is_popup,
+				     gboolean    *is_popup_modifier)
+{
+	panel_util_key_event_is_binding (event, PANEL_TYPE_TOPLEVEL, "popup-panel-menu",
+					 is_popup, is_popup_modifier);
 }
diff --git a/gnome-panel/panel-util.h b/gnome-panel/panel-util.h
index 6d5baa8..55409aa 100644
--- a/gnome-panel/panel-util.h
+++ b/gnome-panel/panel-util.h
@@ -67,6 +67,10 @@ void panel_util_key_event_is_popup (GdkEventKey *event,
 				    gboolean    *is_popup,
 				    gboolean    *is_popup_modifier);
 
+void panel_util_key_event_is_popup_panel (GdkEventKey *event,
+					  gboolean    *is_popup,
+					  gboolean    *is_popup_modifier);
+
 G_END_DECLS
 
 #endif /* PANEL_UTIL_H */
diff --git a/gnome-panel/panel.c b/gnome-panel/panel.c
index e6705a6..f8c0f79 100644
--- a/gnome-panel/panel.c
+++ b/gnome-panel/panel.c
@@ -28,6 +28,7 @@
 #include "drawer.h"
 #include "button-widget.h"
 #include "launcher.h"
+#include "panel-bindings.h"
 #include "panel-context-menu.h"
 #include "panel-util.h"
 #include "panel-config-global.h"
@@ -371,37 +372,37 @@ panel_popup_menu (PanelToplevel *toplevel,
 }
 
 static gboolean
-panel_popup_menu_signal (PanelToplevel *toplevel)
-{
-	return panel_popup_menu (toplevel, 3, GDK_CURRENT_TIME);
-}
-
-static gboolean
 panel_button_press_event (PanelToplevel  *toplevel,
 			  GdkEventButton *event)
 {
+	guint modifiers;
+
 	if (event->button != 3)
 		return FALSE;
 
-	return panel_popup_menu (toplevel, event->button, event->time);
+	modifiers = event->state & GDK_MODIFIER_MASK;
+
+	if (modifiers == panel_bindings_get_mouse_button_modifier_keymask ())
+		return panel_popup_menu (toplevel, event->button, event->time);
+
+	return FALSE;
 }
 
 static gboolean
-panel_key_press_event (GtkWidget   *widget,
-		       GdkEventKey *event)
+panel_key_press_event (PanelToplevel *toplevel,
+		       GdkEventKey   *event)
 {
-	/*
-  	 * If the focus widget is a GtkSocket, i.e. the
-	 * focus is in an applet in another process, then key 
-	 * bindings do not work. We get around this by
-	 * activating the key bindings here.
-	 */ 
-	if (GTK_IS_SOCKET (gtk_window_get_focus (GTK_WINDOW (widget))) &&
-	    event->keyval == GDK_KEY_F10 &&
-	    (event->state & gtk_accelerator_get_default_mod_mask ()) == GDK_CONTROL_MASK)
-		return gtk_bindings_activate (G_OBJECT (widget),
-					      event->keyval,
-					      event->state);
+	gboolean is_popup = FALSE;
+
+	/* We're not connecting to the popup-menu signal since we want to be
+	 * able to handle keybinding of popup-menu + modifier from metacity */
+
+	panel_util_key_event_is_popup (event, NULL, &is_popup);
+	if (!is_popup)
+		panel_util_key_event_is_popup_panel (event, &is_popup, NULL);
+
+	if (is_popup)
+		return panel_popup_menu (toplevel, 3, event->time);
 
 	return FALSE;
 }
@@ -1293,8 +1294,6 @@ panel_setup (PanelToplevel *toplevel)
 			  G_CALLBACK (panel_key_press_event), NULL);
 	g_signal_connect (toplevel, "button-press-event",
 			  G_CALLBACK (panel_button_press_event), NULL);
-	g_signal_connect (toplevel, "popup-menu",
-			  G_CALLBACK (panel_popup_menu_signal), NULL);
 
 	g_signal_connect_swapped (toplevel, "notify::orientation",
 				  G_CALLBACK (panel_orient_change), panel_widget);



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