← Back to team overview

ayatana-commits team mailing list archive

[Merge] lp:~ted/indicator-appmenu/menu-removal-tracking into lp:indicator-appmenu

 

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

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


This patch changes the way we handle the BAMF window being destroyed.  We keep a pointer to it so that we still think we have one for getting_entries.  But, we don't use it for anything.  Instead we're caching the state of the stubs so that we don't end up *using* that pointer anywhere so it's okay that it's effectively invalid.

What's curious about this whole thing is that I don't believe that we should be getting a destroy on the active window before getting a window switch normally, but it seems that we are.
-- 
https://code.launchpad.net/~ted/indicator-appmenu/menu-removal-tracking/+merge/36393
Your team ayatana-commits is subscribed to branch lp:indicator-appmenu.
=== modified file 'src/indicator-appmenu.c'
--- src/indicator-appmenu.c	2010-09-22 15:58:35 +0000
+++ src/indicator-appmenu.c	2010-09-22 22:13:41 +0000
@@ -64,6 +64,13 @@
 typedef struct _IndicatorAppmenuDebug      IndicatorAppmenuDebug;
 typedef struct _IndicatorAppmenuDebugClass IndicatorAppmenuDebugClass;
 
+typedef enum _ActiveStubsState ActiveStubsState;
+enum _ActiveStubsState {
+	STUBS_UNKNOWN,
+	STUBS_SHOW,
+	STUBS_HIDE
+};
+
 struct _IndicatorAppmenuClass {
 	IndicatorObjectClass parent_class;
 
@@ -81,6 +88,7 @@
 
 	BamfMatcher * matcher;
 	BamfWindow * active_window;
+	ActiveStubsState active_stubs;
 
 	gulong sig_entry_added;
 	gulong sig_entry_removed;
@@ -262,6 +270,7 @@
 	self->apps = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_object_unref);
 	self->matcher = NULL;
 	self->active_window = NULL;
+	self->active_stubs = STUBS_UNKNOWN;
 	self->close_item = NULL;
 	self->retry_registration = 0;
 
@@ -757,17 +766,25 @@
 
 	/* Oh, now we're looking at stubs. */
 
-	BamfApplication * app = bamf_matcher_get_application_for_window(iapp->matcher, iapp->active_window);
-	if (app != NULL) {
-		/* First check to see if we can find an app, then if we can
-		   check to see if it has an opinion on whether we should
-		   show the stubs or not. */
-		if (show_menu_stubs(app) == FALSE) {
-			/* If it blocks them, fall out. */
-			return NULL;
+	if (iapp->active_stubs == STUBS_UNKNOWN) {
+		iapp->active_stubs = STUBS_SHOW;
+
+		BamfApplication * app = bamf_matcher_get_application_for_window(iapp->matcher, iapp->active_window);
+		if (app != NULL) {
+			/* First check to see if we can find an app, then if we can
+			   check to see if it has an opinion on whether we should
+			   show the stubs or not. */
+			if (show_menu_stubs(app) == FALSE) {
+				/* If it blocks them, fall out. */
+				iapp->active_stubs = STUBS_HIDE;
+			}
 		}
 	}
 
+	if (iapp->active_stubs == STUBS_HIDE) {
+		return NULL;
+	}
+
 	GList * output = NULL;
 	int i;
 
@@ -846,8 +863,6 @@
 		return;
 	}
 
-	iapp->active_window = NULL;
-
 	/* We're going to a state where we don't know what the active
 	   window is, hopefully BAMF will save us */
 	active_window_changed (iapp->matcher, NULL, NULL, iapp);
@@ -869,7 +884,11 @@
 	}
 
 	iapp->active_window = active_window;
-	g_object_weak_ref(G_OBJECT(active_window), window_finalized_is_active, iapp);
+	iapp->active_stubs = STUBS_UNKNOWN;
+
+	if (active_window != NULL) {
+		g_object_weak_ref(G_OBJECT(active_window), window_finalized_is_active, iapp);
+	}
 
 	if (iapp->close_item == NULL) {
 		g_warning("No close item!?!?!");
@@ -878,6 +897,10 @@
 
 	gtk_widget_set_sensitive(GTK_WIDGET(iapp->close_item), FALSE);
 
+	if (iapp->active_window == NULL) {
+		return;
+	}
+
 	guint xid = bamf_window_get_xid(iapp->active_window);
 	if (xid == 0 || bamf_view_is_closed (BAMF_VIEW (iapp->active_window))) {
 		return;
@@ -1050,7 +1073,11 @@
 	   newwindow variable.  Which means we stay where we were
 	   but get the menus from parents. */
 	g_debug("Switching to menus from XID %d", xid);
-	switch_default_app(appmenu, menus, BAMF_WINDOW(newview));
+	if (newview != NULL) {
+		switch_default_app(appmenu, menus, BAMF_WINDOW(newview));
+	} else {
+		switch_default_app(appmenu, menus, NULL);
+	}
 
 	return;
 }


Follow ups