mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-27 22:20:24 +00:00
gtkwindowhandle: Refactor click handling a bit
Do not get a GdkEvent first and foremost, and only do that in the parts where the GdkEvent is absolutely necessary (i.e. popping up the WM menu for the window).
This commit is contained in:
parent
fbf4817ef5
commit
3ba3e8286f
@ -256,10 +256,17 @@ do_popup_fallback (GtkWindowHandle *self,
|
||||
|
||||
static void
|
||||
do_popup (GtkWindowHandle *self,
|
||||
GdkEvent *event)
|
||||
GtkGestureClick *gesture)
|
||||
{
|
||||
GdkSurface *surface =
|
||||
gtk_native_get_surface (gtk_widget_get_native (GTK_WIDGET (self)));
|
||||
GdkEventSequence *sequence;
|
||||
GdkEvent *event;
|
||||
|
||||
sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
|
||||
event = gtk_gesture_get_last_event (GTK_GESTURE (gesture), sequence);
|
||||
if (!event)
|
||||
return;
|
||||
|
||||
if (!gdk_toplevel_show_window_menu (GDK_TOPLEVEL (surface), event))
|
||||
do_popup_fallback (self, event);
|
||||
@ -267,7 +274,7 @@ do_popup (GtkWindowHandle *self,
|
||||
|
||||
static gboolean
|
||||
perform_titlebar_action_fallback (GtkWindowHandle *self,
|
||||
GdkEvent *event,
|
||||
GtkGestureClick *click_gesture,
|
||||
GdkTitlebarGesture gesture)
|
||||
{
|
||||
GtkSettings *settings;
|
||||
@ -306,7 +313,7 @@ perform_titlebar_action_fallback (GtkWindowHandle *self,
|
||||
"window.minimize",
|
||||
NULL);
|
||||
else if (g_str_equal (action, "menu"))
|
||||
do_popup (self, event);
|
||||
do_popup (self, click_gesture);
|
||||
else
|
||||
{
|
||||
g_warning ("Unsupported titlebar action %s", action);
|
||||
@ -320,7 +327,7 @@ perform_titlebar_action_fallback (GtkWindowHandle *self,
|
||||
|
||||
static gboolean
|
||||
perform_titlebar_action (GtkWindowHandle *self,
|
||||
GdkEvent *event,
|
||||
GtkGestureClick *click_gesture,
|
||||
guint button,
|
||||
int n_press)
|
||||
{
|
||||
@ -349,7 +356,7 @@ perform_titlebar_action (GtkWindowHandle *self,
|
||||
if (gdk_toplevel_titlebar_gesture (GDK_TOPLEVEL (surface), gesture))
|
||||
return TRUE;
|
||||
|
||||
return perform_titlebar_action_fallback (self, event, gesture);
|
||||
return perform_titlebar_action_fallback (self, click_gesture, gesture);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -360,17 +367,10 @@ click_gesture_pressed_cb (GtkGestureClick *gesture,
|
||||
GtkWindowHandle *self)
|
||||
{
|
||||
GtkWidget *widget;
|
||||
GdkEventSequence *sequence;
|
||||
GdkEvent *event;
|
||||
guint button;
|
||||
|
||||
widget = GTK_WIDGET (self);
|
||||
sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
|
||||
button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture));
|
||||
event = gtk_gesture_get_last_event (GTK_GESTURE (gesture), sequence);
|
||||
|
||||
if (!event)
|
||||
return;
|
||||
|
||||
if (n_press > 1)
|
||||
gtk_gesture_set_state (self->drag_gesture, GTK_EVENT_SEQUENCE_DENIED);
|
||||
@ -387,14 +387,14 @@ click_gesture_pressed_cb (GtkGestureClick *gesture,
|
||||
case GDK_BUTTON_PRIMARY:
|
||||
if (n_press == 2)
|
||||
{
|
||||
perform_titlebar_action (self, event, button, n_press);
|
||||
perform_titlebar_action (self, gesture, button, n_press);
|
||||
gtk_gesture_set_state (GTK_GESTURE (gesture),
|
||||
GTK_EVENT_SEQUENCE_CLAIMED);
|
||||
}
|
||||
break;
|
||||
|
||||
case GDK_BUTTON_SECONDARY:
|
||||
if (perform_titlebar_action (self, event, button, n_press))
|
||||
if (perform_titlebar_action (self, gesture, button, n_press))
|
||||
gtk_gesture_set_state (GTK_GESTURE (gesture),
|
||||
GTK_EVENT_SEQUENCE_CLAIMED);
|
||||
|
||||
@ -403,7 +403,7 @@ click_gesture_pressed_cb (GtkGestureClick *gesture,
|
||||
break;
|
||||
|
||||
case GDK_BUTTON_MIDDLE:
|
||||
if (perform_titlebar_action (self, event, button, n_press))
|
||||
if (perform_titlebar_action (self, gesture, button, n_press))
|
||||
gtk_gesture_set_state (GTK_GESTURE (gesture),
|
||||
GTK_EVENT_SEQUENCE_CLAIMED);
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user