[gtk+] menushell/toolbar/window: implement toggle maximize on double click



commit be5b6460e77b992b3d9411838b0adb4f9ee1d933
Author: Lionel Landwerlin <llandwerlin gmail com>
Date:   Wed May 15 22:18:05 2013 +0100

    menushell/toolbar/window: implement toggle maximize on double click
    
    https://bugzilla.gnome.org/show_bug.cgi?id=700419

 gtk/gtkmenushell.c     |   21 +++++--------------
 gtk/gtktoolbar.c       |   32 ++---------------------------
 gtk/gtkwidget.c        |    2 +-
 gtk/gtkwindow.c        |   51 ++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkwindowprivate.h |    3 ++
 5 files changed, 64 insertions(+), 45 deletions(-)
---
diff --git a/gtk/gtkmenushell.c b/gtk/gtkmenushell.c
index 3d3bc5e..97efed3 100644
--- a/gtk/gtkmenushell.c
+++ b/gtk/gtkmenushell.c
@@ -70,6 +70,7 @@
 #include "gtkmenushellprivate.h"
 #include "gtkmnemonichash.h"
 #include "gtkwindow.h"
+#include "gtkwindowprivate.h"
 #include "gtkprivate.h"
 #include "gtkmain.h"
 #include "gtkintl.h"
@@ -646,6 +647,9 @@ gtk_menu_shell_button_press (GtkWidget      *widget,
   GtkWidget *menu_item;
   GtkWidget *parent;
 
+  if (event->type == GDK_2BUTTON_PRESS)
+    return _gtk_window_handle_button_press_for_widget (widget, event);
+
   if (event->type != GDK_BUTTON_PRESS)
     return FALSE;
 
@@ -701,21 +705,8 @@ gtk_menu_shell_button_press (GtkWidget      *widget,
         {
           if (!initially_active)
             {
-              gboolean window_drag = FALSE;
-
-              gtk_widget_style_get (widget,
-                                    "window-dragging", &window_drag,
-                                    NULL);
-
-              if (window_drag)
-                {
-                  gtk_menu_shell_deactivate (menu_shell);
-                  gtk_window_begin_move_drag (GTK_WINDOW (gtk_widget_get_toplevel (widget)),
-                                              event->button,
-                                              event->x_root,
-                                              event->y_root,
-                                              event->time);
-                }
+              if (_gtk_window_handle_button_press_for_widget (widget, event))
+                gtk_menu_shell_deactivate (menu_shell);
             }
         }
     }
diff --git a/gtk/gtktoolbar.c b/gtk/gtktoolbar.c
index 2397985..d325a1a 100644
--- a/gtk/gtktoolbar.c
+++ b/gtk/gtktoolbar.c
@@ -56,6 +56,7 @@
 #include "gtktypebuiltins.h"
 #include "gtkwidgetpath.h"
 #include "gtkwidgetprivate.h"
+#include "gtkwindowprivate.h"
 
 
 /**
@@ -2672,7 +2673,7 @@ gtk_toolbar_arrow_button_press (GtkWidget      *button,
 {
   show_menu (toolbar, event);
   gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
-  
+
   return TRUE;
 }
 
@@ -2680,8 +2681,6 @@ static gboolean
 gtk_toolbar_button_press (GtkWidget      *toolbar,
                          GdkEventButton *event)
 {
-  GtkWidget *window;
-
   if (gdk_event_triggers_context_menu ((GdkEvent *) event))
     {
       gboolean return_value;
@@ -2693,32 +2692,7 @@ gtk_toolbar_button_press (GtkWidget      *toolbar,
       return return_value;
     }
 
-  if (event->type != GDK_BUTTON_PRESS)
-    return FALSE;
-
-  window = gtk_widget_get_toplevel (toolbar);
-
-  if (window)
-    {
-      gboolean window_drag = FALSE;
-
-      gtk_widget_style_get (toolbar,
-                            "window-dragging", &window_drag,
-                            NULL);
-
-      if (window_drag)
-        {
-          gtk_window_begin_move_drag (GTK_WINDOW (window),
-                                      event->button,
-                                      event->x_root,
-                                      event->y_root,
-                                      event->time);
-
-          return TRUE;
-        }
-    }
-
-  return FALSE;
+  return _gtk_window_handle_button_press_for_widget (toolbar, event);
 }
 
 static gboolean
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index be1ce05..25f7bd4 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -3450,7 +3450,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
   gtk_widget_class_install_style_property (klass,
                                            g_param_spec_boolean ("window-dragging",
                                                                  P_("Window dragging"),
-                                                                 P_("Whether windows can be dragged by 
clicking on empty areas"),
+                                                                 P_("Whether windows can be dragged and 
maximized by clicking on empty areas"),
                                                                  FALSE,
                                                                  GTK_PARAM_READABLE));
 
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 8abc5c1..cb38908 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -11667,3 +11667,54 @@ ensure_state_flag_backdrop (GtkWidget *widget)
 
   gtk_widget_queue_draw (widget);
 }
+
+gboolean
+_gtk_window_handle_button_press_for_widget (GtkWidget      *widget,
+                                            GdkEventButton *event)
+{
+  gboolean processed = FALSE;
+  gboolean window_drag = FALSE;
+  GtkWindow *window;
+
+  gtk_widget_style_get (GTK_WIDGET (widget),
+                        "window-dragging", &window_drag,
+                        NULL);
+
+  if (!window_drag)
+    return FALSE;
+
+  if (event->button != GDK_BUTTON_PRIMARY)
+    return FALSE;
+
+  window = GTK_WINDOW (gtk_widget_get_toplevel (widget));
+
+  switch (event->type)
+    {
+    case GDK_BUTTON_PRESS:
+      gtk_window_begin_move_drag (window,
+                                  event->button,
+                                  event->x_root,
+                                  event->y_root,
+                                  event->time);
+      processed = TRUE;
+      break;
+
+    case GDK_2BUTTON_PRESS:
+      {
+        GdkWindow *gdk_window = gtk_widget_get_window (GTK_WIDGET (window));
+
+        if (gdk_window_get_state (gdk_window) & GDK_WINDOW_STATE_MAXIMIZED)
+          gdk_window_unmaximize (gdk_window);
+          else
+            gdk_window_maximize (gdk_window);
+
+        processed = TRUE;
+      }
+      break;
+
+    default:
+      break;
+    }
+
+  return processed;
+}
diff --git a/gtk/gtkwindowprivate.h b/gtk/gtkwindowprivate.h
index 3c27e2e..86724ca 100644
--- a/gtk/gtkwindowprivate.h
+++ b/gtk/gtkwindowprivate.h
@@ -65,6 +65,9 @@ void            _gtk_window_set_allocation         (GtkWindow           *window,
                                                     const GtkAllocation *allocation,
                                                     GtkAllocation       *allocation_out);
 
+gboolean       _gtk_window_handle_button_press_for_widget (GtkWidget      *widget,
+                                                           GdkEventButton *event);
+
 typedef void (*GtkWindowKeysForeachFunc) (GtkWindow      *window,
                                           guint           keyval,
                                           GdkModifierType modifiers,


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