[gtk+/wip/garnacho/window-dragging: 1/2] gtkmenubutton: Popup menu/popover on button release



commit 53414ca11c9405da97b114487f681de60f6f1850
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Feb 25 20:31:09 2015 +0100

    gtkmenubutton: Popup menu/popover on button release
    
    And do it on GtkButton:released, it will behave correctly wrt cancelled
    gestures and broken grabs. Running this on button release allows window
    dragging to take place for menu buttons in headerbars.

 gtk/gtkmenubutton.c |   37 +++++++++++++++++--------------------
 1 files changed, 17 insertions(+), 20 deletions(-)
---
diff --git a/gtk/gtkmenubutton.c b/gtk/gtkmenubutton.c
index de06bf1..9bacf8f 100644
--- a/gtk/gtkmenubutton.c
+++ b/gtk/gtkmenubutton.c
@@ -132,6 +132,7 @@ struct _GtkMenuButtonPrivate
   GtkWidget *arrow_widget;
   GtkArrowType arrow_type;
   gboolean use_popover;
+  guint press_handled : 1;
 };
 
 enum
@@ -433,32 +434,26 @@ gtk_menu_button_toggled (GtkToggleButton *button)
     gtk_widget_set_visible (priv->popover, active);
 }
 
-static gboolean
-gtk_menu_button_button_press_event (GtkWidget      *widget,
-                                    GdkEventButton *event)
+static void
+gtk_menu_button_released (GtkButton *button)
 {
-  GtkMenuButton *menu_button = GTK_MENU_BUTTON (widget);
+  GtkMenuButton *menu_button = GTK_MENU_BUTTON (button);
   GtkMenuButtonPrivate *priv = menu_button->priv;
 
-  if (event->button == GDK_BUTTON_PRIMARY)
+  if (priv->menu && !gtk_widget_get_visible (priv->menu))
     {
-      /* Filter out double/triple clicks */
-      if (event->type != GDK_BUTTON_PRESS)
-        return TRUE;
-
-      if (priv->menu && !gtk_widget_get_visible (priv->menu))
-        popup_menu (menu_button, event);
-      else if (priv->popover && !gtk_widget_get_visible (priv->popover))
-        gtk_widget_show (priv->popover);
-      else
-        return TRUE;
+      GdkEvent *event;
 
-      gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
-
-      return TRUE;
+      event = gtk_get_current_event ();
+      popup_menu (menu_button, &event->button);
+      gdk_event_free (event);
     }
+  else if (priv->popover && !gtk_widget_get_visible (priv->popover))
+    gtk_widget_show (priv->popover);
+
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
 
-  return GTK_WIDGET_CLASS (gtk_menu_button_parent_class)->button_press_event (widget, event);
+  GTK_BUTTON_CLASS (gtk_menu_button_parent_class)->released (button);
 }
 
 static void
@@ -491,6 +486,7 @@ gtk_menu_button_class_init (GtkMenuButtonClass *klass)
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
   GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
+  GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
   GtkToggleButtonClass *toggle_button_class = GTK_TOGGLE_BUTTON_CLASS (klass);
 
   gobject_class->set_property = gtk_menu_button_set_property;
@@ -498,11 +494,12 @@ gtk_menu_button_class_init (GtkMenuButtonClass *klass)
   gobject_class->dispose = gtk_menu_button_dispose;
 
   widget_class->state_flags_changed = gtk_menu_button_state_flags_changed;
-  widget_class->button_press_event = gtk_menu_button_button_press_event;
 
   container_class->add = gtk_menu_button_add;
   container_class->remove = gtk_menu_button_remove;
 
+  button_class->released = gtk_menu_button_released;
+
   toggle_button_class->toggled = gtk_menu_button_toggled;
 
   /**


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