aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy-gtk/empathy-ui-utils.c
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-02-16 22:09:09 +0800
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2011-02-16 22:09:09 +0800
commit33fec6ea1836eaa5ba39bd233a5b81e4f6998a18 (patch)
tree46ac28ef6e74842771b8804ada9c710a51687aaf /libempathy-gtk/empathy-ui-utils.c
parent404871f95d42c41f01af2fdff862a877e624675b (diff)
downloadgsoc2013-empathy-33fec6ea1836eaa5ba39bd233a5b81e4f6998a18.tar
gsoc2013-empathy-33fec6ea1836eaa5ba39bd233a5b81e4f6998a18.tar.gz
gsoc2013-empathy-33fec6ea1836eaa5ba39bd233a5b81e4f6998a18.tar.bz2
gsoc2013-empathy-33fec6ea1836eaa5ba39bd233a5b81e4f6998a18.tar.lz
gsoc2013-empathy-33fec6ea1836eaa5ba39bd233a5b81e4f6998a18.tar.xz
gsoc2013-empathy-33fec6ea1836eaa5ba39bd233a5b81e4f6998a18.tar.zst
gsoc2013-empathy-33fec6ea1836eaa5ba39bd233a5b81e4f6998a18.zip
add empathy_context_menu_new()
That's basically the same trick as we did in individual_view_popup_menu_idle_cb(). We can't unfortunatelly not use this function there as the popup may be reused in some cases.
Diffstat (limited to 'libempathy-gtk/empathy-ui-utils.c')
-rw-r--r--libempathy-gtk/empathy-ui-utils.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/libempathy-gtk/empathy-ui-utils.c b/libempathy-gtk/empathy-ui-utils.c
index b53be03ec..1016c729c 100644
--- a/libempathy-gtk/empathy-ui-utils.c
+++ b/libempathy-gtk/empathy-ui-utils.c
@@ -1907,3 +1907,37 @@ empathy_make_color_whiter (GdkRGBA *color)
color->green = (color->green + white.green) / 2;
color->blue = (color->blue + white.blue) / 2;
}
+
+static void
+menu_deactivate_cb (GtkMenu *menu,
+ gpointer user_data)
+{
+ gtk_menu_detach (menu);
+
+ /* FIXME: we shouldn't have to disconnect the signal (bgo #641327) */
+ g_signal_handlers_disconnect_by_func (menu,
+ menu_deactivate_cb, user_data);
+}
+
+/* Convenient function to create a GtkMenu attached to @attach_to and detach
+ * it when the menu is not displayed any more. This is useful when creating a
+ * context menu that we want to get rid as soon as it as been displayed. */
+GtkWidget *
+empathy_context_menu_new (GtkWidget *attach_to)
+{
+ GtkWidget *menu;
+
+ menu = gtk_menu_new ();
+
+ gtk_menu_attach_to_widget (GTK_MENU (menu), attach_to, NULL);
+
+ /* menu is initially unowned but gtk_menu_attach_to_widget() taked its
+ * floating ref. We can either wait that @attach_to releases its ref when
+ * it will be destroyed (when leaving Empathy most of the time) or explicitely
+ * detach the menu when it's not displayed any more.
+ * We go for the latter as we don't want to keep useless menus in memory
+ * during the whole lifetime of Empathy. */
+ g_signal_connect (menu, "deactivate", G_CALLBACK (menu_deactivate_cb), NULL);
+
+ return menu;
+}