summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2006-04-29 06:34:14 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2006-04-29 06:34:14 +0000
commit10583204d999ba1e5d9c57ef47a0de0de55119c3 (patch)
tree148a0d5bc20a0fc246fea0f84d65bedb24ced2a7
parentab7c146eb497239816c4077d0c82ded26090cbce (diff)
downloadgtk+-10583204d999ba1e5d9c57ef47a0de0de55119c3.tar.gz
Add a menu position function for use with popups on status icons.
2006-04-29 Matthias Clasen <mclasen@redhat.com> * gtk/gtk.symbols: * gtk/gtkstatusicon.h: * gtk/gtkstatusicon.c (gtk_status_icon_position_menu): Add a menu position function for use with popups on status icons. (#334573, Christian Persch)
-rw-r--r--ChangeLog6
-rw-r--r--ChangeLog.pre-2-106
-rw-r--r--docs/reference/ChangeLog4
-rw-r--r--docs/reference/gtk/gtk-sections.txt1
-rw-r--r--gtk/gtk.symbols1
-rwxr-xr-xgtk/gtkstatusicon.c108
-rwxr-xr-xgtk/gtkstatusicon.h7
7 files changed, 133 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index bfd2895a53..0923e566f2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2006-04-29 Matthias Clasen <mclasen@redhat.com>
+ * gtk/gtk.symbols:
+ * gtk/gtkstatusicon.h:
+ * gtk/gtkstatusicon.c (gtk_status_icon_position_menu): Add a menu
+ position function for use with popups on status icons. (#334573,
+ Christian Persch)
+
* gtk/gtkwidget.c (gtk_widget_is_composited): Fix a C99ism. (#340055,
Kazuki Iwamoto)
diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10
index bfd2895a53..0923e566f2 100644
--- a/ChangeLog.pre-2-10
+++ b/ChangeLog.pre-2-10
@@ -1,5 +1,11 @@
2006-04-29 Matthias Clasen <mclasen@redhat.com>
+ * gtk/gtk.symbols:
+ * gtk/gtkstatusicon.h:
+ * gtk/gtkstatusicon.c (gtk_status_icon_position_menu): Add a menu
+ position function for use with popups on status icons. (#334573,
+ Christian Persch)
+
* gtk/gtkwidget.c (gtk_widget_is_composited): Fix a C99ism. (#340055,
Kazuki Iwamoto)
diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog
index e68e35a555..700249068b 100644
--- a/docs/reference/ChangeLog
+++ b/docs/reference/ChangeLog
@@ -1,3 +1,7 @@
+2006-04-29 Matthias Clasen <mclasen@redhat.com>
+
+ * gtk/gtk-sections.txt: Add gtk_status_icon_position_menu
+
2006-04-25 Matthias Clasen <mclasen@redhat.com>
* gdk/gdk-sections.txt: Add gdk_screen_is_composited
diff --git a/docs/reference/gtk/gtk-sections.txt b/docs/reference/gtk/gtk-sections.txt
index d5acc625dc..0744b6b7e3 100644
--- a/docs/reference/gtk/gtk-sections.txt
+++ b/docs/reference/gtk/gtk-sections.txt
@@ -3240,6 +3240,7 @@ gtk_status_icon_get_visible
gtk_status_icon_set_blinking
gtk_status_icon_get_blinking
gtk_status_icon_is_embedded
+gtk_status_icon_position_menu
<SUBSECTION Standard>
GTK_TYPE_STATUS_ICON
GTK_STATUS_ICON
diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols
index 4a2614bc02..e4fba9775d 100644
--- a/gtk/gtk.symbols
+++ b/gtk/gtk.symbols
@@ -1050,6 +1050,7 @@ gtk_status_icon_get_visible
gtk_status_icon_set_blinking
gtk_status_icon_get_blinking
gtk_status_icon_is_embedded
+gtk_status_icon_position_menu
#endif
#endif
diff --git a/gtk/gtkstatusicon.c b/gtk/gtkstatusicon.c
index b38f7cde72..9a37f4fd9b 100755
--- a/gtk/gtkstatusicon.c
+++ b/gtk/gtkstatusicon.c
@@ -1469,5 +1469,113 @@ gtk_status_icon_is_embedded (GtkStatusIcon *status_icon)
#endif
}
+/**
+ * gtk_status_icon_position_menu:
+ * @menu: the #GtkMenu
+ * @x: return location for the x position
+ * @y: return location for the y position
+ * @push_in: return location for whether the menu should be pushed in
+ * to be completely inside the screen instead of just clamped to the
+ * size to the screen.
+ * @user_data: the status icon to position the menu on
+ *
+ * Menu positioning function to use with gtk_menu_popup()
+ * to position @menu aligned to the status icon @user_data.
+ *
+ * Since: 2.10
+ **/
+void
+gtk_status_icon_position_menu (GtkMenu *menu,
+ gint *x,
+ gint *y,
+ gboolean *push_in,
+ gpointer user_data)
+{
+#ifdef GDK_WINDOWING_X11
+ GtkStatusIcon *status_icon;
+ GtkStatusIconPrivate *priv;
+ GtkTrayIcon *tray_icon;
+ GtkWidget *widget;
+ GdkScreen *screen;
+ GtkTextDirection direction;
+ GtkRequisition menu_req;
+ GdkRectangle monitor;
+ gint monitor_num, height, width, xoffset, yoffset;
+
+ g_return_if_fail (GTK_IS_MENU (menu));
+ g_return_if_fail (GTK_IS_STATUS_ICON (user_data));
+
+ status_icon = GTK_STATUS_ICON (user_data);
+ priv = status_icon->priv;
+ tray_icon = GTK_TRAY_ICON (priv->tray_icon);
+ widget = priv->tray_icon;
+
+ direction = gtk_widget_get_direction (widget);
+
+ screen = gtk_widget_get_screen (widget);
+ gtk_menu_set_screen (menu, screen);
+
+ monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window);
+ if (monitor_num < 0)
+ monitor_num = 0;
+ gtk_menu_set_monitor (menu, monitor_num);
+
+ gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
+
+ gdk_window_get_origin (widget->window, x, y);
+
+ gtk_widget_size_request (GTK_WIDGET (menu), &menu_req);
+
+ if (_gtk_tray_icon_get_orientation (tray_icon) == GTK_ORIENTATION_VERTICAL)
+ {
+ width = 0;
+ height = widget->allocation.height;
+ xoffset = widget->allocation.width;
+ yoffset = 0;
+ }
+ else
+ {
+ width = widget->allocation.width;
+ height = 0;
+ xoffset = 0;
+ yoffset = widget->allocation.height;
+ }
+
+ if (direction == GTK_TEXT_DIR_RTL)
+ {
+ if ((*x - (menu_req.width - width)) >= monitor.x)
+ *x -= menu_req.width - width;
+ else if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
+ *x += xoffset;
+ else if ((monitor.x + monitor.width - (*x + xoffset)) < *x)
+ *x -= menu_req.width - width;
+ else
+ *x += xoffset;
+ }
+ else
+ {
+ if ((*x + xoffset + menu_req.width) < (monitor.x + monitor.width))
+ *x += xoffset;
+ else if ((*x - (menu_req.width - width)) >= monitor.x)
+ *x -= menu_req.width - width;
+ else if ((monitor.x + monitor.width - (*x + xoffset)) > *x)
+ *x += xoffset;
+ else
+ *x -= menu_req.width - width;
+ }
+
+ if ((*y + yoffset + menu_req.height) < (monitor.y + monitor.height))
+ *y += yoffset;
+ else if ((*y - (menu_req.height - height)) >= monitor.y)
+ *y -= menu_req.height - height;
+ else if (monitor.y + monitor.height - (*y + yoffset) > *y)
+ *y += yoffset;
+ else
+ *y -= menu_req.height - height;
+
+ *push_in = FALSE;
+#endif /* GDK_WINDOWING_X11 */
+}
+
#define __GTK_STATUS_ICON_C__
#include "gtkaliasdef.c"
diff --git a/gtk/gtkstatusicon.h b/gtk/gtkstatusicon.h
index c810dac1bf..265b006e53 100755
--- a/gtk/gtkstatusicon.h
+++ b/gtk/gtkstatusicon.h
@@ -25,6 +25,7 @@
#define __GTK_STATUS_ICON_H__
#include <gtk/gtkimage.h>
+#include <gtk/gtkmenu.h>
G_BEGIN_DECLS
@@ -103,6 +104,12 @@ gboolean gtk_status_icon_get_blinking (GtkStatusIcon *st
gboolean gtk_status_icon_is_embedded (GtkStatusIcon *status_icon);
+void gtk_status_icon_position_menu (GtkMenu *menu,
+ gint *x,
+ gint *y,
+ gboolean *push_in,
+ gpointer user_data);
+
G_END_DECLS
#endif /* __GTK_STATUS_ICON_H__ */