[maemo-commits] [maemo-commits] r9416 - in projects/haf/branches/gtk+/maemo-gtk-2-10: . gtk

From: subversion at stage.maemo.org subversion at stage.maemo.org
Date: Mon Jan 29 15:37:39 EET 2007
Author: mitch
Date: 2007-01-29 15:37:31 +0200 (Mon, 29 Jan 2007)
New Revision: 9416

Modified:
   projects/haf/branches/gtk+/maemo-gtk-2-10/ChangeLog
   projects/haf/branches/gtk+/maemo-gtk-2-10/gtk/gtkmenu.c
Log:
2007-01-29  Michael Natterer  <mitch at imendio.com>

	* gtk/gtkmenu.c: port over handling of visibility-notify-event to
	pop down menus when they become obscured.



Modified: projects/haf/branches/gtk+/maemo-gtk-2-10/ChangeLog
===================================================================
--- projects/haf/branches/gtk+/maemo-gtk-2-10/ChangeLog	2007-01-29 13:34:48 UTC (rev 9415)
+++ projects/haf/branches/gtk+/maemo-gtk-2-10/ChangeLog	2007-01-29 13:37:31 UTC (rev 9416)
@@ -1,5 +1,10 @@
 2007-01-29  Michael Natterer  <mitch at imendio.com>
 
+	* gtk/gtkmenu.c: port over handling of visibility-notify-event to
+	pop down menus when they become obscured.
+
+2007-01-29  Michael Natterer  <mitch at imendio.com>
+
 	* gtk/gtkmenu.c (gtk_menu_popup): port over selecting of first
 	item if none is selected.
 

Modified: projects/haf/branches/gtk+/maemo-gtk-2-10/gtk/gtkmenu.c
===================================================================
--- projects/haf/branches/gtk+/maemo-gtk-2-10/gtk/gtkmenu.c	2007-01-29 13:34:48 UTC (rev 9415)
+++ projects/haf/branches/gtk+/maemo-gtk-2-10/gtk/gtkmenu.c	2007-01-29 13:37:31 UTC (rev 9416)
@@ -254,6 +254,12 @@
 static void _gtk_menu_refresh_accel_paths (GtkMenu *menu,
 					   gboolean group_changed);
 
+#ifdef MAEMO_CHANGES
+static gboolean gtk_menu_window_visibility_notify_event (GtkWidget          *widget,
+                                                         GdkEventVisibility *event,
+                                                         GtkMenu            *menu);
+#endif /* MAEMO_CHANGES */
+
 static const gchar	  attach_data_key[] = "gtk-menu-attach-data";
 
 static guint menu_signals[LAST_SIGNAL] = { 0 };
@@ -877,6 +883,9 @@
 				     "signal::event", gtk_menu_window_event, menu,
 				     "signal::size_request", gtk_menu_window_size_request, menu,
 				     "signal::destroy", gtk_widget_destroyed, &menu->toplevel,
+#ifdef MAEMO_CHANGES
+                                     "signal::visibility_notify_event", gtk_menu_window_visibility_notify_event, menu,
+#endif /* MAEMO_CHANGES */
 				     NULL);
 #ifdef MAEMO_CHANGES
   gtk_window_set_decorated (GTK_WINDOW (menu->toplevel), FALSE);
@@ -4948,5 +4957,79 @@
 }
 #endif /* MAEMO_CHANGES */
 
+#ifdef MAEMO_CHANGES
+static gboolean
+gtk_menu_window_visibility_notify_event (GtkWidget          *widget,
+                                         GdkEventVisibility *event,
+                                         GtkMenu            *menu)
+{
+  GtkMenuShell *menu_shell;
+  GdkScreen *screen;
+  GList *stack;
+  gboolean deactivate;
+
+  /* The point here is to close the menu if another window (eg. dialog,
+     even partially!) gets on top of the menu. However our own submenus may
+     also fully obscure us, so we have to check that case.
+
+     It's also possible that we get here while a submenu was opened and
+     closed quickly, so we don't really see it anymore but its window is
+     still obscuring us.. So, never close the menu if another menu is on top
+     of us. */
+  if (event->state == GDK_VISIBILITY_UNOBSCURED)
+    return FALSE;
+
+  menu_shell = GTK_MENU_SHELL (menu);
+
+  screen = gtk_widget_get_screen (widget);
+
+  deactivate = FALSE;
+
+  /* Inspect windows above us */
+  stack = gdk_screen_get_window_stack (screen);
+  if (stack != NULL)
+    {
+      GList *iter;
+
+      iter = g_list_last (stack);
+
+      while (iter)
+        {
+          GdkWindow *win = iter->data;
+          GdkWindowTypeHint type;
+
+          if (win == widget->window)
+            break;
+
+          gdk_error_trap_push ();
+          type = gdk_window_get_type_hint (win);
+          if (!gdk_error_trap_pop () &&
+              (type != GDK_WINDOW_TYPE_HINT_MESSAGE)
+              && (type != GDK_WINDOW_TYPE_HINT_MENU))
+            {
+              /* A non-message and non-menu window above us; close. */
+              deactivate = TRUE;
+
+              break;
+            }
+
+          iter = iter->prev;
+        }
+
+      g_list_foreach (stack, (GFunc) g_object_unref, NULL);
+      g_list_free (stack);
+    }
+
+  if (deactivate)
+    {
+      gtk_menu_shell_deactivate (menu_shell);
+
+      return TRUE;
+    }
+
+  return FALSE;
+}
+#endif /* MAEMO_CHANGES */
+
 #define __GTK_MENU_C__
 #include "gtkaliasdef.c"


More information about the maemo-commits mailing list