diff options
author | Michael Natterer <mitch@lanedo.com> | 2011-09-27 15:37:28 +0200 |
---|---|---|
committer | Michael Natterer <mitch@gimp.org> | 2011-09-27 15:45:18 +0200 |
commit | 2d3db3421fd8067dd9c59a0727da239936187cc5 (patch) | |
tree | c9668bfba51b4df9dd76b478cc3c1b10e51973cd /gdk/gdkevents.c | |
parent | 27cbbc4a7d8e8f010b5b83f7563b6cc36926c8cb (diff) | |
download | gtk+-2d3db3421fd8067dd9c59a0727da239936187cc5.tar.gz |
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.
Diffstat (limited to 'gdk/gdkevents.c')
-rw-r--r-- | gdk/gdkevents.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c index ae42b4ffa4..eeaac2dccc 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, |