← Back to team overview

ayatana-commits team mailing list archive

[Merge] lp:~ted/indicator-appmenu/menu-show-signals into lp:indicator-appmenu

 

Ted Gould has proposed merging lp:~ted/indicator-appmenu/menu-show-signals into lp:indicator-appmenu.

Requested reviews:
  Indicator Applet Developers (indicator-applet-developers)


Passes up the signal to show the menus so that Unity can pick it up.  Unfortunately, I can't really test it without Unity :(
-- 
https://code.launchpad.net/~ted/indicator-appmenu/menu-show-signals/+merge/35465
Your team ayatana-commits is subscribed to branch lp:indicator-appmenu.
=== modified file 'src/indicator-appmenu-marshal.list'
--- src/indicator-appmenu-marshal.list	2010-07-15 18:26:31 +0000
+++ src/indicator-appmenu-marshal.list	2010-09-14 20:33:50 +0000
@@ -1,2 +1,3 @@
 VOID: UINT, STRING, BOXED
 VOID: UINT
+VOID: POINTER, UINT

=== modified file 'src/indicator-appmenu.c'
--- src/indicator-appmenu.c	2010-09-09 14:33:37 +0000
+++ src/indicator-appmenu.c	2010-09-14 20:33:50 +0000
@@ -82,6 +82,7 @@
 
 	gulong sig_entry_added;
 	gulong sig_entry_removed;
+	gulong sig_show_menu;
 
 	GtkMenuItem * close_item;
 
@@ -164,6 +165,10 @@
 static void window_entry_removed                                     (WindowMenus * mw,
                                                                       IndicatorObjectEntry * entry,
                                                                       gpointer user_data);
+static void window_show_menu                                         (WindowMenus * mw,
+                                                                      IndicatorObjectEntry * entry,
+                                                                      guint timestamp,
+                                                                      gpointer user_data);
 static void active_window_changed                                    (BamfMatcher * matcher,
                                                                       BamfView * oldview,
                                                                       BamfView * newview,
@@ -763,6 +768,10 @@
 		g_signal_handler_disconnect(G_OBJECT(iapp->default_app), iapp->sig_entry_removed);
 		iapp->sig_entry_removed = 0;
 	}
+	if (iapp->sig_show_menu != 0) {
+		g_signal_handler_disconnect(G_OBJECT(iapp->default_app), iapp->sig_show_menu);
+		iapp->sig_show_menu = 0;
+	}
 
 	/* Default App is NULL, let's see if it needs replacement */
 	iapp->default_app = NULL;
@@ -784,6 +793,10 @@
 		                                           WINDOW_MENUS_SIGNAL_ENTRY_REMOVED,
 		                                           G_CALLBACK(window_entry_removed),
 		                                           iapp);
+		iapp->sig_show_menu     = g_signal_connect(G_OBJECT(iapp->default_app),
+		                                           WINDOW_MENUS_SIGNAL_SHOW_MENU,
+		                                           G_CALLBACK(window_show_menu),
+		                                           iapp);
 	}
 
 	/* Get our new list of entries.  Now we can go ahead and signal
@@ -1055,6 +1068,14 @@
 	return;
 }
 
+/* Pass up the show menu event */
+static void
+window_show_menu (WindowMenus * mw, IndicatorObjectEntry * entry, guint timestamp, gpointer user_data)
+{
+	g_signal_emit_by_name(G_OBJECT(user_data), INDICATOR_OBJECT_SIGNAL_MENU_SHOW, entry, timestamp);
+	return;
+}
+
 /**********************
   DEBUG INTERFACE
  **********************/

=== modified file 'src/window-menus.c'
--- src/window-menus.c	2010-08-27 21:43:00 +0000
+++ src/window-menus.c	2010-09-14 20:33:50 +0000
@@ -28,6 +28,7 @@
 #include <glib.h>
 
 #include "window-menus.h"
+#include "indicator-appmenu-marshal.h"
 
 /* Private parts */
 
@@ -63,6 +64,7 @@
 	ENTRY_REMOVED,
 	DESTROY,
 	ERROR_STATE,
