[Goodies-commits] r3329 - xfce4-notes-plugin/trunk/panel-plugin

Mike Massonnet mmassonnet at xfce.org
Wed Oct 10 23:57:29 CEST 2007


Author: mmassonnet
Date: 2007-10-10 21:57:29 +0000 (Wed, 10 Oct 2007)
New Revision: 3329

Modified:
   xfce4-notes-plugin/trunk/panel-plugin/notes.c
   xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c
Log:
Add positionning functions for the menus.


Modified: xfce4-notes-plugin/trunk/panel-plugin/notes.c
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/notes.c	2007-10-10 21:57:14 UTC (rev 3328)
+++ xfce4-notes-plugin/trunk/panel-plugin/notes.c	2007-10-10 21:57:29 UTC (rev 3329)
@@ -36,6 +36,11 @@
 
 static gboolean         notes_window_menu_popup         (NotesWindow *notes_window,
                                                          GdkEvent *event);
+static void             notes_window_menu_position      (GtkMenu *menu,
+                                                         gint *x,
+                                                         gint *y,
+                                                         gboolean *push_in,
+                                                         gpointer user_data);
 static void             notes_window_menu_destroy       (NotesWindow *notes_window);
 
 static void             notes_window_set_sos_always     (NotesWindow *notes_window);
@@ -535,8 +540,8 @@
       gtk_menu_popup (GTK_MENU (notes_window->menu),
                       NULL,
                       NULL,
+                      (GtkMenuPositionFunc) notes_window_menu_position,
                       NULL,
-                      NULL,
                       event->button.button,
                       event->button.time);
     }
@@ -544,6 +549,45 @@
 }
 
 static void
+notes_window_menu_position (GtkMenu *menu,
+                            gint *x0,
+                            gint *y0,
+                            gboolean *push_in,
+                            gpointer user_data)
+{
+  GdkWindow            *toplevel;
+  gint                  x1, y1, width, height, depth;
+  GtkWidget            *btn_menu;
+  GtkRequisition        requisition0;
+
+  g_return_if_fail (GTK_IS_MENU (menu));
+  btn_menu = gtk_menu_get_attach_widget (menu);
+  g_return_if_fail (GTK_IS_WIDGET (btn_menu));
+
+  toplevel = gdk_window_get_toplevel (btn_menu->window);
+  gdk_window_get_geometry (toplevel, &x1, &y1, &width, &height, &depth);
+  gdk_window_get_origin (btn_menu->window, x0, y0);
+  gtk_widget_size_request (GTK_WIDGET (menu), &requisition0);
+
+  TRACE ("\nx0/y0: %d/%d"
+         "\nx1/y1/width/height: %d/%d/%d/%d",
+         *x0, *y0,
+         x1, y1, width, height);
+
+   if (*y0 + btn_menu->allocation.height + requisition0.height > gdk_screen_height())
+    /* Show menu above button, since there is not enough space below */
+    *y0 -= requisition0.height;
+   else
+    /* Show menu below button */
+    *y0 += btn_menu->allocation.height;
+
+   *x0 += width - requisition0.width;
+   if (*x0 + requisition0.width > gdk_screen_width ())
+     /* Adjust horizontal position */
+     *x0 = gdk_screen_width () - requisition0.width;
+}
+
+static void
 notes_window_menu_destroy (NotesWindow *notes_window)
 {
   DBG ("Dettach window menu");

Modified: xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c	2007-10-10 21:57:14 UTC (rev 3328)
+++ xfce4-notes-plugin/trunk/panel-plugin/panel-plugin.c	2007-10-10 21:57:29 UTC (rev 3329)
@@ -55,6 +55,11 @@
 
 static gboolean         notes_plugin_menu_popup         (NotesPlugin *notes_plugin,
                                                          GdkEvent *event);
+static void             notes_plugin_menu_position      (GtkMenu *menu,
+                                                         gint *x0,
+                                                         gint *y0,
+                                                         gboolean *push_in,
+                                                         gpointer user_data);
 static void             notes_plugin_menu_destroy       (NotesPlugin *notes_plugin);
 
 /* TODO sort the next functions */
@@ -240,8 +245,8 @@
       gtk_menu_popup (GTK_MENU (notes_plugin->menu),
                       NULL,
                       NULL,
+                      (GtkMenuPositionFunc) notes_plugin_menu_position,
                       NULL,
-                      NULL,
                       event->button.button,
                       event->button.time);
     }
@@ -249,6 +254,38 @@
 }
 
 static void
+notes_plugin_menu_position (GtkMenu *menu,
+                            gint *x0,
+                            gint *y0,
+                            gboolean *push_in,
+                            gpointer user_data)
+{
+  GtkWidget            *btn_panel;
+  GtkRequisition        requisition0;
+
+  g_return_if_fail (GTK_IS_MENU (menu));
+  btn_panel = gtk_menu_get_attach_widget (menu);
+  g_return_if_fail (GTK_IS_WIDGET (btn_panel));
+
+  gdk_window_get_origin (btn_panel->window, x0, y0);
+  gtk_widget_size_request (GTK_WIDGET (menu), &requisition0);
+
+  TRACE ("x0/y0: %d/%d",
+         *x0, *y0);
+
+   if (*y0 + btn_panel->allocation.height + requisition0.height > gdk_screen_height())
+    /* Show menu above button, since there is not enough space below */
+    *y0 -= requisition0.height;
+   else
+    /* Show menu below button */
+    *y0 += btn_panel->allocation.height;
+
+   if (*x0 + requisition0.width > gdk_screen_width ())
+     /* Adjust horizontal position */
+     *x0 = gdk_screen_width () - requisition0.width;
+}
+
+static void
 notes_plugin_menu_destroy (NotesPlugin *notes_plugin)
 {
   DBG ("Dettach window menu");




More information about the Goodies-commits mailing list