Merge lp:~larsu/indicator-appmenu/lp1075263 into lp:indicator-appmenu/13.04

Proposed by Lars Karlitski on 2012-11-07
Status: Merged
Approved by: Ted Gould on 2012-11-12
Approved revision: 218
Merge reported by: Lars Karlitski
Merged at revision: not available
Proposed branch: lp:~larsu/indicator-appmenu/lp1075263
Merge into: lp:indicator-appmenu/13.04
Diff against target: 121 lines (+1/-55)
1 file modified
src/indicator-appmenu.c (+1/-55)
To merge this branch: bzr merge lp:~larsu/indicator-appmenu/lp1075263
Reviewer Review Type Date Requested Status
Ted Gould (community) 2012-11-07 Approve on 2012-11-12
Charles Kerr (community) 2012-11-07 Approve on 2012-11-07
Review via email: mp+133272@code.launchpad.net

Commit Message

Remove window-destroy timeout

The windows were hashed by xid, and the entries in the hash table weren't
removed until five seconds after the window was destroyed. Thus, restarting an
application within these five seconds and being lucky enough to get the same
xid again would lead to the menu of the old instance being shown. Activating
menu items doesn't work in that case, because the action group is on the dbus
connection of the new instance.

This was initially introduced to work around a bug in BAMF (lp:718926), which
has since been fixed.

To post a comment you must log in.
Charles Kerr (charlesk) wrote :

Nice detective work. :)

All this looks right to me, but for completeness' sake I should point out that though this patch seems to mostly be a reversion of https://code.launchpad.net/~ted/indicator-appmenu/destruction-will-happen-in-time/+merge/56641 which was added for lp:718926, this patch and the pre-718926 code have some minor differences (such as in new_window()) and some major ones (such as in unregister_window()).

review: Approve
Ted Gould (ted) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/indicator-appmenu.c'
2--- src/indicator-appmenu.c 2012-05-08 00:26:54 +0000
3+++ src/indicator-appmenu.c 2012-11-07 15:02:19 +0000
4@@ -106,8 +106,6 @@
5 GDBusConnection * bus;
6 guint owner_id;
7 guint dbus_registration;
8-
9- GHashTable * destruction_timers;
10 };
11
12
13@@ -203,7 +201,6 @@
14 gpointer user_data);
15 static void menus_destroyed (GObject * menus,
16 gpointer user_data);
17-static void source_unregister (gpointer user_data);
18 static GVariant * unregister_window (IndicatorAppmenu * iapp,
19 guint windowid);
20
21@@ -287,9 +284,6 @@
22 self->desktop_windows = g_hash_table_new(g_direct_hash, g_direct_equal);
23 self->desktop_menu = NULL; /* Starts NULL until found */
24
25- /* Set up the hashtable of destruction timers */
26- self->destruction_timers = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, source_unregister);
27-
28 build_window_menus(self);
29
30 /* Get the default BAMF matcher */
31@@ -408,14 +402,6 @@
32 iapp->dbus_registration = 0;
33 }
34
35- if (iapp->destruction_timers != NULL) {
36- /* These are in dispose and not finalize becuase the dereference
37- function removes timers that could need the object to be in
38- a valid state, so it's better to have them in dispose */
39- g_hash_table_destroy(iapp->destruction_timers);
40- iapp->destruction_timers = NULL;
41- }
42-
43 if (iapp->bus != NULL) {
44 g_object_unref(iapp->bus);
45 iapp->bus = NULL;
46@@ -627,9 +613,6 @@
47 IndicatorAppmenu * iapp = INDICATOR_APPMENU(user_data);
48 guint32 xid = bamf_window_get_xid(window);
49
50- /* Make sure we don't destroy it later */
51- g_hash_table_remove(iapp->destruction_timers, GUINT_TO_POINTER(xid));
52-
53 if (bamf_window_get_window_type(window) != BAMF_WINDOW_DESKTOP) {
54 return;
55 }
56@@ -651,32 +634,6 @@
57 return;
58 }
59
60-typedef struct _destroy_data_t destroy_data_t;
61-struct _destroy_data_t {
62- IndicatorAppmenu * iapp;
63- guint32 xid;
64-};
65-
66-/* Timeout to finally cleanup the window. Causes is to ignore glitches that
67- come from BAMF/WNCK. */
68-static gboolean
69-destroy_window_timeout (gpointer user_data)
70-{
71- destroy_data_t * destroy_data = (destroy_data_t *)user_data;
72- g_hash_table_steal(destroy_data->iapp->destruction_timers, GUINT_TO_POINTER(destroy_data->xid));
73- unregister_window(destroy_data->iapp, destroy_data->xid);
74- return FALSE; /* free's data through source deregistration */
75-}
76-
77-/* Unregisters the source in the hash table when it gets removed. This ensure
78- we don't leave any timeouts around */
79-static void
80-source_unregister (gpointer user_data)
81-{
82- g_source_remove(GPOINTER_TO_UINT(user_data));
83- return;
84-}
85-
86 /* When windows leave us, this function gets called */
87 static void
88 old_window (BamfMatcher * matcher, BamfView * view, gpointer user_data)
89@@ -689,12 +646,7 @@
90 BamfWindow * window = BAMF_WINDOW(view);
91 guint32 xid = bamf_window_get_xid(window);
92
93- destroy_data_t * destroy_data = g_new0(destroy_data_t, 1);
94- destroy_data->iapp = iapp;
95- destroy_data->xid = xid;
96-
97- guint source_id = g_timeout_add_seconds_full(G_PRIORITY_LOW, 5, destroy_window_timeout, destroy_data, g_free);
98- g_hash_table_replace(iapp->destruction_timers, GUINT_TO_POINTER(xid), GUINT_TO_POINTER(source_id));
99+ unregister_window(iapp, xid);
100
101 return;
102 }
103@@ -1178,9 +1130,6 @@
104 {
105 g_debug("Registering window ID %d with path %s from %s", windowid, objectpath, sender);
106
107- /* Shouldn't do anything, but let's be sure */
108- g_hash_table_remove(iapp->destruction_timers, GUINT_TO_POINTER(windowid));
109-
110 if (g_hash_table_lookup(iapp->apps, GUINT_TO_POINTER(windowid)) == NULL && windowid != 0) {
111 WindowMenu * wm = WINDOW_MENU(window_menu_dbusmenu_new(windowid, sender, objectpath));
112 g_return_val_if_fail(wm != NULL, FALSE);
113@@ -1230,9 +1179,6 @@
114 g_return_val_if_fail(IS_INDICATOR_APPMENU(iapp), NULL);
115 g_return_val_if_fail(iapp->matcher != NULL, NULL);
116
117- /* Make sure we don't destroy it later */
118- g_hash_table_remove(iapp->destruction_timers, GUINT_TO_POINTER(windowid));
119-
120 /* If it's a desktop window remove it from that table as well */
121 g_hash_table_remove(iapp->desktop_windows, GUINT_TO_POINTER(windowid));
122

Subscribers

People subscribed via source and target branches