+	SHOW_MENU,
 	LAST_SIGNAL
 };
 
@@ -123,6 +125,13 @@
 	                                      NULL, NULL,
 	                                      g_cclosure_marshal_VOID__BOOLEAN,
 	                                      G_TYPE_NONE, 1, G_TYPE_BOOLEAN, G_TYPE_NONE);
+	signals[SHOW_MENU] =     g_signal_new(WINDOW_MENUS_SIGNAL_SHOW_MENU,
+	                                      G_TYPE_FROM_CLASS(klass),
+	                                      G_SIGNAL_RUN_LAST,
+	                                      G_STRUCT_OFFSET (WindowMenusClass, show_menu),
+	                                      NULL, NULL,
+	                                      _indicator_appmenu_marshal_VOID__POINTER_UINT,
+	                                      G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_UINT, G_TYPE_NONE);
 
 	return;
 }
@@ -295,6 +304,34 @@
 	return;
 }
 
+/* Called when a menu item wants to be displayed.  We need to see if
+   it's one of our root items and pass it up if so. */
+static void
+item_activate (DbusmenuClient * client, DbusmenuMenuitem * item, guint timestamp, gpointer user_data)
+{
+	g_return_if_fail(IS_WINDOW_MENUS(user_data));
+	WindowMenusPrivate * priv = WINDOW_MENUS_GET_PRIVATE(user_data);
+
+	if (priv->root == NULL) {
+		return;
+	}
+
+	guint position = dbusmenu_menuitem_get_position(priv->root, item);
+	if (position == 0) {
+		/* Ugly, ugly hack.  I shouldn't have used guint in the function
+		   above, but now I have to do this.  Ew! */
+		GList * children = dbusmenu_menuitem_get_children(priv->root);
+		if (children == NULL || children->data != item) {
+			return;
+		}
+	}
+
+	IndicatorObjectEntry * entry = &g_array_index(priv->entries, IndicatorObjectEntry, position);
+	g_signal_emit(G_OBJECT(user_data), signals[SHOW_MENU], 0, entry, timestamp, TRUE);
+
+	return;
+}
+
 /* Build a new window menus object and attach to the signals to build
    up the representative menu. */
 WindowMenus *
@@ -333,6 +370,7 @@
 
 	g_signal_connect(G_OBJECT(priv->client), DBUSMENU_GTKCLIENT_SIGNAL_ROOT_CHANGED, G_CALLBACK(root_changed),   newmenu);
 	g_signal_connect(G_OBJECT(priv->client), DBUSMENU_CLIENT_SIGNAL_EVENT_RESULT, G_CALLBACK(event_status), newmenu);
+	g_signal_connect(G_OBJECT(priv->client), DBUSMENU_CLIENT_SIGNAL_ITEM_ACTIVATE, G_CALLBACK(item_activate), newmenu);
 
 	DbusmenuMenuitem * root = dbusmenu_client_get_root(DBUSMENU_CLIENT(priv->client));
 	if (root != NULL) {

=== modified file 'src/window-menus.h'
--- src/window-menus.h	2010-08-27 16:48:21 +0000
+++ src/window-menus.h	2010-09-14 20:33:50 +0000
@@ -39,6 +39,7 @@
 #define WINDOW_MENUS_SIGNAL_ENTRY_REMOVED  "entry-removed"
 #define WINDOW_MENUS_SIGNAL_DESTROY        "destroy"
 #define WINDOW_MENUS_SIGNAL_ERROR_STATE    "error-state"
+#define WINDOW_MENUS_SIGNAL_SHOW_MENU      "show-menu"
 
 typedef struct _WindowMenus      WindowMenus;
 typedef struct _WindowMenusClass WindowMenusClass;
@@ -52,6 +53,8 @@
 
 	void (*destroy)       (WindowMenus * wm, gpointer user_data);
 	void (*error_state)   (WindowMenus * wm, gboolean state, gpointer user_data);
+
+	void (*show_menu)     (WindowMenus * wm, IndicatorObjectEntry * entry, guint timestamp, gpointer user_data);
 };
 
 struct _WindowMenus {


Follow ups