Merge lp:~3v1n0/bamf/g-control-center-rematching into lp:bamf/0.4

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: 432
Merged at revision: 433
Proposed branch: lp:~3v1n0/bamf/g-control-center-rematching
Merge into: lp:bamf/0.4
Diff against target: 367 lines (+167/-37)
2 files modified
src/bamf-matcher.c (+166/-37)
src/bamf-matcher.h (+1/-0)
To merge this branch: bzr merge lp:~3v1n0/bamf/g-control-center-rematching
Reviewer Review Type Date Requested Status
Unity Team Pending
Review via email: mp+89516@code.launchpad.net

Description of the change

Fixed bug bug #801784 making gnome-control-center to rematch in BAMF

Used a similar hack used for re-matching libreoffice. Here the gnome-control-center window is rematched when its name changes, getting its ID from the defined WM_WINDOW_ROLE.

Also I've fixed a bug that caused all the gnome-control-center desktop to be ignored by the matcher, only the last parsed was considered by bamf before (due to this when doing "gnome-control-center display" in a terminal, the window was matched as a generic g-c-c window, not as the display one). To do this, I've added a white-list regex to match the prefixes that must not be ignored and that should be included into the exec string (I guess that this can be useful also for fixing the matching of the wine apps).

Note that this branch to work correctly needs lp:~3v1n0/ubuntu/precise/gnome-control-center/add-window-role-to-panels
If no patched gnome-control-center is found, all the gnome-control-center windows will always be shown as generic g-c-c windows.

To post a comment you must log in.
432. By Marco Trevisan (Treviño)

