Merge lp:~3v1n0/bamf/better-lib-caching into lp:bamf
- better-lib-caching
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Stephen M. Webb |
Approved revision: | 639 |
Merged at revision: | 617 |
Proposed branch: | lp:~3v1n0/bamf/better-lib-caching |
Merge into: | lp:bamf |
Diff against target: |
846 lines (+357/-74) 14 files modified
configure.ac (+1/-0) debian/control (+1/-0) debian/libbamf3-2.symbols (+4/-0) lib/libbamf/Makefile.am (+1/-1) lib/libbamf/bamf-application.c (+66/-15) lib/libbamf/bamf-application.h (+4/-0) lib/libbamf/bamf-factory.c (+57/-0) lib/libbamf/bamf-factory.h (+9/-2) lib/libbamf/bamf-matcher.c (+149/-45) lib/libbamf/bamf-matcher.h (+3/-0) lib/libbamf/bamf-view.c (+52/-9) lib/libbamf/bamf-view.h (+4/-0) tests/bamfdaemon/Makefile.am (+3/-1) tests/libbamf/Makefile.am (+3/-1) |
To merge this branch: | bzr merge lp:~3v1n0/bamf/better-lib-caching |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Stephen M. Webb (community) | Needs Fixing | ||
PS Jenkins bot (community) | continuous-integration | Approve | |
Christopher Townsend | Approve | ||
Review via email: mp+257002@code.launchpad.net |
Commit message
libBAMF: cache active{
Add new methods in matcher, view and application.
Description of the change
Reduce DBus chatting between libbamf and bamfdaemon for retrieving informations that have been already sent using signals or previous calls.
Try to reduce the data usage, and include new methods to implement some common features that clients had to do by hand so far.
PS Jenkins bot (ps-jenkins) wrote : | # |
- 632. By Marco Trevisan (Treviño)
-
configure.ac: define LIBBAMF_SONAME in a global place
- 633. By Marco Trevisan (Treviño)
-
debian: bump version to 0.5.2~bzr and SONAME
- 634. By Marco Trevisan (Treviño)
-
gir1.2-
bamf-3. install: work with both multi-arch and not
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:634
http://
Executed test runs:
UNSTABLE: http://
UNSTABLE: http://
deb: http://
Click here to trigger a rebuild:
http://
- 635. By Marco Trevisan (Treviño)
-
Makefile.am: tests, use realpath to fix tests when using builddir != srcdir
- 636. By Marco Trevisan (Treviño)
-
debian/control: add hicolor-icon-theme ad build dependency
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:634
http://
Executed test runs:
None: http://
None: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:636
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
- 637. By Marco Trevisan (Treviño)
-
BamfApplication: fix a typo in Return annotation
- 638. By Marco Trevisan (Treviño)
-
BamfView: fix virtual annotation to respect new standard
Christopher Townsend (townsend) wrote : | # |
Ok, seems fine to me.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:638
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Stephen M. Webb (bregma) wrote : | # |
debian/changelog entry is in the wrong format to be picked up by the ci-train merger. See https:/
- 639. By Marco Trevisan (Treviño)
-
debian/changelog: setting distro as UNRELEASED
- 640. By Marco Trevisan (Treviño)
-
libbamf, BamfMatcher: use a g_warning not to crash if matcher can't be reached
- 641. By Marco Trevisan (Treviño)
-
Libbamf: revert soname change
- 642. By Marco Trevisan (Treviño)
-
Merging with trunk
- 643. By Marco Trevisan (Treviño)
-
debian/
gir1.2- bamf-3. install: only support multi-arch
Preview Diff
1 | === modified file 'configure.ac' |
2 | --- configure.ac 2015-04-21 11:11:10 +0000 |
3 | +++ configure.ac 2015-11-03 10:05:35 +0000 |
4 | @@ -4,6 +4,7 @@ |
5 | AC_INIT(bamf, 0.5.2, dx-team@canonical.com) |
6 | AC_PREREQ(2.69) |
7 | AC_SUBST(LIBBAMF_VER, 3) |
8 | +AC_SUBST(LIBBAMF_SONAME, 2:0:0) |
9 | |
10 | AC_CONFIG_SRCDIR(src/main.c) |
11 | AC_CONFIG_HEADERS(config.h) |
12 | |
13 | === modified file 'debian/control' |
14 | --- debian/control 2015-06-27 04:40:27 +0000 |
15 | +++ debian/control 2015-11-03 10:05:35 +0000 |
16 | @@ -8,6 +8,7 @@ |
17 | dh-autoreconf, |
18 | gobject-introspection (>= 1.41.4-1~), |
19 | gtk-doc-tools, |
20 | + hicolor-icon-theme, |
21 | libglib2.0-dev (>= 2.32.0), |
22 | libgtop2-dev, |
23 | libgtk-3-dev (>= 3.0.0), |
24 | |
25 | === modified file 'debian/libbamf3-2.symbols' |
26 | --- debian/libbamf3-2.symbols 2013-08-09 15:24:39 +0000 |
27 | +++ debian/libbamf3-2.symbols 2015-11-03 10:05:35 +0000 |
28 | @@ -7,6 +7,7 @@ |
29 | bamf_application_get_supported_mime_types@Base 0.3.0 |
30 | bamf_application_get_type@Base 0.2.20 |
31 | bamf_application_get_windows@Base 0.2.20 |
32 | + bamf_application_get_window_for_xid@Base 0.5.2~bzr0 |
33 | bamf_application_get_xids@Base 0.2.20 |
34 | bamf_application_new@Base 0.2.20 |
35 | bamf_application_new_favorite@Base 0.2.60 |
36 | @@ -27,6 +28,7 @@ |
37 | bamf_matcher_get_running_applications@Base 0.2.20 |
38 | bamf_matcher_get_tabs@Base 0.2.20 |
39 | bamf_matcher_get_type@Base 0.2.20 |
40 | + bamf_matcher_get_window_for_xid@Base 0.5.2~bzr0 |
41 | bamf_matcher_get_window_stack_for_monitor@Base 0.2.108 |
42 | bamf_matcher_get_windows@Base 0.2.46 |
43 | bamf_matcher_get_xids_for_application@Base 0.2.20 |
44 | @@ -47,12 +49,14 @@ |
45 | bamf_view_get_type@Base 0.2.20 |
46 | bamf_view_get_view_type@Base 0.2.20 |
47 | bamf_view_is_active@Base 0.2.20 |
48 | + bamf_view_has_child@Base 0.5.2~bzr0 |
49 | bamf_view_is_closed@Base 0.2.54 |
50 | bamf_view_is_running@Base 0.2.20 |
51 | bamf_view_is_sticky@Base 0.2.60 |
52 | bamf_view_is_urgent@Base 0.2.20 |
53 | bamf_view_is_user_visible@Base 0.4.0 |
54 | bamf_view_set_sticky@Base 0.2.60 |
55 | + bamf_view_peek_children@Base 0.5.2~bzr0 |
56 | bamf_view_user_visible@Base 0.2.20 |
57 | bamf_window_get_monitor@Base 0.2.108 |
58 | bamf_window_get_pid@Base 0.2.112 |
59 | |
60 | === modified file 'lib/libbamf/Makefile.am' |
61 | --- lib/libbamf/Makefile.am 2013-08-09 15:42:38 +0000 |
62 | +++ lib/libbamf/Makefile.am 2015-11-03 10:05:35 +0000 |
63 | @@ -57,7 +57,7 @@ |
64 | libbamf_la_LDFLAGS = \ |
65 | -shared \ |
66 | -export-symbols-regex "^bamf_" \ |
67 | - -version-info 2:0:0 \ |
68 | + -version-info $(LIBBAMF_SONAME) \ |
69 | $(COVERAGE_LDFLAGS) \ |
70 | $(NULL) |
71 | |
72 | |
73 | === modified file 'lib/libbamf/bamf-application.c' |
74 | --- lib/libbamf/bamf-application.c 2014-03-07 17:22:20 +0000 |
75 | +++ lib/libbamf/bamf-application.c 2015-11-03 10:05:35 +0000 |
76 | @@ -251,6 +251,7 @@ |
77 | GVariantIter *iter; |
78 | GVariant *xids_variant; |
79 | GArray *xids; |
80 | + GList *children, *l; |
81 | guint32 xid; |
82 | GError *error = NULL; |
83 | |
84 | @@ -260,6 +261,24 @@ |
85 | if (!_bamf_view_remote_ready (BAMF_VIEW (application))) |
86 | return NULL; |
87 | |
88 | + children = bamf_view_peek_children (BAMF_VIEW (application)); |
89 | + |
90 | + if (children) |
91 | + { |
92 | + xids = g_array_new (FALSE, TRUE, sizeof (guint32)); |
93 | + |
94 | + for (l = children; l; l = l->next) |
95 | + { |
96 | + if (!BAMF_IS_WINDOW (l->data)) |
97 | + continue; |
98 | + |
99 | + xid = bamf_window_get_xid (BAMF_WINDOW (l->data)); |
100 | + g_array_append_val (xids, xid); |
101 | + } |
102 | + |
103 | + return xids; |
104 | + } |
105 | + |
106 | if (!_bamf_dbus_item_application_call_xids_sync (priv->proxy, &xids_variant, |
107 | CANCELLABLE (application), &error)) |
108 | { |
109 | @@ -298,26 +317,60 @@ |
110 | GList * |
111 | bamf_application_get_windows (BamfApplication *application) |
112 | { |
113 | - GList *children, *l; |
114 | - GList *windows = NULL; |
115 | + GList *children, *l, *next; |
116 | BamfView *view; |
117 | |
118 | g_return_val_if_fail (BAMF_IS_APPLICATION (application), NULL); |
119 | |
120 | children = bamf_view_get_children (BAMF_VIEW (application)); |
121 | + l = children; |
122 | |
123 | - for (l = children; l; l = l->next) |
124 | + while (l != NULL) |
125 | { |
126 | view = l->data; |
127 | - |
128 | - if (BAMF_IS_WINDOW (view)) |
129 | - { |
130 | - windows = g_list_prepend (windows, view); |
131 | - } |
132 | - } |
133 | - |
134 | - g_list_free (children); |
135 | - return windows; |
136 | + next = l->next; |
137 | + |
138 | + if (!BAMF_IS_WINDOW (view)) |
139 | + { |
140 | + children = g_list_delete_link (children, l); |
141 | + } |
142 | + l = next; |
143 | + } |
144 | + |
145 | + return children; |
146 | +} |
147 | + |
148 | +/** |
149 | + * bamf_application_get_window_for_xid: |
150 | + * @application: a #BamfApplication |
151 | + * @xid: an X11 Window ID |
152 | + * |
153 | + * Used to fetch the application contains a Window with given @xid. |
154 | + * |
155 | + * Since: 0.5.2 |
156 | + * Returns: (transfer none): a #BamfWindow for the passed @xid or %NULL if not found. |
157 | + */ |
158 | +BamfWindow * |
159 | +bamf_application_get_window_for_xid (BamfApplication *application, |
160 | + guint32 xid) |
161 | +{ |
162 | + GList *l; |
163 | + BamfWindow *window; |
164 | + |
165 | + g_return_val_if_fail (BAMF_IS_APPLICATION (application), FALSE); |
166 | + |
167 | + for (l = bamf_view_peek_children (BAMF_VIEW (application)); l; l = l->next) |
168 | + { |
169 | + if (BAMF_IS_WINDOW (l->data)) |
170 | + { |
171 | + window = BAMF_WINDOW (l->data); |
172 | + |
173 | + if (bamf_window_get_xid (window) == xid) |
174 | + return window; |
175 | + } |
176 | + } |
177 | + |
178 | + return NULL; |
179 | } |
180 | |
181 | /** |
182 | @@ -572,7 +625,7 @@ |
183 | G_CALLBACK (bamf_application_on_supported_mime_types_changed), view); |
184 | |
185 | GList *children, *l; |
186 | - children = bamf_view_get_children (view); |
187 | + children = bamf_view_peek_children (view); |
188 | |
189 | if (priv->cached_xids) |
190 | { |
191 | @@ -588,8 +641,6 @@ |
192 | guint32 xid = bamf_window_get_xid (BAMF_WINDOW (l->data)); |
193 | priv->cached_xids = g_list_prepend (priv->cached_xids, GUINT_TO_POINTER (xid)); |
194 | } |
195 | - |
196 | - g_list_free (children); |
197 | } |
198 | |
199 | static void |
200 | |
201 | === modified file 'lib/libbamf/bamf-application.h' |
202 | --- lib/libbamf/bamf-application.h 2013-08-05 16:18:46 +0000 |
203 | +++ lib/libbamf/bamf-application.h 2015-11-03 10:05:35 +0000 |
204 | @@ -30,6 +30,7 @@ |
205 | |
206 | #include <glib-object.h> |
207 | #include <libbamf/bamf-view.h> |
208 | +#include <libbamf/bamf-window.h> |
209 | |
210 | G_BEGIN_DECLS |
211 | |
212 | @@ -94,6 +95,9 @@ |
213 | |
214 | gboolean bamf_application_get_show_menu_stubs (BamfApplication *application); |
215 | |
216 | +BamfWindow * bamf_application_get_window_for_xid (BamfApplication *application, |
217 | + guint32 xid); |
218 | + |
219 | |
220 | /* Deprecated symbols */ |
221 | G_GNUC_DEPRECATED |
222 | |
223 | === modified file 'lib/libbamf/bamf-factory.c' |
224 | --- lib/libbamf/bamf-factory.c 2013-06-21 17:51:51 +0000 |
225 | +++ lib/libbamf/bamf-factory.c 2015-11-03 10:05:35 +0000 |
226 | @@ -54,6 +54,7 @@ |
227 | static BamfFactory *static_factory = NULL; |
228 | |
229 | static void on_view_weak_unref (BamfFactory *self, BamfView *view_was_here); |
230 | +static void on_view_closed (BamfView *view, BamfFactory *self); |
231 | |
232 | static void |
233 | bamf_factory_dispose (GObject *object) |
234 | @@ -66,6 +67,7 @@ |
235 | for (l = self->priv->allocated_views, next = NULL; l; l = next) |
236 | { |
237 | g_object_weak_unref (G_OBJECT (l->data), (GWeakNotify) on_view_weak_unref, self); |
238 | + g_signal_handlers_disconnect_by_func (l->data, on_view_closed, self); |
239 | next = l->next; |
240 | g_list_free1 (l); |
241 | } |
242 | @@ -183,6 +185,33 @@ |
243 | G_CALLBACK (on_view_closed), self); |
244 | } |
245 | |
246 | +BamfWindow * |
247 | +_bamf_factory_window_for_xid (BamfFactory * factory, |
248 | + guint32 xid) |
249 | +{ |
250 | + BamfWindow *result = NULL, *win; |
251 | + GList *l; |
252 | + |
253 | + for (l = factory->priv->allocated_views; l; l = l->next) |
254 | + { |
255 | + if (!BAMF_IS_WINDOW (l->data)) |
256 | + continue; |
257 | + |
258 | + if (bamf_view_is_closed (l->data)) |
259 | + continue; |
260 | + |
261 | + win = BAMF_WINDOW (l->data); |
262 | + |
263 | + if (bamf_window_get_xid (win) == xid) |
264 | + { |
265 | + result = win; |
266 | + break; |
267 | + } |
268 | + } |
269 | + |
270 | + return result; |
271 | +} |
272 | + |
273 | BamfApplication * |
274 | _bamf_factory_app_for_file (BamfFactory * factory, |
275 | const char * path, |
276 | @@ -220,6 +249,34 @@ |
277 | return result; |
278 | } |
279 | |
280 | +BamfApplication * |
281 | +_bamf_factory_app_for_xid (BamfFactory * factory, |
282 | + guint32 xid) |
283 | +{ |
284 | + BamfApplication *result = NULL, *app; |
285 | + GList *l, *local_children; |
286 | + |
287 | + for (l = factory->priv->allocated_views; l; l = l->next) |
288 | + { |
289 | + if (!BAMF_IS_APPLICATION (l->data)) |
290 | + continue; |
291 | + |
292 | + if (bamf_view_is_closed (l->data)) |
293 | + continue; |
294 | + |
295 | + app = BAMF_APPLICATION (l->data); |
296 | + local_children = _bamf_application_get_cached_xids (app); |
297 | + |
298 | + if (g_list_find (local_children, GUINT_TO_POINTER (xid))) |
299 | + { |
300 | + result = app; |
301 | + break; |
302 | + } |
303 | + } |
304 | + |
305 | + return result; |
306 | +} |
307 | + |
308 | static |
309 | BamfFactoryViewType compute_factory_type_by_str (const char *type) |
310 | { |
311 | |
312 | === modified file 'lib/libbamf/bamf-factory.h' |
313 | --- lib/libbamf/bamf-factory.h 2013-06-08 13:54:06 +0000 |
314 | +++ lib/libbamf/bamf-factory.h 2015-11-03 10:05:35 +0000 |
315 | @@ -30,6 +30,7 @@ |
316 | |
317 | #include <glib-object.h> |
318 | #include <libbamf/bamf-view.h> |
319 | +#include <libbamf/bamf-window.h> |
320 | #include <libbamf/bamf-application.h> |
321 | |
322 | G_BEGIN_DECLS |
323 | @@ -89,9 +90,15 @@ |
324 | const char * path, |
325 | const char * type); |
326 | |
327 | +BamfWindow * _bamf_factory_window_for_xid (BamfFactory * factory, |
328 | + guint32 xid); |
329 | + |
330 | BamfApplication * _bamf_factory_app_for_file (BamfFactory * factory, |
331 | - const char * path, |
332 | - gboolean create); |
333 | + const char * path, |
334 | + gboolean create); |
335 | + |
336 | +BamfApplication * _bamf_factory_app_for_xid (BamfFactory * factory, |
337 | + guint32 xid); |
338 | |
339 | BamfFactory * _bamf_factory_get_default (void); |
340 | |
341 | |
342 | === modified file 'lib/libbamf/bamf-matcher.c' |
343 | --- lib/libbamf/bamf-matcher.c 2013-06-13 22:20:25 +0000 |
344 | +++ lib/libbamf/bamf-matcher.c 2015-11-03 10:05:35 +0000 |
345 | @@ -63,6 +63,9 @@ |
346 | { |
347 | BamfDBusMatcher *proxy; |
348 | GCancellable *cancellable; |
349 | + |
350 | + BamfWindow *active_window; |
351 | + BamfApplication *active_application; |
352 | }; |
353 | |
354 | static BamfMatcher * default_matcher = NULL; |
355 | @@ -129,6 +132,47 @@ |
356 | } |
357 | |
358 | |
359 | +static gboolean |
360 | +track_ptr (GType wanted_type, |
361 | + BamfView *active, |
362 | + gpointer *cache_pointer) |
363 | +{ |
364 | + if (G_TYPE_CHECK_INSTANCE_TYPE (active, wanted_type)) |
365 | + { |
366 | + if (*cache_pointer == active) |
367 | + return FALSE; |
368 | + |
369 | + *cache_pointer = active; |
370 | + g_object_add_weak_pointer (G_OBJECT (active), cache_pointer); |
371 | + return TRUE; |
372 | + } |
373 | + else if (G_TYPE_CHECK_INSTANCE_TYPE (*cache_pointer, wanted_type)) |
374 | + { |
375 | + g_object_remove_weak_pointer (G_OBJECT (*cache_pointer), cache_pointer); |
376 | + *cache_pointer = NULL; |
377 | + return TRUE; |
378 | + } |
379 | + |
380 | + return FALSE; |
381 | +} |
382 | + |
383 | +static void |
384 | +bamf_matcher_on_name_owner_changed (BamfDBusMatcher *proxy, |
385 | + GParamSpec *param, |
386 | + BamfMatcher *matcher) |
387 | +{ |
388 | + /* This is called when the bamfdaemon is killed / started */ |
389 | + gchar *name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (proxy)); |
390 | + |
391 | + if (!name_owner) |
392 | + { |
393 | + track_ptr (BAMF_TYPE_APPLICATION, NULL, (gpointer *) &matcher->priv->active_application); |
394 | + track_ptr (BAMF_TYPE_WINDOW, NULL, (gpointer *) &matcher->priv->active_window); |
395 | + } |
396 | + |
397 | + g_free (name_owner); |
398 | +} |
399 | + |
400 | static void |
401 | bamf_matcher_on_view_opened (BamfDBusMatcher *proxy, |
402 | const char *path, |
403 | @@ -175,12 +219,17 @@ |
404 | { |
405 | BamfView *old_view; |
406 | BamfView *new_view; |
407 | - |
408 | - BamfFactory *factory = _bamf_factory_get_default (); |
409 | + BamfFactory *factory; |
410 | + |
411 | + factory = _bamf_factory_get_default (); |
412 | + |
413 | old_view = _bamf_factory_view_for_path_type (factory, old_path, BAMF_FACTORY_APPLICATION); |
414 | new_view = _bamf_factory_view_for_path_type (factory, new_path, BAMF_FACTORY_APPLICATION); |
415 | |
416 | - g_signal_emit (matcher, matcher_signals[ACTIVE_APPLICATION_CHANGED], 0, old_view, new_view); |
417 | + if (track_ptr (BAMF_TYPE_APPLICATION, new_view, (gpointer *) &matcher->priv->active_application)) |
418 | + { |
419 | + g_signal_emit (matcher, matcher_signals[ACTIVE_APPLICATION_CHANGED], 0, old_view, new_view); |
420 | + } |
421 | } |
422 | |
423 | static void |
424 | @@ -191,12 +240,31 @@ |
425 | { |
426 | BamfView *old_view; |
427 | BamfView *new_view; |
428 | - |
429 | - BamfFactory *factory = _bamf_factory_get_default (); |
430 | + BamfApplication *old_app; |
431 | + BamfApplication *new_app; |
432 | + BamfFactory *factory; |
433 | + BamfMatcherPrivate *priv; |
434 | + |
435 | + priv = matcher->priv; |
436 | + old_app = priv->active_application; |
437 | + new_app = old_app; |
438 | + factory = _bamf_factory_get_default (); |
439 | + |
440 | old_view = _bamf_factory_view_for_path_type (factory, old_path, BAMF_FACTORY_WINDOW); |
441 | new_view = _bamf_factory_view_for_path_type (factory, new_path, BAMF_FACTORY_WINDOW); |
442 | |
443 | + track_ptr (BAMF_TYPE_WINDOW, new_view, (gpointer *) &priv->active_window); |
444 | + |
445 | + if (BAMF_IS_WINDOW (new_view)) |
446 | + new_app = _bamf_factory_app_for_xid (factory, bamf_window_get_xid (BAMF_WINDOW (new_view))); |
447 | + |
448 | + track_ptr (BAMF_TYPE_APPLICATION, (BamfView *) new_app, (gpointer *) &priv->active_application); |
449 | g_signal_emit (matcher, matcher_signals[ACTIVE_WINDOW_CHANGED], 0, old_view, new_view); |
450 | + |
451 | + if (new_app != old_app) |
452 | + { |
453 | + g_signal_emit (matcher, matcher_signals[ACTIVE_APPLICATION_CHANGED], 0, old_app, new_app); |
454 | + } |
455 | } |
456 | |
457 | static void |
458 | @@ -221,12 +289,15 @@ |
459 | |
460 | if (error) |
461 | { |
462 | - g_error ("Unable to get %s matcher: %s", BAMF_DBUS_SERVICE_NAME, error ? error->message : ""); |
463 | + g_warning ("Unable to get %s matcher: %s", BAMF_DBUS_SERVICE_NAME, error ? error->message : ""); |
464 | g_error_free (error); |
465 | } |
466 | |
467 | g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (priv->proxy), BAMF_DBUS_DEFAULT_TIMEOUT); |
468 | |
469 | + g_signal_connect (priv->proxy, "notify::g-name-owner", |
470 | + G_CALLBACK (bamf_matcher_on_name_owner_changed), self); |
471 | + |
472 | g_signal_connect (priv->proxy, "view-opened", |
473 | G_CALLBACK (bamf_matcher_on_view_opened), self); |
474 | |
475 | @@ -303,30 +374,30 @@ |
476 | g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL); |
477 | priv = matcher->priv; |
478 | |
479 | + if (BAMF_IS_APPLICATION (priv->active_application)) |
480 | + { |
481 | + if (!bamf_view_is_closed (BAMF_VIEW (priv->active_application))) |
482 | + return priv->active_application; |
483 | + } |
484 | + |
485 | if (!_bamf_dbus_matcher_call_active_application_sync (priv->proxy, &app, priv->cancellable, &error)) |
486 | { |
487 | g_warning ("Failed to get active application: %s", error ? error->message : ""); |
488 | g_error_free (error); |
489 | - return NULL; |
490 | - } |
491 | - |
492 | - if (app && app[0] == '\0') |
493 | - { |
494 | - g_free (app); |
495 | - return NULL; |
496 | - } |
497 | - |
498 | - if (!app) |
499 | - return NULL; |
500 | + track_ptr (BAMF_TYPE_APPLICATION, NULL, (gpointer *) &priv->active_application); |
501 | + return NULL; |
502 | + } |
503 | |
504 | BamfFactory *factory = _bamf_factory_get_default (); |
505 | view = _bamf_factory_view_for_path_type (factory, app, BAMF_FACTORY_APPLICATION); |
506 | g_free (app); |
507 | |
508 | if (!BAMF_IS_APPLICATION (view)) |
509 | - return NULL; |
510 | - |
511 | - return BAMF_APPLICATION (view); |
512 | + view = NULL; |
513 | + |
514 | + track_ptr (BAMF_TYPE_APPLICATION, view, (gpointer *) &priv->active_application); |
515 | + |
516 | + return priv->active_application; |
517 | } |
518 | |
519 | /** |
520 | @@ -348,30 +419,60 @@ |
521 | g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL); |
522 | priv = matcher->priv; |
523 | |
524 | + if (BAMF_IS_APPLICATION (priv->active_window)) |
525 | + { |
526 | + if (!bamf_view_is_closed (BAMF_VIEW (priv->active_window))) |
527 | + return priv->active_window; |
528 | + } |
529 | + |
530 | if (!_bamf_dbus_matcher_call_active_window_sync (priv->proxy, &win, priv->cancellable, &error)) |
531 | { |
532 | g_warning ("Failed to get active window: %s", error ? error->message : ""); |
533 | g_error_free (error); |
534 | - return NULL; |
535 | - } |
536 | - |
537 | - if (win && win[0] == '\0') |
538 | - { |
539 | - g_free (win); |
540 | - return NULL; |
541 | - } |
542 | - |
543 | - if (!win) |
544 | - return NULL; |
545 | + track_ptr (BAMF_TYPE_WINDOW, NULL, (gpointer *) &priv->active_window); |
546 | + return NULL; |
547 | + } |
548 | |
549 | BamfFactory *factory = _bamf_factory_get_default (); |
550 | view = _bamf_factory_view_for_path_type (factory, win, BAMF_FACTORY_WINDOW); |
551 | g_free (win); |
552 | |
553 | if (!BAMF_IS_WINDOW (view)) |
554 | - return NULL; |
555 | - |
556 | - return BAMF_WINDOW (view); |
557 | + view = NULL; |
558 | + |
559 | + track_ptr (BAMF_TYPE_WINDOW, view, (gpointer *) &priv->active_window); |
560 | + |
561 | + return priv->active_window; |
562 | +} |
563 | + |
564 | +/** |
565 | + * bamf_matcher_get_window_for_xid: |
566 | + * @matcher: a #BamfMatcher |
567 | + * @xid: The X11 Window ID to search for |
568 | + * |
569 | + * Used to fetch the #BamfWindow that wraps the given @window. |
570 | + * |
571 | + * Returns: (transfer none): The #BamfWindow representing the xid passed, or NULL if none exists. |
572 | + */ |
573 | +BamfWindow * |
574 | +bamf_matcher_get_window_for_xid (BamfMatcher *matcher, guint32 xid) |
575 | +{ |
576 | + BamfWindow *window; |
577 | + BamfApplication *app; |
578 | + |
579 | + g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL); |
580 | + |
581 | + window = _bamf_factory_window_for_xid (_bamf_factory_get_default (), xid); |
582 | + |
583 | + if (BAMF_IS_WINDOW (window)) |
584 | + return window; |
585 | + |
586 | + app = bamf_matcher_get_application_for_xid (matcher, xid); |
587 | + |
588 | + if (BAMF_IS_APPLICATION (app)) |
589 | + window = bamf_application_get_window_for_xid (app, xid); |
590 | + |
591 | + return BAMF_IS_WINDOW (window) ? window : NULL; |
592 | } |
593 | |
594 | /** |
595 | @@ -386,7 +487,7 @@ |
596 | BamfApplication * |
597 | bamf_matcher_get_application_for_window (BamfMatcher *matcher, BamfWindow *window) |
598 | { |
599 | - g_return_val_if_fail(BAMF_IS_WINDOW(window), NULL); |
600 | + g_return_val_if_fail (BAMF_IS_WINDOW (window), NULL); |
601 | return bamf_matcher_get_application_for_xid (matcher, bamf_window_get_xid(window)); |
602 | } |
603 | |
604 | @@ -404,11 +505,18 @@ |
605 | { |
606 | BamfMatcherPrivate *priv; |
607 | BamfView *view; |
608 | + BamfFactory *factory; |
609 | char *app = NULL; |
610 | GError *error = NULL; |
611 | |
612 | g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL); |
613 | priv = matcher->priv; |
614 | + factory = _bamf_factory_get_default (); |
615 | + |
616 | + view = (BamfView*) _bamf_factory_app_for_xid (factory, xid); |
617 | + |
618 | + if (BAMF_IS_APPLICATION (view)) |
619 | + return BAMF_APPLICATION (view); |
620 | |
621 | if (!_bamf_dbus_matcher_call_application_for_xid_sync (priv->proxy, xid, &app, priv->cancellable, &error)) |
622 | { |
623 | @@ -417,16 +525,6 @@ |
624 | return NULL; |
625 | } |
626 | |
627 | - if (app && app[0] == '\0') |
628 | - { |
629 | - g_free (app); |
630 | - return NULL; |
631 | - } |
632 | - |
633 | - if (!app) |
634 | - return NULL; |
635 | - |
636 | - BamfFactory *factory = _bamf_factory_get_default (); |
637 | view = _bamf_factory_view_for_path_type (factory, app, BAMF_FACTORY_APPLICATION); |
638 | g_free (app); |
639 | |
640 | @@ -440,12 +538,18 @@ |
641 | bamf_matcher_application_is_running (BamfMatcher *matcher, const gchar *app) |
642 | { |
643 | BamfMatcherPrivate *priv; |
644 | + BamfApplication *view; |
645 | gboolean running = FALSE; |
646 | GError *error = NULL; |
647 | |
648 | g_return_val_if_fail (BAMF_IS_MATCHER (matcher), FALSE); |
649 | priv = matcher->priv; |
650 | |
651 | + view = _bamf_factory_app_for_file (_bamf_factory_get_default (), app, FALSE); |
652 | + |
653 | + if (BAMF_IS_APPLICATION (view)) |
654 | + return bamf_view_is_running (BAMF_VIEW (view)); |
655 | + |
656 | if (!_bamf_dbus_matcher_call_application_is_running_sync (priv->proxy, |
657 | app ? app : "", |
658 | &running, |
659 | |
660 | === modified file 'lib/libbamf/bamf-matcher.h' |
661 | --- lib/libbamf/bamf-matcher.h 2013-06-08 13:54:06 +0000 |
662 | +++ lib/libbamf/bamf-matcher.h 2015-11-03 10:05:35 +0000 |
663 | @@ -89,6 +89,9 @@ |
664 | |
665 | BamfWindow * bamf_matcher_get_active_window (BamfMatcher *matcher); |
666 | |
667 | +BamfWindow * bamf_matcher_get_window_for_xid (BamfMatcher *matcher, |
668 | + guint32 xid); |
669 | + |
670 | BamfApplication * bamf_matcher_get_application_for_xid (BamfMatcher *matcher, |
671 | guint32 xid); |
672 | BamfApplication * bamf_matcher_get_application_for_window (BamfMatcher *matcher, |
673 | |
674 | === modified file 'lib/libbamf/bamf-view.c' |
675 | --- lib/libbamf/bamf-view.c 2013-10-10 15:04:14 +0000 |
676 | +++ lib/libbamf/bamf-view.c 2015-11-03 10:05:35 +0000 |
677 | @@ -105,6 +105,27 @@ |
678 | GList * |
679 | bamf_view_get_children (BamfView *view) |
680 | { |
681 | + g_return_val_if_fail (BAMF_IS_VIEW (view), NULL); |
682 | + |
683 | + if (BAMF_VIEW_GET_CLASS (view)->get_children) |
684 | + return BAMF_VIEW_GET_CLASS (view)->get_children (view); |
685 | + |
686 | + return g_list_copy (bamf_view_peek_children (view)); |
687 | +} |
688 | + |
689 | +/** |
690 | + * bamf_view_peek_children: |
691 | + * @view: a #BamfView |
692 | + * |
693 | + * Note: Makes sever dbus calls the first time this is called on a view. |
694 | + * Dbus messaging is reduced afterwards. |
695 | + * Since: 0.5.2 |
696 | + * Returns: (element-type Bamf.View) (transfer none): Returns a list of #BamfView which |
697 | + * is owned by the #BamfView and should not freed or modified after usage. |
698 | + */ |
699 | +GList * |
700 | +bamf_view_peek_children (BamfView *view) |
701 | +{ |
702 | char ** children; |
703 | int i, len; |
704 | GList *results = NULL; |
705 | @@ -114,16 +135,13 @@ |
706 | |
707 | g_return_val_if_fail (BAMF_IS_VIEW (view), NULL); |
708 | |
709 | - if (BAMF_VIEW_GET_CLASS (view)->get_children) |
710 | - return BAMF_VIEW_GET_CLASS (view)->get_children (view); |
711 | - |
712 | if (!_bamf_view_remote_ready (view)) |
713 | return NULL; |
714 | |
715 | priv = view->priv; |
716 | |
717 | if (priv->cached_children || !priv->reload_children) |
718 | - return g_list_copy (priv->cached_children); |
719 | + return priv->cached_children; |
720 | |
721 | if (!_bamf_dbus_item_view_call_children_sync (priv->proxy, &children, CANCELLABLE (view), &error)) |
722 | { |
723 | @@ -153,7 +171,30 @@ |
724 | priv->reload_children = FALSE; |
725 | priv->cached_children = results; |
726 | |
727 | - return g_list_copy (priv->cached_children); |
728 | + return priv->cached_children; |
729 | +} |
730 | + |
731 | +/** |
732 | + * bamf_view_has_child: |
733 | + * @view: a #BamfView |
734 | + * |
735 | + * Returns: %TRUE whether the #BamfView @view has the specified @child. |
736 | + */ |
737 | +gboolean |
738 | +bamf_view_has_child (BamfView *view, BamfView *child) |
739 | +{ |
740 | + GList *l; |
741 | + |
742 | + g_return_val_if_fail (BAMF_IS_VIEW (view), FALSE); |
743 | + g_return_val_if_fail (BAMF_IS_VIEW (child), FALSE); |
744 | + |
745 | + for (l = bamf_view_peek_children (view); l; l = l->next) |
746 | + { |
747 | + if (l->data == child) |
748 | + return TRUE; |
749 | + } |
750 | + |
751 | + return FALSE; |
752 | } |
753 | |
754 | /** |
755 | @@ -389,13 +430,11 @@ |
756 | } |
757 | |
758 | /** |
759 | - * bamf_view_get_view_type: |
760 | + * bamf_view_get_view_type: (virtual view_type) |
761 | * @view: a #BamfView |
762 | * |
763 | * The view type of a window is a short string used to represent all views of the same class. These |
764 | * descriptions should not be used to do casting as they are not considered stable. |
765 | - * |
766 | - * Virtual: view_type |
767 | */ |
768 | const gchar * |
769 | bamf_view_get_view_type (BamfView *self) |
770 | @@ -481,6 +520,7 @@ |
771 | { |
772 | BamfView *view; |
773 | BamfViewPrivate *priv; |
774 | + gboolean was_cached = FALSE; |
775 | |
776 | view = _bamf_factory_view_for_path (_bamf_factory_get_default (), path); |
777 | priv = self->priv; |
778 | @@ -499,11 +539,14 @@ |
779 | if (l) |
780 | { |
781 | priv->cached_children = g_list_delete_link (priv->cached_children, l); |
782 | - g_object_unref (view); |
783 | + was_cached = TRUE; |
784 | } |
785 | } |
786 | |
787 | g_signal_emit (G_OBJECT (self), view_signals[CHILD_REMOVED], 0, view); |
788 | + |
789 | + if (was_cached) |
790 | + g_object_unref (view); |
791 | } |
792 | |
793 | static void |
794 | |
795 | === modified file 'lib/libbamf/bamf-view.h' |
796 | --- lib/libbamf/bamf-view.h 2013-08-09 15:32:46 +0000 |
797 | +++ lib/libbamf/bamf-view.h 2015-11-03 10:05:35 +0000 |
798 | @@ -121,6 +121,10 @@ |
799 | |
800 | GList * bamf_view_get_children (BamfView *view); |
801 | |
802 | +GList * bamf_view_peek_children (BamfView *view); |
803 | + |
804 | +gboolean bamf_view_has_child (BamfView *view, BamfView *child); |
805 | + |
806 | gboolean bamf_view_is_closed (BamfView *view); |
807 | |
808 | gboolean bamf_view_is_active (BamfView *view); |
809 | |
810 | === modified file 'tests/bamfdaemon/Makefile.am' |
811 | --- tests/bamfdaemon/Makefile.am 2014-04-07 21:31:21 +0000 |
812 | +++ tests/bamfdaemon/Makefile.am 2015-11-03 10:05:35 +0000 |
813 | @@ -1,3 +1,5 @@ |
814 | +TESTDIR=$(shell realpath $(abs_top_srcdir)/tests) |
815 | + |
816 | noinst_PROGRAMS = \ |
817 | test-bamf |
818 | |
819 | @@ -44,7 +46,7 @@ |
820 | -I$(top_srcdir)/lib \ |
821 | -I$(top_builddir)/lib \ |
822 | -DWNCK_I_KNOW_THIS_IS_UNSTABLE \ |
823 | - -DTESTDIR=\""$(abs_top_srcdir)/tests"\" \ |
824 | + -DTESTDIR=\""$(TESTDIR)"\" \ |
825 | $(COVERAGE_CFLAGS) \ |
826 | $(GCC_FLAGS) \ |
827 | $(GLIB_CFLAGS) \ |
828 | |
829 | === modified file 'tests/libbamf/Makefile.am' |
830 | --- tests/libbamf/Makefile.am 2013-06-21 18:21:31 +0000 |
831 | +++ tests/libbamf/Makefile.am 2015-11-03 10:05:35 +0000 |
832 | @@ -1,3 +1,5 @@ |
833 | +TESTDIR=$(shell realpath $(abs_top_srcdir)/tests) |
834 | + |
835 | noinst_PROGRAMS = \ |
836 | test-libbamf |
837 | |
838 | @@ -12,7 +14,7 @@ |
839 | -I$(top_builddir)/lib \ |
840 | -I$(top_srcdir)/lib/libbamf \ |
841 | -I$(top_builddir)/lib/libbamf \ |
842 | - -DTESTDIR=\""$(abs_top_srcdir)/tests"\" \ |
843 | + -DTESTDIR=\""$(TESTDIR)"\" \ |
844 | $(COVERAGE_CFLAGS) \ |
845 | $(GCC_FLAGS) \ |
846 | $(GLIB_CFLAGS) \ |
FAILED: Continuous integration, rev:631 jenkins. qa.ubuntu. com/job/ bamf-ci/ 111/ jenkins. qa.ubuntu. com/job/ bamf-vivid- amd64-ci/ 7/console jenkins. qa.ubuntu. com/job/ bamf-vivid- armhf-ci/ 7/console
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/bamf- ci/111/ rebuild
http://