Merge lp:~3v1n0/bamf/better-lib-caching into lp:bamf

Proposed by Marco Trevisan (Treviño)
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
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{window,application} and be smarter in reusing known resources

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.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
lp:~3v1n0/bamf/better-lib-caching updated
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

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
lp:~3v1n0/bamf/better-lib-caching updated
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

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
lp:~3v1n0/bamf/better-lib-caching updated
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

Revision history for this message
Christopher Townsend (townsend) wrote :

Ok, seems fine to me.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Stephen M. Webb (bregma) wrote :

debian/changelog entry is in the wrong format to be picked up by the ci-train merger. See https://wiki.ubuntu.com/citrain/FAQ#I_don.27t_like_the_auto-generated_changelog_coming_from_CI_Train and the inline comment.

review: Needs Fixing
lp:~3v1n0/bamf/better-lib-caching updated
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

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'configure.ac'
--- configure.ac 2015-04-21 11:11:10 +0000
+++ configure.ac 2015-11-03 10:05:35 +0000
@@ -4,6 +4,7 @@
4AC_INIT(bamf, 0.5.2, dx-team@canonical.com)4AC_INIT(bamf, 0.5.2, dx-team@canonical.com)
5AC_PREREQ(2.69)5AC_PREREQ(2.69)
6AC_SUBST(LIBBAMF_VER, 3)6AC_SUBST(LIBBAMF_VER, 3)
7AC_SUBST(LIBBAMF_SONAME, 2:0:0)
78
8AC_CONFIG_SRCDIR(src/main.c)9AC_CONFIG_SRCDIR(src/main.c)
9AC_CONFIG_HEADERS(config.h)10AC_CONFIG_HEADERS(config.h)
1011
=== modified file 'debian/control'
--- debian/control 2015-06-27 04:40:27 +0000
+++ debian/control 2015-11-03 10:05:35 +0000
@@ -8,6 +8,7 @@
8 dh-autoreconf,8 dh-autoreconf,
9 gobject-introspection (>= 1.41.4-1~),9 gobject-introspection (>= 1.41.4-1~),
10 gtk-doc-tools,10 gtk-doc-tools,
11 hicolor-icon-theme,
11 libglib2.0-dev (>= 2.32.0),12 libglib2.0-dev (>= 2.32.0),
12 libgtop2-dev,13 libgtop2-dev,
13 libgtk-3-dev (>= 3.0.0),14 libgtk-3-dev (>= 3.0.0),
1415
=== modified file 'debian/libbamf3-2.symbols'
--- debian/libbamf3-2.symbols 2013-08-09 15:24:39 +0000
+++ debian/libbamf3-2.symbols 2015-11-03 10:05:35 +0000
@@ -7,6 +7,7 @@
7 bamf_application_get_supported_mime_types@Base 0.3.07 bamf_application_get_supported_mime_types@Base 0.3.0
8 bamf_application_get_type@Base 0.2.208 bamf_application_get_type@Base 0.2.20
9 bamf_application_get_windows@Base 0.2.209 bamf_application_get_windows@Base 0.2.20
10 bamf_application_get_window_for_xid@Base 0.5.2~bzr0
10 bamf_application_get_xids@Base 0.2.2011 bamf_application_get_xids@Base 0.2.20
11 bamf_application_new@Base 0.2.2012 bamf_application_new@Base 0.2.20
12 bamf_application_new_favorite@Base 0.2.6013 bamf_application_new_favorite@Base 0.2.60
@@ -27,6 +28,7 @@
27 bamf_matcher_get_running_applications@Base 0.2.2028 bamf_matcher_get_running_applications@Base 0.2.20
28 bamf_matcher_get_tabs@Base 0.2.2029 bamf_matcher_get_tabs@Base 0.2.20
29 bamf_matcher_get_type@Base 0.2.2030 bamf_matcher_get_type@Base 0.2.20
31 bamf_matcher_get_window_for_xid@Base 0.5.2~bzr0
30 bamf_matcher_get_window_stack_for_monitor@Base 0.2.10832 bamf_matcher_get_window_stack_for_monitor@Base 0.2.108
31 bamf_matcher_get_windows@Base 0.2.4633 bamf_matcher_get_windows@Base 0.2.46
32 bamf_matcher_get_xids_for_application@Base 0.2.2034 bamf_matcher_get_xids_for_application@Base 0.2.20
@@ -47,12 +49,14 @@
47 bamf_view_get_type@Base 0.2.2049 bamf_view_get_type@Base 0.2.20
48 bamf_view_get_view_type@Base 0.2.2050 bamf_view_get_view_type@Base 0.2.20
49 bamf_view_is_active@Base 0.2.2051 bamf_view_is_active@Base 0.2.20
52 bamf_view_has_child@Base 0.5.2~bzr0
50 bamf_view_is_closed@Base 0.2.5453 bamf_view_is_closed@Base 0.2.54
51 bamf_view_is_running@Base 0.2.2054 bamf_view_is_running@Base 0.2.20
52 bamf_view_is_sticky@Base 0.2.6055 bamf_view_is_sticky@Base 0.2.60
53 bamf_view_is_urgent@Base 0.2.2056 bamf_view_is_urgent@Base 0.2.20
54 bamf_view_is_user_visible@Base 0.4.057 bamf_view_is_user_visible@Base 0.4.0
55 bamf_view_set_sticky@Base 0.2.6058 bamf_view_set_sticky@Base 0.2.60
59 bamf_view_peek_children@Base 0.5.2~bzr0
56 bamf_view_user_visible@Base 0.2.2060 bamf_view_user_visible@Base 0.2.20
57 bamf_window_get_monitor@Base 0.2.10861 bamf_window_get_monitor@Base 0.2.108
58 bamf_window_get_pid@Base 0.2.11262 bamf_window_get_pid@Base 0.2.112
5963
=== modified file 'lib/libbamf/Makefile.am'
--- lib/libbamf/Makefile.am 2013-08-09 15:42:38 +0000
+++ lib/libbamf/Makefile.am 2015-11-03 10:05:35 +0000
@@ -57,7 +57,7 @@
57libbamf_la_LDFLAGS = \57libbamf_la_LDFLAGS = \
58 -shared \58 -shared \
59 -export-symbols-regex "^bamf_" \59 -export-symbols-regex "^bamf_" \
60 -version-info 2:0:0 \60 -version-info $(LIBBAMF_SONAME) \
61 $(COVERAGE_LDFLAGS) \61 $(COVERAGE_LDFLAGS) \
62 $(NULL)62 $(NULL)
6363
6464
=== modified file 'lib/libbamf/bamf-application.c'
--- lib/libbamf/bamf-application.c 2014-03-07 17:22:20 +0000
+++ lib/libbamf/bamf-application.c 2015-11-03 10:05:35 +0000
@@ -251,6 +251,7 @@
251 GVariantIter *iter;251 GVariantIter *iter;
252 GVariant *xids_variant;252 GVariant *xids_variant;
253 GArray *xids;253 GArray *xids;
254 GList *children, *l;
254 guint32 xid;255 guint32 xid;
255 GError *error = NULL;256 GError *error = NULL;
256257
@@ -260,6 +261,24 @@
260 if (!_bamf_view_remote_ready (BAMF_VIEW (application)))261 if (!_bamf_view_remote_ready (BAMF_VIEW (application)))
261 return NULL;262 return NULL;
262263
264 children = bamf_view_peek_children (BAMF_VIEW (application));
265
266 if (children)
267 {
268 xids = g_array_new (FALSE, TRUE, sizeof (guint32));
269
270 for (l = children; l; l = l->next)
271 {
272 if (!BAMF_IS_WINDOW (l->data))
273 continue;
274
275 xid = bamf_window_get_xid (BAMF_WINDOW (l->data));
276 g_array_append_val (xids, xid);
277 }
278
279 return xids;
280 }
281
263 if (!_bamf_dbus_item_application_call_xids_sync (priv->proxy, &xids_variant,282 if (!_bamf_dbus_item_application_call_xids_sync (priv->proxy, &xids_variant,
264 CANCELLABLE (application), &error))283 CANCELLABLE (application), &error))
265 {284 {
@@ -298,26 +317,60 @@
298GList *317GList *
299bamf_application_get_windows (BamfApplication *application)318bamf_application_get_windows (BamfApplication *application)
300{319{
301 GList *children, *l;320 GList *children, *l, *next;
302 GList *windows = NULL;
303 BamfView *view;321 BamfView *view;
304322
305 g_return_val_if_fail (BAMF_IS_APPLICATION (application), NULL);323 g_return_val_if_fail (BAMF_IS_APPLICATION (application), NULL);
306324
307 children = bamf_view_get_children (BAMF_VIEW (application));325 children = bamf_view_get_children (BAMF_VIEW (application));
326 l = children;
308327
309 for (l = children; l; l = l->next)328 while (l != NULL)
310 {329 {
311 view = l->data;330 view = l->data;
312331 next = l->next;
313 if (BAMF_IS_WINDOW (view))332
314 {333 if (!BAMF_IS_WINDOW (view))
315 windows = g_list_prepend (windows, view);334 {
316 }335 children = g_list_delete_link (children, l);
317 }336 }
318337 l = next;
319 g_list_free (children);338 }
320 return windows;339
340 return children;
341}
342
343/**
344 * bamf_application_get_window_for_xid:
345 * @application: a #BamfApplication
346 * @xid: an X11 Window ID
347 *
348 * Used to fetch the application contains a Window with given @xid.
349 *
350 * Since: 0.5.2
351 * Returns: (transfer none): a #BamfWindow for the passed @xid or %NULL if not found.
352 */
353BamfWindow *
354bamf_application_get_window_for_xid (BamfApplication *application,
355 guint32 xid)
356{
357 GList *l;
358 BamfWindow *window;
359
360 g_return_val_if_fail (BAMF_IS_APPLICATION (application), FALSE);
361
362 for (l = bamf_view_peek_children (BAMF_VIEW (application)); l; l = l->next)
363 {
364 if (BAMF_IS_WINDOW (l->data))
365 {
366 window = BAMF_WINDOW (l->data);
367
368 if (bamf_window_get_xid (window) == xid)
369 return window;
370 }
371 }
372
373 return NULL;
321}374}
322375
323/**376/**
@@ -572,7 +625,7 @@
572 G_CALLBACK (bamf_application_on_supported_mime_types_changed), view);625 G_CALLBACK (bamf_application_on_supported_mime_types_changed), view);
573626
574 GList *children, *l;627 GList *children, *l;
575 children = bamf_view_get_children (view);628 children = bamf_view_peek_children (view);
576629
577 if (priv->cached_xids)630 if (priv->cached_xids)
578 {631 {
@@ -588,8 +641,6 @@
588 guint32 xid = bamf_window_get_xid (BAMF_WINDOW (l->data));641 guint32 xid = bamf_window_get_xid (BAMF_WINDOW (l->data));
589 priv->cached_xids = g_list_prepend (priv->cached_xids, GUINT_TO_POINTER (xid));642 priv->cached_xids = g_list_prepend (priv->cached_xids, GUINT_TO_POINTER (xid));
590 }643 }
591
592 g_list_free (children);
593}644}
594645
595static void646static void
596647
=== modified file 'lib/libbamf/bamf-application.h'
--- lib/libbamf/bamf-application.h 2013-08-05 16:18:46 +0000
+++ lib/libbamf/bamf-application.h 2015-11-03 10:05:35 +0000
@@ -30,6 +30,7 @@
3030
31#include <glib-object.h>31#include <glib-object.h>
32#include <libbamf/bamf-view.h>32#include <libbamf/bamf-view.h>
33#include <libbamf/bamf-window.h>
3334
34G_BEGIN_DECLS35G_BEGIN_DECLS
3536
@@ -94,6 +95,9 @@
9495
95gboolean bamf_application_get_show_menu_stubs (BamfApplication *application);96gboolean bamf_application_get_show_menu_stubs (BamfApplication *application);
9697
98BamfWindow * bamf_application_get_window_for_xid (BamfApplication *application,
99 guint32 xid);
100
97101
98/* Deprecated symbols */102/* Deprecated symbols */
99G_GNUC_DEPRECATED103G_GNUC_DEPRECATED
100104
=== modified file 'lib/libbamf/bamf-factory.c'
--- lib/libbamf/bamf-factory.c 2013-06-21 17:51:51 +0000
+++ lib/libbamf/bamf-factory.c 2015-11-03 10:05:35 +0000
@@ -54,6 +54,7 @@
54static BamfFactory *static_factory = NULL;54static BamfFactory *static_factory = NULL;
5555
56static void on_view_weak_unref (BamfFactory *self, BamfView *view_was_here);56static void on_view_weak_unref (BamfFactory *self, BamfView *view_was_here);
57static void on_view_closed (BamfView *view, BamfFactory *self);
5758
58static void59static void
59bamf_factory_dispose (GObject *object)60bamf_factory_dispose (GObject *object)
@@ -66,6 +67,7 @@
66 for (l = self->priv->allocated_views, next = NULL; l; l = next)67 for (l = self->priv->allocated_views, next = NULL; l; l = next)
67 {68 {
68 g_object_weak_unref (G_OBJECT (l->data), (GWeakNotify) on_view_weak_unref, self);69 g_object_weak_unref (G_OBJECT (l->data), (GWeakNotify) on_view_weak_unref, self);
70 g_signal_handlers_disconnect_by_func (l->data, on_view_closed, self);
69 next = l->next;71 next = l->next;
70 g_list_free1 (l);72 g_list_free1 (l);
71 }73 }
@@ -183,6 +185,33 @@
183 G_CALLBACK (on_view_closed), self);185 G_CALLBACK (on_view_closed), self);
184}186}
185187
188BamfWindow *
189_bamf_factory_window_for_xid (BamfFactory * factory,
190 guint32 xid)
191{
192 BamfWindow *result = NULL, *win;
193 GList *l;
194
195 for (l = factory->priv->allocated_views; l; l = l->next)
196 {
197 if (!BAMF_IS_WINDOW (l->data))
198 continue;
199
200 if (bamf_view_is_closed (l->data))
201 continue;
202
203 win = BAMF_WINDOW (l->data);
204
205 if (bamf_window_get_xid (win) == xid)
206 {
207 result = win;
208 break;
209 }
210 }
211
212 return result;
213}
214
186BamfApplication *215BamfApplication *
187_bamf_factory_app_for_file (BamfFactory * factory,216_bamf_factory_app_for_file (BamfFactory * factory,
188 const char * path,217 const char * path,
@@ -220,6 +249,34 @@
220 return result;249 return result;
221}250}
222251
252BamfApplication *
253_bamf_factory_app_for_xid (BamfFactory * factory,
254 guint32 xid)
255{
256 BamfApplication *result = NULL, *app;
257 GList *l, *local_children;
258
259 for (l = factory->priv->allocated_views; l; l = l->next)
260 {
261 if (!BAMF_IS_APPLICATION (l->data))
262 continue;
263
264 if (bamf_view_is_closed (l->data))
265 continue;
266
267 app = BAMF_APPLICATION (l->data);
268 local_children = _bamf_application_get_cached_xids (app);
269
270 if (g_list_find (local_children, GUINT_TO_POINTER (xid)))
271 {
272 result = app;
273 break;
274 }
275 }
276
277 return result;
278}
279
223static280static
224BamfFactoryViewType compute_factory_type_by_str (const char *type)281BamfFactoryViewType compute_factory_type_by_str (const char *type)
225{282{
226283
=== modified file 'lib/libbamf/bamf-factory.h'
--- lib/libbamf/bamf-factory.h 2013-06-08 13:54:06 +0000
+++ lib/libbamf/bamf-factory.h 2015-11-03 10:05:35 +0000
@@ -30,6 +30,7 @@
3030
31#include <glib-object.h>31#include <glib-object.h>
32#include <libbamf/bamf-view.h>32#include <libbamf/bamf-view.h>
33#include <libbamf/bamf-window.h>
33#include <libbamf/bamf-application.h>34#include <libbamf/bamf-application.h>
3435
35G_BEGIN_DECLS36G_BEGIN_DECLS
@@ -89,9 +90,15 @@
89 const char * path,90 const char * path,
90 const char * type);91 const char * type);
9192
93BamfWindow * _bamf_factory_window_for_xid (BamfFactory * factory,
94 guint32 xid);
95
92BamfApplication * _bamf_factory_app_for_file (BamfFactory * factory,96BamfApplication * _bamf_factory_app_for_file (BamfFactory * factory,
93 const char * path,97 const char * path,
94 gboolean create);98 gboolean create);
99
100BamfApplication * _bamf_factory_app_for_xid (BamfFactory * factory,
101 guint32 xid);
95102
96BamfFactory * _bamf_factory_get_default (void);103BamfFactory * _bamf_factory_get_default (void);
97104
98105
=== modified file 'lib/libbamf/bamf-matcher.c'
--- lib/libbamf/bamf-matcher.c 2013-06-13 22:20:25 +0000
+++ lib/libbamf/bamf-matcher.c 2015-11-03 10:05:35 +0000
@@ -63,6 +63,9 @@
63{63{
64 BamfDBusMatcher *proxy;64 BamfDBusMatcher *proxy;
65 GCancellable *cancellable;65 GCancellable *cancellable;
66
67 BamfWindow *active_window;
68 BamfApplication *active_application;
66};69};
6770
68static BamfMatcher * default_matcher = NULL;71static BamfMatcher * default_matcher = NULL;
@@ -129,6 +132,47 @@
129}132}
130133
131134
135static gboolean
136track_ptr (GType wanted_type,
137 BamfView *active,
138 gpointer *cache_pointer)
139{
140 if (G_TYPE_CHECK_INSTANCE_TYPE (active, wanted_type))
141 {
142 if (*cache_pointer == active)
143 return FALSE;
144
145 *cache_pointer = active;
146 g_object_add_weak_pointer (G_OBJECT (active), cache_pointer);
147 return TRUE;
148 }
149 else if (G_TYPE_CHECK_INSTANCE_TYPE (*cache_pointer, wanted_type))
150 {
151 g_object_remove_weak_pointer (G_OBJECT (*cache_pointer), cache_pointer);
152 *cache_pointer = NULL;
153 return TRUE;
154 }
155
156 return FALSE;
157}
158
159static void
160bamf_matcher_on_name_owner_changed (BamfDBusMatcher *proxy,
161 GParamSpec *param,
162 BamfMatcher *matcher)
163{
164 /* This is called when the bamfdaemon is killed / started */
165 gchar *name_owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (proxy));
166
167 if (!name_owner)
168 {
169 track_ptr (BAMF_TYPE_APPLICATION, NULL, (gpointer *) &matcher->priv->active_application);
170 track_ptr (BAMF_TYPE_WINDOW, NULL, (gpointer *) &matcher->priv->active_window);
171 }
172
173 g_free (name_owner);
174}
175
132static void176static void
133bamf_matcher_on_view_opened (BamfDBusMatcher *proxy,177bamf_matcher_on_view_opened (BamfDBusMatcher *proxy,
134 const char *path,178 const char *path,
@@ -175,12 +219,17 @@
175{219{
176 BamfView *old_view;220 BamfView *old_view;
177 BamfView *new_view;221 BamfView *new_view;
178222 BamfFactory *factory;
179 BamfFactory *factory = _bamf_factory_get_default ();223
224 factory = _bamf_factory_get_default ();
225
180 old_view = _bamf_factory_view_for_path_type (factory, old_path, BAMF_FACTORY_APPLICATION);226 old_view = _bamf_factory_view_for_path_type (factory, old_path, BAMF_FACTORY_APPLICATION);
181 new_view = _bamf_factory_view_for_path_type (factory, new_path, BAMF_FACTORY_APPLICATION);227 new_view = _bamf_factory_view_for_path_type (factory, new_path, BAMF_FACTORY_APPLICATION);
182228
183 g_signal_emit (matcher, matcher_signals[ACTIVE_APPLICATION_CHANGED], 0, old_view, new_view);229 if (track_ptr (BAMF_TYPE_APPLICATION, new_view, (gpointer *) &matcher->priv->active_application))
230 {
231 g_signal_emit (matcher, matcher_signals[ACTIVE_APPLICATION_CHANGED], 0, old_view, new_view);
232 }
184}233}
185234
186static void235static void
@@ -191,12 +240,31 @@
191{240{
192 BamfView *old_view;241 BamfView *old_view;
193 BamfView *new_view;242 BamfView *new_view;
194243 BamfApplication *old_app;
195 BamfFactory *factory = _bamf_factory_get_default ();244 BamfApplication *new_app;
245 BamfFactory *factory;
246 BamfMatcherPrivate *priv;
247
248 priv = matcher->priv;
249 old_app = priv->active_application;
250 new_app = old_app;
251 factory = _bamf_factory_get_default ();
252
196 old_view = _bamf_factory_view_for_path_type (factory, old_path, BAMF_FACTORY_WINDOW);253 old_view = _bamf_factory_view_for_path_type (factory, old_path, BAMF_FACTORY_WINDOW);
197 new_view = _bamf_factory_view_for_path_type (factory, new_path, BAMF_FACTORY_WINDOW);254 new_view = _bamf_factory_view_for_path_type (factory, new_path, BAMF_FACTORY_WINDOW);
198255
256 track_ptr (BAMF_TYPE_WINDOW, new_view, (gpointer *) &priv->active_window);
257
258 if (BAMF_IS_WINDOW (new_view))
259 new_app = _bamf_factory_app_for_xid (factory, bamf_window_get_xid (BAMF_WINDOW (new_view)));
260
261 track_ptr (BAMF_TYPE_APPLICATION, (BamfView *) new_app, (gpointer *) &priv->active_application);
199 g_signal_emit (matcher, matcher_signals[ACTIVE_WINDOW_CHANGED], 0, old_view, new_view);262 g_signal_emit (matcher, matcher_signals[ACTIVE_WINDOW_CHANGED], 0, old_view, new_view);
263
264 if (new_app != old_app)
265 {
266 g_signal_emit (matcher, matcher_signals[ACTIVE_APPLICATION_CHANGED], 0, old_app, new_app);
267 }
200}268}
201269
202static void270static void
@@ -221,12 +289,15 @@
221289
222 if (error)290 if (error)
223 {291 {
224 g_error ("Unable to get %s matcher: %s", BAMF_DBUS_SERVICE_NAME, error ? error->message : "");292 g_warning ("Unable to get %s matcher: %s", BAMF_DBUS_SERVICE_NAME, error ? error->message : "");
225 g_error_free (error);293 g_error_free (error);
226 }294 }
227295
228 g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (priv->proxy), BAMF_DBUS_DEFAULT_TIMEOUT);296 g_dbus_proxy_set_default_timeout (G_DBUS_PROXY (priv->proxy), BAMF_DBUS_DEFAULT_TIMEOUT);
229297
298 g_signal_connect (priv->proxy, "notify::g-name-owner",
299 G_CALLBACK (bamf_matcher_on_name_owner_changed), self);
300
230 g_signal_connect (priv->proxy, "view-opened",301 g_signal_connect (priv->proxy, "view-opened",
231 G_CALLBACK (bamf_matcher_on_view_opened), self);302 G_CALLBACK (bamf_matcher_on_view_opened), self);
232303
@@ -303,30 +374,30 @@
303 g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);374 g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
304 priv = matcher->priv;375 priv = matcher->priv;
305376
377 if (BAMF_IS_APPLICATION (priv->active_application))
378 {
379 if (!bamf_view_is_closed (BAMF_VIEW (priv->active_application)))
380 return priv->active_application;
381 }
382
306 if (!_bamf_dbus_matcher_call_active_application_sync (priv->proxy, &app, priv->cancellable, &error))383 if (!_bamf_dbus_matcher_call_active_application_sync (priv->proxy, &app, priv->cancellable, &error))
307 {384 {
308 g_warning ("Failed to get active application: %s", error ? error->message : "");385 g_warning ("Failed to get active application: %s", error ? error->message : "");
309 g_error_free (error);386 g_error_free (error);
310 return NULL;387 track_ptr (BAMF_TYPE_APPLICATION, NULL, (gpointer *) &priv->active_application);
311 }388 return NULL;
312389 }
313 if (app && app[0] == '\0')
314 {
315 g_free (app);
316 return NULL;
317 }
318
319 if (!app)
320 return NULL;
321390
322 BamfFactory *factory = _bamf_factory_get_default ();391 BamfFactory *factory = _bamf_factory_get_default ();
323 view = _bamf_factory_view_for_path_type (factory, app, BAMF_FACTORY_APPLICATION);392 view = _bamf_factory_view_for_path_type (factory, app, BAMF_FACTORY_APPLICATION);
324 g_free (app);393 g_free (app);
325394
326 if (!BAMF_IS_APPLICATION (view))395 if (!BAMF_IS_APPLICATION (view))
327 return NULL;396 view = NULL;
328397
329 return BAMF_APPLICATION (view);398 track_ptr (BAMF_TYPE_APPLICATION, view, (gpointer *) &priv->active_application);
399
400 return priv->active_application;
330}401}
331402
332/**403/**
@@ -348,30 +419,60 @@
348 g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);419 g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
349 priv = matcher->priv;420 priv = matcher->priv;
350421
422 if (BAMF_IS_APPLICATION (priv->active_window))
423 {
424 if (!bamf_view_is_closed (BAMF_VIEW (priv->active_window)))
425 return priv->active_window;
426 }
427
351 if (!_bamf_dbus_matcher_call_active_window_sync (priv->proxy, &win, priv->cancellable, &error))428 if (!_bamf_dbus_matcher_call_active_window_sync (priv->proxy, &win, priv->cancellable, &error))
352 {429 {
353 g_warning ("Failed to get active window: %s", error ? error->message : "");430 g_warning ("Failed to get active window: %s", error ? error->message : "");
354 g_error_free (error);431 g_error_free (error);
355 return NULL;432 track_ptr (BAMF_TYPE_WINDOW, NULL, (gpointer *) &priv->active_window);
356 }433 return NULL;
357434 }
358 if (win && win[0] == '\0')
359 {
360 g_free (win);
361 return NULL;
362 }
363
364 if (!win)
365 return NULL;
366435
367 BamfFactory *factory = _bamf_factory_get_default ();436 BamfFactory *factory = _bamf_factory_get_default ();
368 view = _bamf_factory_view_for_path_type (factory, win, BAMF_FACTORY_WINDOW);437 view = _bamf_factory_view_for_path_type (factory, win, BAMF_FACTORY_WINDOW);
369 g_free (win);438 g_free (win);
370439
371 if (!BAMF_IS_WINDOW (view))440 if (!BAMF_IS_WINDOW (view))
372 return NULL;441 view = NULL;
373442
374 return BAMF_WINDOW (view);443 track_ptr (BAMF_TYPE_WINDOW, view, (gpointer *) &priv->active_window);
444
445 return priv->active_window;
446}
447
448/**
449 * bamf_matcher_get_window_for_xid:
450 * @matcher: a #BamfMatcher
451 * @xid: The X11 Window ID to search for
452 *
453 * Used to fetch the #BamfWindow that wraps the given @window.
454 *
455 * Returns: (transfer none): The #BamfWindow representing the xid passed, or NULL if none exists.
456 */
457BamfWindow *
458bamf_matcher_get_window_for_xid (BamfMatcher *matcher, guint32 xid)
459{
460 BamfWindow *window;
461 BamfApplication *app;
462
463 g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
464
465 window = _bamf_factory_window_for_xid (_bamf_factory_get_default (), xid);
466
467 if (BAMF_IS_WINDOW (window))
468 return window;
469
470 app = bamf_matcher_get_application_for_xid (matcher, xid);
471
472 if (BAMF_IS_APPLICATION (app))
473 window = bamf_application_get_window_for_xid (app, xid);
474
475 return BAMF_IS_WINDOW (window) ? window : NULL;
375}476}
376477
377/**478/**
@@ -386,7 +487,7 @@
386BamfApplication *487BamfApplication *
387bamf_matcher_get_application_for_window (BamfMatcher *matcher, BamfWindow *window)488bamf_matcher_get_application_for_window (BamfMatcher *matcher, BamfWindow *window)
388{489{
389 g_return_val_if_fail(BAMF_IS_WINDOW(window), NULL);490 g_return_val_if_fail (BAMF_IS_WINDOW (window), NULL);
390 return bamf_matcher_get_application_for_xid (matcher, bamf_window_get_xid(window));491 return bamf_matcher_get_application_for_xid (matcher, bamf_window_get_xid(window));
391}492}
392493
@@ -404,11 +505,18 @@
404{505{
405 BamfMatcherPrivate *priv;506 BamfMatcherPrivate *priv;
406 BamfView *view;507 BamfView *view;
508 BamfFactory *factory;
407 char *app = NULL;509 char *app = NULL;
408 GError *error = NULL;510 GError *error = NULL;
409511
410 g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);512 g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
411 priv = matcher->priv;513 priv = matcher->priv;
514 factory = _bamf_factory_get_default ();
515
516 view = (BamfView*) _bamf_factory_app_for_xid (factory, xid);
517
518 if (BAMF_IS_APPLICATION (view))
519 return BAMF_APPLICATION (view);
412520
413 if (!_bamf_dbus_matcher_call_application_for_xid_sync (priv->proxy, xid, &app, priv->cancellable, &error))521 if (!_bamf_dbus_matcher_call_application_for_xid_sync (priv->proxy, xid, &app, priv->cancellable, &error))
414 {522 {
@@ -417,16 +525,6 @@
417 return NULL;525 return NULL;
418 }526 }
419527
420 if (app && app[0] == '\0')
421 {
422 g_free (app);
423 return NULL;
424 }
425
426 if (!app)
427 return NULL;
428
429 BamfFactory *factory = _bamf_factory_get_default ();
430 view = _bamf_factory_view_for_path_type (factory, app, BAMF_FACTORY_APPLICATION);528 view = _bamf_factory_view_for_path_type (factory, app, BAMF_FACTORY_APPLICATION);
431 g_free (app);529 g_free (app);
432530
@@ -440,12 +538,18 @@
440bamf_matcher_application_is_running (BamfMatcher *matcher, const gchar *app)538bamf_matcher_application_is_running (BamfMatcher *matcher, const gchar *app)
441{539{
442 BamfMatcherPrivate *priv;540 BamfMatcherPrivate *priv;
541 BamfApplication *view;
443 gboolean running = FALSE;542 gboolean running = FALSE;
444 GError *error = NULL;543 GError *error = NULL;
445544
446 g_return_val_if_fail (BAMF_IS_MATCHER (matcher), FALSE);545 g_return_val_if_fail (BAMF_IS_MATCHER (matcher), FALSE);
447 priv = matcher->priv;546 priv = matcher->priv;
448547
548 view = _bamf_factory_app_for_file (_bamf_factory_get_default (), app, FALSE);
549
550 if (BAMF_IS_APPLICATION (view))
551 return bamf_view_is_running (BAMF_VIEW (view));
552
449 if (!_bamf_dbus_matcher_call_application_is_running_sync (priv->proxy,553 if (!_bamf_dbus_matcher_call_application_is_running_sync (priv->proxy,
450 app ? app : "",554 app ? app : "",
451 &running,555 &running,
452556
=== modified file 'lib/libbamf/bamf-matcher.h'
--- lib/libbamf/bamf-matcher.h 2013-06-08 13:54:06 +0000
+++ lib/libbamf/bamf-matcher.h 2015-11-03 10:05:35 +0000
@@ -89,6 +89,9 @@
8989
90BamfWindow * bamf_matcher_get_active_window (BamfMatcher *matcher);90BamfWindow * bamf_matcher_get_active_window (BamfMatcher *matcher);
9191
92BamfWindow * bamf_matcher_get_window_for_xid (BamfMatcher *matcher,
93 guint32 xid);
94
92BamfApplication * bamf_matcher_get_application_for_xid (BamfMatcher *matcher,95BamfApplication * bamf_matcher_get_application_for_xid (BamfMatcher *matcher,
93 guint32 xid);96 guint32 xid);
94BamfApplication * bamf_matcher_get_application_for_window (BamfMatcher *matcher,97BamfApplication * bamf_matcher_get_application_for_window (BamfMatcher *matcher,
9598
=== modified file 'lib/libbamf/bamf-view.c'
--- lib/libbamf/bamf-view.c 2013-10-10 15:04:14 +0000
+++ lib/libbamf/bamf-view.c 2015-11-03 10:05:35 +0000
@@ -105,6 +105,27 @@
105GList *105GList *
106bamf_view_get_children (BamfView *view)106bamf_view_get_children (BamfView *view)
107{107{
108 g_return_val_if_fail (BAMF_IS_VIEW (view), NULL);
109
110 if (BAMF_VIEW_GET_CLASS (view)->get_children)
111 return BAMF_VIEW_GET_CLASS (view)->get_children (view);
112
113 return g_list_copy (bamf_view_peek_children (view));
114}
115
116/**
117 * bamf_view_peek_children:
118 * @view: a #BamfView
119 *
120 * Note: Makes sever dbus calls the first time this is called on a view.
121 * Dbus messaging is reduced afterwards.
122 * Since: 0.5.2
123 * Returns: (element-type Bamf.View) (transfer none): Returns a list of #BamfView which
124 * is owned by the #BamfView and should not freed or modified after usage.
125 */
126GList *
127bamf_view_peek_children (BamfView *view)
128{
108 char ** children;129 char ** children;
109 int i, len;130 int i, len;
110 GList *results = NULL;131 GList *results = NULL;
@@ -114,16 +135,13 @@
114135
115 g_return_val_if_fail (BAMF_IS_VIEW (view), NULL);136 g_return_val_if_fail (BAMF_IS_VIEW (view), NULL);
116137
117 if (BAMF_VIEW_GET_CLASS (view)->get_children)
118 return BAMF_VIEW_GET_CLASS (view)->get_children (view);
119
120 if (!_bamf_view_remote_ready (view))138 if (!_bamf_view_remote_ready (view))
121 return NULL;139 return NULL;
122140
123 priv = view->priv;141 priv = view->priv;
124142
125 if (priv->cached_children || !priv->reload_children)143 if (priv->cached_children || !priv->reload_children)
126 return g_list_copy (priv->cached_children);144 return priv->cached_children;
127145
128 if (!_bamf_dbus_item_view_call_children_sync (priv->proxy, &children, CANCELLABLE (view), &error))146 if (!_bamf_dbus_item_view_call_children_sync (priv->proxy, &children, CANCELLABLE (view), &error))
129 {147 {
@@ -153,7 +171,30 @@
153 priv->reload_children = FALSE;171 priv->reload_children = FALSE;
154 priv->cached_children = results;172 priv->cached_children = results;
155173
156 return g_list_copy (priv->cached_children);174 return priv->cached_children;
175}
176
177/**
178 * bamf_view_has_child:
179 * @view: a #BamfView
180 *
181 * Returns: %TRUE whether the #BamfView @view has the specified @child.
182 */
183gboolean
184bamf_view_has_child (BamfView *view, BamfView *child)
185{
186 GList *l;
187
188 g_return_val_if_fail (BAMF_IS_VIEW (view), FALSE);
189 g_return_val_if_fail (BAMF_IS_VIEW (child), FALSE);
190
191 for (l = bamf_view_peek_children (view); l; l = l->next)
192 {
193 if (l->data == child)
194 return TRUE;
195 }
196
197 return FALSE;
157}198}
158199
159/**200/**
@@ -389,13 +430,11 @@
389}430}
390431
391/**432/**
392 * bamf_view_get_view_type:433 * bamf_view_get_view_type: (virtual view_type)
393 * @view: a #BamfView434 * @view: a #BamfView
394 *435 *
395 * The view type of a window is a short string used to represent all views of the same class. These436 * The view type of a window is a short string used to represent all views of the same class. These
396 * descriptions should not be used to do casting as they are not considered stable.437 * descriptions should not be used to do casting as they are not considered stable.
397 *
398 * Virtual: view_type
399 */438 */
400const gchar *439const gchar *
401bamf_view_get_view_type (BamfView *self)440bamf_view_get_view_type (BamfView *self)
@@ -481,6 +520,7 @@
481{520{
482 BamfView *view;521 BamfView *view;
483 BamfViewPrivate *priv;522 BamfViewPrivate *priv;
523 gboolean was_cached = FALSE;
484524
485 view = _bamf_factory_view_for_path (_bamf_factory_get_default (), path);525 view = _bamf_factory_view_for_path (_bamf_factory_get_default (), path);
486 priv = self->priv;526 priv = self->priv;
@@ -499,11 +539,14 @@
499 if (l)539 if (l)
500 {540 {
501 priv->cached_children = g_list_delete_link (priv->cached_children, l);541 priv->cached_children = g_list_delete_link (priv->cached_children, l);
502 g_object_unref (view);542 was_cached = TRUE;
503 }543 }
504 }544 }
505545
506 g_signal_emit (G_OBJECT (self), view_signals[CHILD_REMOVED], 0, view);546 g_signal_emit (G_OBJECT (self), view_signals[CHILD_REMOVED], 0, view);
547
548 if (was_cached)
549 g_object_unref (view);
507}550}
508551
509static void552static void
510553
=== modified file 'lib/libbamf/bamf-view.h'
--- lib/libbamf/bamf-view.h 2013-08-09 15:32:46 +0000
+++ lib/libbamf/bamf-view.h 2015-11-03 10:05:35 +0000
@@ -121,6 +121,10 @@
121121
122GList * bamf_view_get_children (BamfView *view);122GList * bamf_view_get_children (BamfView *view);
123123
124GList * bamf_view_peek_children (BamfView *view);
125
126gboolean bamf_view_has_child (BamfView *view, BamfView *child);
127
124gboolean bamf_view_is_closed (BamfView *view);128gboolean bamf_view_is_closed (BamfView *view);
125129
126gboolean bamf_view_is_active (BamfView *view);130gboolean bamf_view_is_active (BamfView *view);
127131
=== modified file 'tests/bamfdaemon/Makefile.am'
--- tests/bamfdaemon/Makefile.am 2014-04-07 21:31:21 +0000
+++ tests/bamfdaemon/Makefile.am 2015-11-03 10:05:35 +0000
@@ -1,3 +1,5 @@
1TESTDIR=$(shell realpath $(abs_top_srcdir)/tests)
2
1noinst_PROGRAMS = \3noinst_PROGRAMS = \
2 test-bamf4 test-bamf
35
@@ -44,7 +46,7 @@
44 -I$(top_srcdir)/lib \46 -I$(top_srcdir)/lib \
45 -I$(top_builddir)/lib \47 -I$(top_builddir)/lib \
46 -DWNCK_I_KNOW_THIS_IS_UNSTABLE \48 -DWNCK_I_KNOW_THIS_IS_UNSTABLE \
47 -DTESTDIR=\""$(abs_top_srcdir)/tests"\" \49 -DTESTDIR=\""$(TESTDIR)"\" \
48 $(COVERAGE_CFLAGS) \50 $(COVERAGE_CFLAGS) \
49 $(GCC_FLAGS) \51 $(GCC_FLAGS) \
50 $(GLIB_CFLAGS) \52 $(GLIB_CFLAGS) \
5153
=== modified file 'tests/libbamf/Makefile.am'
--- tests/libbamf/Makefile.am 2013-06-21 18:21:31 +0000
+++ tests/libbamf/Makefile.am 2015-11-03 10:05:35 +0000
@@ -1,3 +1,5 @@
1TESTDIR=$(shell realpath $(abs_top_srcdir)/tests)
2
1noinst_PROGRAMS = \3noinst_PROGRAMS = \
2 test-libbamf4 test-libbamf
35
@@ -12,7 +14,7 @@
12 -I$(top_builddir)/lib \14 -I$(top_builddir)/lib \
13 -I$(top_srcdir)/lib/libbamf \15 -I$(top_srcdir)/lib/libbamf \
14 -I$(top_builddir)/lib/libbamf \16 -I$(top_builddir)/lib/libbamf \
15 -DTESTDIR=\""$(abs_top_srcdir)/tests"\" \17 -DTESTDIR=\""$(TESTDIR)"\" \
16 $(COVERAGE_CFLAGS) \18 $(COVERAGE_CFLAGS) \
17 $(GCC_FLAGS) \19 $(GCC_FLAGS) \
18 $(GLIB_CFLAGS) \20 $(GLIB_CFLAGS) \

Subscribers

People subscribed via source and target branches