BamfMatcher: don't include bzr as a good prefix.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/bamf-matcher.c'
2--- src/bamf-matcher.c 2012-01-17 08:57:56 +0000
3+++ src/bamf-matcher.c 2012-01-26 14:33:26 +0000
4@@ -51,6 +51,7 @@
5 struct _BamfMatcherPrivate
6 {
7 GArray * bad_prefixes;
8+ GArray * good_prefixes;
9 GArray * known_pids;
10 GHashTable * desktop_id_table;
11 GHashTable * desktop_file_table;
12@@ -297,7 +298,9 @@
13 get_open_office_window_hint (BamfMatcher * self, BamfLegacyWindow * window)
14 {
15 const gchar *name;
16+ const gchar *class;
17 char *exec = NULL;
18+ BamfWindowType type;
19 GHashTable *desktopFileTable;
20 GList *list;
21
22@@ -305,8 +308,8 @@
23 g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (window), NULL);
24
25 name = bamf_legacy_window_get_name (window);
26- const gchar *class = bamf_legacy_window_get_class_name (window);
27- BamfWindowType type = bamf_legacy_window_get_window_type (window);
28+ class = bamf_legacy_window_get_class_name (window);
29+ type = bamf_legacy_window_get_window_type (window);
30
31 if (name == NULL && class == NULL)
32 return NULL;
33@@ -418,6 +421,7 @@
34 gchar **parts;
35 gint i, j;
36 gboolean regexFail;
37+ gboolean goodPrefix = FALSE;
38 GRegex *regex;
39
40 if (!execString || (execString && execString[0] == '\0'))
41@@ -431,29 +435,57 @@
42 {
43 part = parts[i];
44
45- if (!g_str_has_prefix (part, "-"))
46+ if (part[0] != '-')
47 {
48- tmp = g_utf8_strrchr (part, -1, G_DIR_SEPARATOR);
49- if (tmp)
50- part = tmp + 1;
51-
52- regexFail = FALSE;
53- for (j = 0; j < self->priv->bad_prefixes->len; j++)
54- {
55- regex = g_array_index (self->priv->bad_prefixes, GRegex *, j);
56- if (g_regex_match (regex, part, 0, NULL))
57- {
58- regexFail = TRUE;
59+ if (goodPrefix)
60+ {
61+ gchar *tmp = g_strconcat (result, " ", part, NULL);
62+ g_free (result);
63+ result = tmp;
64+ }
65+ else
66+ {
67+ for (j = 0; j < self->priv->good_prefixes->len; j++)
68+ {
69+ regex = g_array_index (self->priv->good_prefixes, GRegex *, j);
70+ if (g_regex_match (regex, part, 0, NULL))
71+ {
72+ goodPrefix = TRUE;
73+ result = g_strdup (part);
74+ break;
75+ }
76+ }
77+ }
78+
79+ if (!goodPrefix)
80+ {
81+ tmp = g_utf8_strrchr (part, -1, G_DIR_SEPARATOR);
82+ if (tmp)
83+ part = tmp + 1;
84+
85+ regexFail = FALSE;
86+ for (j = 0; j < self->priv->bad_prefixes->len; j++)
87+ {
88+ regex = g_array_index (self->priv->bad_prefixes, GRegex *, j);
89+ if (g_regex_match (regex, part, 0, NULL))
90+ {
91+ regexFail = TRUE;
92+ break;
93+ }
94+ }
95+
96+ if (!regexFail)
97+ {
98+ result = g_strdup (part);
99 break;
100 }
101 }
102+ }
103+ else if (goodPrefix)
104+ {
105+ break;
106+ }
107
108- if (!regexFail)
109- {
110- result = g_strdup (part);
111- break;
112- }
113- }
114 i++;
115 }
116
117@@ -479,7 +511,7 @@
118 }
119
120 static GArray *
121-prefix_strings (BamfMatcher * self)
122+bad_prefix_strings (void)
123 {
124 GArray *arr = g_array_new (FALSE, TRUE, sizeof (char *));
125
126@@ -514,6 +546,17 @@
127 }
128
129 static GArray *
130+good_prefix_strings (void)
131+{
132+ GArray *arr = g_array_new (FALSE, TRUE, sizeof (char *));
133+
134+ char *str = "^gnome-control-center$";
135+ g_array_append_val (arr, str);
136+
137+ return arr;
138+}
139+
140+static GArray *
141 pid_parent_tree (BamfMatcher *self, gint pid)
142 {
143 BamfMatcherPrivate *priv;
144@@ -1269,11 +1312,8 @@
145 }
146
147 static char *
148-get_window_hint (BamfMatcher *self,
149- BamfLegacyWindow *window,
150- const char *atom_name)
151+get_window_hint (BamfLegacyWindow *window, const char *atom_name)
152 {
153- g_return_val_if_fail (BAMF_IS_MATCHER (self), NULL);
154 g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (window), NULL);
155
156 Window xid = bamf_legacy_window_get_xid (window);
157@@ -1281,12 +1321,8 @@
158 }
159
160 static void
161-set_window_hint (BamfMatcher * self,
162- BamfLegacyWindow * window,
163- const char *atom_name,
164- const char *data)
165+set_window_hint (BamfLegacyWindow * window, const char *atom_name, const char *data)
166 {
167- g_return_if_fail (BAMF_IS_MATCHER (self));
168 g_return_if_fail (BAMF_LEGACY_WINDOW (window));
169
170 Window xid = bamf_legacy_window_get_xid (window);
171@@ -1452,7 +1488,7 @@
172
173 window = bamf_window_get_window (bamf_window);
174
175- hint = get_window_hint (self, window, _NET_WM_DESKTOP_FILE);
176+ hint = get_window_hint (window, _NET_WM_DESKTOP_FILE);
177 const char *window_class = bamf_legacy_window_get_class_name (window);
178
179 if (hint && hint[0] != '\0' && !is_web_app_window(self, window))
180@@ -1690,7 +1726,7 @@
181 return;
182 }
183
184- window_hint = get_window_hint (self, window, _NET_WM_DESKTOP_FILE);
185+ window_hint = get_window_hint (window, _NET_WM_DESKTOP_FILE);
186 if (window_hint)
187 {
188 if (window_hint[0] != '\0')
189@@ -1732,7 +1768,7 @@
190 g_array_free (pids, TRUE);
191
192 if (window_hint)
193- set_window_hint (self, window, _NET_WM_DESKTOP_FILE, window_hint);
194+ set_window_hint (window, _NET_WM_DESKTOP_FILE, window_hint);
195 }
196
197 static void
198@@ -1769,7 +1805,7 @@
199 char *old_hint;
200 const char *new_hint;
201
202- old_hint = get_window_hint (self, window, _NET_WM_DESKTOP_FILE);
203+ old_hint = get_window_hint (window, _NET_WM_DESKTOP_FILE);
204 new_hint = get_open_office_window_hint (self, window);
205
206 if (new_hint && g_strcmp0 (new_hint, old_hint) != 0)
207@@ -1787,6 +1823,67 @@
208 g_object_unref (window);
209 }
210
211+static char *
212+get_gnome_control_center_window_hint (BamfMatcher * self, BamfLegacyWindow * window)
213+{
214+ gchar *role;
215+ gchar *exec;
216+ GHashTable *desktopFileTable;
217+ GList *list;
218+
219+ g_return_val_if_fail (BAMF_IS_MATCHER (self), NULL);
220+ g_return_val_if_fail (BAMF_IS_LEGACY_WINDOW (window), NULL);
221+
222+ role = get_window_hint (window, WM_WINDOW_ROLE);
223+
224+ if (role && role[0] == '\0')
225+ {
226+ g_free (role);
227+ role = NULL;
228+ }
229+
230+ exec = g_strconcat ("gnome-control-center", (role ? " " : NULL), role, NULL);
231+
232+ desktopFileTable = self->priv->desktop_file_table;
233+ list = g_hash_table_lookup (desktopFileTable, exec);
234+
235+ if (!list && g_strcmp0 ("gnome-control-center", exec) != 0)
236+ {
237+ list = g_hash_table_lookup (desktopFileTable, "gnome-control-center");
238+ }
239+
240+ g_free (exec);
241+
242+ return (list ? (char *) list->data : NULL);
243+}
244+
245+static void
246+on_gnome_control_center_window_name_changed (BamfLegacyWindow *window, BamfMatcher* self)
247+{
248+ g_return_if_fail (BAMF_IS_MATCHER (self));
249+ g_return_if_fail (BAMF_IS_LEGACY_WINDOW (window));
250+
251+ char *old_hint;
252+ const char *new_hint;
253+
254+ old_hint = get_window_hint (window, _NET_WM_DESKTOP_FILE);
255+ new_hint = get_gnome_control_center_window_hint (self, window);
256+
257+ if (new_hint && g_strcmp0 (new_hint, old_hint) != 0)
258+ {
259+ bamf_legacy_window_reopen (window);
260+ }
261+
262+ g_free (old_hint);
263+}
264+
265+static void
266+on_gnome_control_center_window_closed (BamfLegacyWindow *window, BamfMatcher* self)
267+{
268+ g_signal_handlers_disconnect_by_func (window, on_gnome_control_center_window_name_changed, self);
269+ g_object_unref (window);
270+}
271+
272 static void
273 handle_window_opened (BamfLegacyScreen * screen, BamfLegacyWindow * window, BamfMatcher *self)
274 {
275@@ -1813,12 +1910,12 @@
276 return;
277 }
278
279- char *old_hint = get_window_hint (self, window, _NET_WM_DESKTOP_FILE);
280+ char *old_hint = get_window_hint (window, _NET_WM_DESKTOP_FILE);
281 const char *new_hint = get_open_office_window_hint (self, window);
282
283 if (new_hint && g_strcmp0 (old_hint, new_hint) != 0)
284 {
285- set_window_hint (self, window, _NET_WM_DESKTOP_FILE, new_hint);
286+ set_window_hint (window, _NET_WM_DESKTOP_FILE, new_hint);
287 }
288
289 g_object_ref (window);
290@@ -1827,6 +1924,22 @@
291
292 g_free (old_hint);
293 }
294+ else if (g_strcmp0 (bamf_legacy_window_get_class_name (window), "Gnome-control-center") == 0)
295+ {
296+ char *old_hint = get_window_hint (window, _NET_WM_DESKTOP_FILE);
297+ const char *new_hint = get_gnome_control_center_window_hint (self, window);
298+
299+ if (new_hint && g_strcmp0 (old_hint, new_hint) != 0)
300+ {
301+ set_window_hint (window, _NET_WM_DESKTOP_FILE, new_hint);
302+ }
303+
304+ g_object_ref (window);
305+ g_signal_connect (window, "name-changed", (GCallback) on_gnome_control_center_window_name_changed, self);
306+ g_signal_connect (window, "closed", (GCallback) on_gnome_control_center_window_closed, self);
307+
308+ g_free (old_hint);
309+ }
310
311 /* we have a window who is ready to be matched */
312 handle_raw_window (self, window);
313@@ -2567,17 +2680,26 @@
314
315 priv->known_pids = g_array_new (FALSE, TRUE, sizeof (gint));
316 priv->bad_prefixes = g_array_new (FALSE, TRUE, sizeof (GRegex *));
317+ priv->good_prefixes = g_array_new (FALSE, TRUE, sizeof (GRegex *));
318 priv->registered_pids = g_hash_table_new_full (g_direct_hash, g_direct_equal,
319 NULL, g_free);
320
321- prefixstrings = prefix_strings (self);
322+ prefixstrings = bad_prefix_strings ();
323 for (i = 0; i < prefixstrings->len; i++)
324 {
325 char *str = g_array_index (prefixstrings, char *, i);
326 GRegex *regex = g_regex_new (str, G_REGEX_OPTIMIZE, 0, NULL);
327 g_array_append_val (priv->bad_prefixes, regex);
328 }
329+ g_array_free (prefixstrings, TRUE);
330
331+ prefixstrings = good_prefix_strings ();
332+ for (i = 0; i < prefixstrings->len; i++)
333+ {
334+ char *str = g_array_index (prefixstrings, char *, i);
335+ GRegex *regex = g_regex_new (str, G_REGEX_OPTIMIZE, 0, NULL);
336+ g_array_append_val (priv->good_prefixes, regex);
337+ }
338 g_array_free (prefixstrings, TRUE);
339
340 create_desktop_file_table (self, &(priv->desktop_file_table),
341@@ -2670,7 +2792,14 @@
342 g_regex_unref (regex);
343 }
344
345+ for (i = 0; i < priv->good_prefixes->len; i++)
346+ {
347+ GRegex *regex = g_array_index (priv->good_prefixes, GRegex *, i);
348+ g_regex_unref (regex);
349+ }
350+
351 g_array_free (priv->bad_prefixes, TRUE);
352+ g_array_free (priv->good_prefixes, TRUE);
353 g_array_free (priv->known_pids, TRUE);
354 g_hash_table_destroy (priv->desktop_id_table);
355 g_hash_table_destroy (priv->desktop_file_table);
356
357=== modified file 'src/bamf-matcher.h'
358--- src/bamf-matcher.h 2012-01-09 18:02:45 +0000
359+++ src/bamf-matcher.h 2012-01-26 14:33:26 +0000
360@@ -46,6 +46,7 @@
361 #define BAMF_MATCHER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), BAMF_TYPE_MATCHER, BamfMatcherClass))
362
363 #define _NET_WM_DESKTOP_FILE "_NET_WM_DESKTOP_FILE"
364+#define WM_WINDOW_ROLE "WM_WINDOW_ROLE"
365
366 typedef struct _BamfMatcher BamfMatcher;
367 typedef struct _BamfMatcherClass BamfMatcherClass;

Subscribers

People subscribed via source and target branches