[gtk+] Bug 659406 - Abstract what triggers a context menu
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Bug 659406 - Abstract what triggers a context menu
- Date: Tue, 27 Sep 2011 13:46:55 +0000 (UTC)
commit 2d3db3421fd8067dd9c59a0727da239936187cc5
Author: Michael Natterer <mitch lanedo com>
Date: Tue Sep 27 15:37:28 2011 +0200
Bug 659406 - Abstract what triggers a context menu
Add gdk_event_triggers_context_menu(), using the new modifier
abstraction API. Remove _gtk_button_event_triggers_context_menu()
and port all callers.
gdk/gdkevents.c | 50 +++++++++++++++++++++++++++++++++++++++++
gdk/gdkevents.h | 3 +-
gtk/gtkcolorsel.c | 2 +-
gtk/gtkentry.c | 2 +-
gtk/gtkfilechooserdefault.c | 4 +-
gtk/gtklabel.c | 4 +-
gtk/gtklinkbutton.c | 4 +-
gtk/gtkmain.c | 20 ----------------
gtk/gtkmountoperation.c | 2 +-
gtk/gtknotebook.c | 2 +-
gtk/gtkprivate.h | 2 -
gtk/gtkrecentchooserdefault.c | 4 +--
gtk/gtkstatusicon.c | 2 +-
gtk/gtktextview.c | 2 +-
gtk/gtktoolbar.c | 2 +-
15 files changed, 66 insertions(+), 39 deletions(-)
---
diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c
index ae42b4f..eeaac2d 100644
--- a/gdk/gdkevents.c
+++ b/gdk/gdkevents.c
@@ -1448,6 +1448,56 @@ gdk_event_request_motions (const GdkEventMotion *event)
}
}
+/**
+ * gdk_event_triggers_context_menu:
+ * @event: a #GdkEvent, currently only button events are meaningful values
+ *
+ * This function returns whether a #GdkEventButton should trigger a
+ * context menu, according to platform conventions. The right mouse
+ * button always triggers context menus. Additionally, if
+ * gdk_keymap_get_modifier_mask() returns a non-0 mask for
+ * %GDK_MODIFIER_INTENT_CONTEXT_MENU, then the left mouse button will
+ * also trigger a context menu if this modifier is pressed.
+ *
+ * This function should always be used instead of simply checking for
+ * event->button == 3.
+ *
+ * Returns: %TRUE if the event should trigger a context menu.
+ *
+ * Since: 3.4
+ **/
+gboolean
+gdk_event_triggers_context_menu (const GdkEvent *event)
+{
+ g_return_val_if_fail (event != NULL, FALSE);
+
+ if (event->type == GDK_BUTTON_PRESS)
+ {
+ const GdkEventButton *bevent = (const GdkEventButton *) event;
+ GdkDisplay *display;
+ GdkModifierType modifier;
+
+ g_return_val_if_fail (GDK_IS_WINDOW (bevent->window), FALSE);
+
+ if (bevent->button == 3 &&
+ ! (bevent->state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK)))
+ return TRUE;
+
+ display = gdk_window_get_display (bevent->window);
+
+ modifier = gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
+ GDK_MODIFIER_INTENT_CONTEXT_MENU);
+
+ if (modifier != 0 &&
+ bevent->button == 1 &&
+ ! (bevent->state & (GDK_BUTTON2_MASK | GDK_BUTTON3_MASK)) &&
+ (bevent->state & modifier))
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
static gboolean
gdk_events_get_axis_distances (GdkEvent *event1,
GdkEvent *event2,
diff --git a/gdk/gdkevents.h b/gdk/gdkevents.h
index 8bf7d56..24a3b8e 100644
--- a/gdk/gdkevents.h
+++ b/gdk/gdkevents.h
@@ -1076,7 +1076,8 @@ GdkDevice* gdk_event_get_device (const GdkEvent *event);
void gdk_event_set_source_device (GdkEvent *event,
GdkDevice *device);
GdkDevice* gdk_event_get_source_device (const GdkEvent *event);
-void gdk_event_request_motions (const GdkEventMotion *event);
+void gdk_event_request_motions (const GdkEventMotion *event);
+gboolean gdk_event_triggers_context_menu (const GdkEvent *event);
gboolean gdk_events_get_distance (GdkEvent *event1,
GdkEvent *event2,
diff --git a/gtk/gtkcolorsel.c b/gtk/gtkcolorsel.c
index 3b8f048..d660672 100644
--- a/gtk/gtkcolorsel.c
+++ b/gtk/gtkcolorsel.c
@@ -1505,7 +1505,7 @@ palette_press (GtkWidget *drawing_area,
gtk_widget_grab_focus (drawing_area);
- if (_gtk_button_event_triggers_context_menu (event))
+ if (gdk_event_triggers_context_menu ((GdkEvent *) event))
{
do_popup (colorsel, drawing_area, event->time);
return TRUE;
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index c22cb0e..1806464 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -3774,7 +3774,7 @@ gtk_entry_button_press (GtkWidget *widget,
tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
- if (_gtk_button_event_triggers_context_menu (event))
+ if (gdk_event_triggers_context_menu ((GdkEvent *) event))
{
gtk_entry_do_popup (entry, event);
priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index 8c3db4c..896b878 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -3448,7 +3448,7 @@ shortcuts_button_press_event_cb (GtkWidget *widget,
if (in_press)
return FALSE;
- if (!_gtk_button_event_triggers_context_menu (event))
+ if (!gdk_event_triggers_context_menu ((GdkEvent *) event))
return FALSE;
in_press = TRUE;
@@ -4300,7 +4300,7 @@ list_button_press_event_cb (GtkWidget *widget,
if (in_press)
return FALSE;
- if (!_gtk_button_event_triggers_context_menu (event))
+ if (!gdk_event_triggers_context_menu ((GdkEvent *) event))
return FALSE;
in_press = TRUE;
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 00422a5..3546749 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -4715,7 +4715,7 @@ gtk_label_button_press (GtkWidget *widget,
if (info->active_link)
{
- if (_gtk_button_event_triggers_context_menu (event))
+ if (gdk_event_triggers_context_menu ((GdkEvent *) event))
{
info->link_clicked = 1;
gtk_label_do_popup (label, event);
@@ -4734,7 +4734,7 @@ gtk_label_button_press (GtkWidget *widget,
info->in_drag = FALSE;
info->select_words = FALSE;
- if (_gtk_button_event_triggers_context_menu (event))
+ if (gdk_event_triggers_context_menu ((GdkEvent *) event))
{
gtk_label_do_popup (label, event);
diff --git a/gtk/gtklinkbutton.c b/gtk/gtklinkbutton.c
index 0fdcbea..ffa89c0 100644
--- a/gtk/gtklinkbutton.c
+++ b/gtk/gtklinkbutton.c
@@ -522,10 +522,10 @@ gtk_link_button_button_press (GtkWidget *widget,
if (!gtk_widget_has_focus (widget))
gtk_widget_grab_focus (widget);
- if (_gtk_button_event_triggers_context_menu (event))
+ if (gdk_event_triggers_context_menu ((GdkEvent *) event))
{
gtk_link_button_do_popup (GTK_LINK_BUTTON (widget), event);
-
+
return TRUE;
}
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c
index e42f730..a0ca89d 100644
--- a/gtk/gtkmain.c
+++ b/gtk/gtkmain.c
@@ -2643,23 +2643,3 @@ _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
return continue_emission;
}
-
-gboolean
-_gtk_button_event_triggers_context_menu (GdkEventButton *event)
-{
- if (event->type == GDK_BUTTON_PRESS)
- {
- if (event->button == 3 &&
- ! (event->state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK)))
- return TRUE;
-
-#ifdef GDK_WINDOWING_QUARTZ
- if (event->button == 1 &&
- ! (event->state & (GDK_BUTTON2_MASK | GDK_BUTTON3_MASK)) &&
- (event->state & GDK_CONTROL_MASK))
- return TRUE;
-#endif
- }
-
- return FALSE;
-}
diff --git a/gtk/gtkmountoperation.c b/gtk/gtkmountoperation.c
index dea21f5..c1ad3da 100644
--- a/gtk/gtkmountoperation.c
+++ b/gtk/gtkmountoperation.c
@@ -1167,7 +1167,7 @@ on_button_press_event_for_process_tree_view (GtkWidget *widget,
ret = FALSE;
- if (_gtk_button_event_triggers_context_menu (event))
+ if (gtk_button_event_triggers_context_menu (event))
{
ret = do_popup_menu_for_process_tree_view (widget, event, op);
}
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index afc51d3..8ea2c6c 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -2858,7 +2858,7 @@ gtk_notebook_button_press (GtkWidget *widget,
if (arrow)
return gtk_notebook_arrow_button_press (notebook, arrow, event->button);
- if (priv->menu && _gtk_button_event_triggers_context_menu (event))
+ if (priv->menu && gdk_event_triggers_context_menu ((GdkEvent *) event))
{
gtk_menu_popup (GTK_MENU (priv->menu), NULL, NULL,
NULL, NULL, 3, event->time);
diff --git a/gtk/gtkprivate.h b/gtk/gtkprivate.h
index 0def8c1..458a4b9 100644
--- a/gtk/gtkprivate.h
+++ b/gtk/gtkprivate.h
@@ -83,8 +83,6 @@ void _gtk_modules_init (gint *argc,
void _gtk_modules_settings_changed (GtkSettings *settings,
const gchar *modules);
-gboolean _gtk_button_event_triggers_context_menu (GdkEventButton *event);
-
G_END_DECLS
#endif /* __GTK_PRIVATE_H__ */
diff --git a/gtk/gtkrecentchooserdefault.c b/gtk/gtkrecentchooserdefault.c
index 7adc1ae..160b37f 100644
--- a/gtk/gtkrecentchooserdefault.c
+++ b/gtk/gtkrecentchooserdefault.c
@@ -74,8 +74,6 @@
#include "gtkrecentchooserutils.h"
#include "gtkrecentchooserdefault.h"
-#include "gtkprivate.h"
-
enum
{
@@ -1905,7 +1903,7 @@ recent_view_button_press_cb (GtkWidget *widget,
{
GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
- if (_gtk_button_event_triggers_context_menu (event))
+ if (gdk_event_triggers_context_menu ((GdkEvent *) event))
{
GtkTreePath *path;
gboolean res;
diff --git a/gtk/gtkstatusicon.c b/gtk/gtkstatusicon.c
index 27a2b14..4f4dfb8 100644
--- a/gtk/gtkstatusicon.c
+++ b/gtk/gtkstatusicon.c
@@ -1810,7 +1810,7 @@ gtk_status_icon_button_press (GtkStatusIcon *status_icon,
if (handled)
return TRUE;
- if (_gtk_button_event_triggers_context_menu (event))
+ if (gdk_event_triggers_context_menu ((GdkEvent *) event))
{
emit_popup_menu_signal (status_icon, event->button, event->time);
return TRUE;
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index e128c3a..a2e5020 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -4545,7 +4545,7 @@ gtk_text_view_button_press_event (GtkWidget *widget, GdkEventButton *event)
{
gtk_text_view_reset_im_context (text_view);
- if (_gtk_button_event_triggers_context_menu (event))
+ if (gdk_event_triggers_context_menu ((GdkEvent *) event))
{
gtk_text_view_do_popup (text_view, event);
return TRUE;
diff --git a/gtk/gtktoolbar.c b/gtk/gtktoolbar.c
index dd3d05e..ba6ccb5 100644
--- a/gtk/gtktoolbar.c
+++ b/gtk/gtktoolbar.c
@@ -2748,7 +2748,7 @@ gtk_toolbar_button_press (GtkWidget *toolbar,
{
GtkWidget *window;
- if (_gtk_button_event_triggers_context_menu (event))
+ if (gdk_event_triggers_context_menu ((GdkEvent *) event))
{
gboolean return_value;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]