Merge lp:~3v1n0/bamf/lib-factory-xids-matching into lp:bamf/0.4

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: 480
Merged at revision: 462
Proposed branch: lp:~3v1n0/bamf/lib-factory-xids-matching
Merge into: lp:bamf/0.4
Diff against target: 892 lines (+410/-120)
9 files modified
lib/libbamf/Makefile.am (+1/-0)
lib/libbamf/bamf-application-private.h (+30/-0)
lib/libbamf/bamf-application.c (+71/-8)
lib/libbamf/bamf-factory.c (+157/-44)
lib/libbamf/bamf-factory.h (+17/-0)
lib/libbamf/bamf-matcher.c (+68/-38)
lib/libbamf/bamf-view-private.h (+2/-0)
lib/libbamf/bamf-view.c (+62/-29)
lib/libbamf/bamf-window.c (+2/-1)
To merge this branch: bzr merge lp:~3v1n0/bamf/lib-factory-xids-matching
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
Review via email: mp+103591@code.launchpad.net

Commit message

BamfFactory: be more smart to re-associate a dbus path to a view using windows xid

Description of the change

BamfFactory has been improved adding the new bamf_factory_view_for_path_type that allows to get a view from a path with the defined type. This allows to avoid (when the type is known) to create a temporary view, only to query via dbus the type of the object.

Also now the factory now has been improved to re-associate the opened views to the new ones using the related windows xids. So basically when a new application has been opened, we initially try to re-associate it to the opened view with the same desktop file; if that check fails we fallback to the children windows xid comparison (if a view has at least a xid that matches the ones of the new application, then we consider them the same).

So, thanks to this both applications with .desktop files associated and applications with no desktop file can be re-used avoiding memory duplication and double launcher icon instances.

Tests covered by: lp:~3v1n0/unity/launcher-double-icons-tests

To post a comment you must log in.
Revision history for this message
Michal Hruby (mhr3) wrote :
Download full text (3.6 KiB)

It seems to be working fine, although it seems to be causing some assertions:

(bamfdaemon:26376): GLib-CRITICAL **: g_str_has_prefix: assertion `str != NULL' failed

Backtrace:

#0 g_log (log_domain=0x7ffff632370e "GLib", log_level=G_LOG_LEVEL_CRITICAL,
    format=0x7ffff632cb2a "%s: assertion `%s' failed")
    at /build/buildd/glib2.0-2.32.1/./glib/gmessages.c:788
#1 0x00007ffff63014f2 in g_str_has_prefix (str=0x0,
    prefix=0x43e931 "libreoffice")
    at /build/buildd/glib2.0-2.32.1/./glib/gstrfuncs.c:2771
#2 0x000000000042f265 in is_open_office_window (window=0x7ac1e0,
    self=<optimized out>)
    at /home/miso-work/unity/source/bamf/src/bamf-matcher.c:1378
#3 handle_window_opened (screen=<optimized out>, window=0x7ac1e0,
    self=0x7861b0) at /home/miso-work/unity/source/bamf/src/bamf-matcher.c:2081
#4 0x00007ffff67b6354 in g_cclosure_marshal_VOID__OBJECTv (closure=0x7b2630,
    return_value=<optimized out>, instance=0x777a80, args=<optimized out>,
    marshal_data=<optimized out>, n_params=<optimized out>,
    param_types=0x79bf50)
    at /build/buildd/glib2.0-2.32.1/./gobject/gmarshal.c:1312
#5 0x00007ffff67b2eca in _g_closure_invoke_va (closure=0x7b2630,
    return_value=0x0, instance=0x777a80, args=0x7fffffffd348, n_params=1,
    param_types=<optimized out>)
    at /build/buildd/glib2.0-2.32.1/./gobject/gclosure.c:840
#6 0x00007ffff67cb741 in g_signal_emit_valist (instance=0x777a80,
    signal_id=<optimized out>, detail=0, var_args=<optimized out>)
---Type <return> to continue, or q <return> to quit---
    at /build/buildd/glib2.0-2.32.1/./gobject/gsignal.c:3207
#7 0x00007ffff67cc242 in g_signal_emit (instance=<optimized out>,
    signal_id=<optimized out>, detail=<optimized out>)
    at /build/buildd/glib2.0-2.32.1/./gobject/gsignal.c:3352
#8 0x00007ffff67b6354 in g_cclosure_marshal_VOID__OBJECTv (closure=0x7b2590,
    return_value=<optimized out>, instance=0x79a390, args=<optimized out>,
    marshal_data=<optimized out>, n_params=<optimized out>,
    param_types=0x7b0f30)
    at /build/buildd/glib2.0-2.32.1/./gobject/gmarshal.c:1312
#9 0x00007ffff67b2eca in _g_closure_invoke_va (closure=0x7b2590,
    return_value=0x0, instance=0x79a390, args=0x7fffffffd718, n_params=1,
    param_types=<optimized out>)
    at /build/buildd/glib2.0-2.32.1/./gobject/gclosure.c:840
#10 0x00007ffff67cb741 in g_signal_emit_valist (instance=0x79a390,
    signal_id=<optimized out>, detail=0, var_args=<optimized out>)
    at /build/buildd/glib2.0-2.32.1/./gobject/gsignal.c:3207
#11 0x00007ffff67cc242 in g_signal_emit (instance=<optimized out>,
    signal_id=<optimized out>, detail=<optimized out>)
    at /build/buildd/glib2.0-2.32.1/./gobject/gsignal.c:3352
#12 0x00007ffff787e339 in ?? () from /usr/lib/libwnck-3.so.0
#13 0x00007ffff787ea24 in ?? () from /usr/lib/libwnck-3.so.0
#14 0x00007ffff62e4c9a in g_main_dispatch (context=0x666a80)
    at /build/buildd/glib2.0-2.32.1/./glib/gmain.c:2515
#15 g_main_context_dispatch (context=0x666a80)
    at /build/buildd/glib2.0-2.32.1/./glib/gmain.c:3052
#16 0x00007ffff62e5060 in g_main_context_iterate (dispatch=1,
    block=<optimized out>, context=0x666a80, self=<optimized out>)
    at ...

Read more...

Revision history for this message
Michal Hruby (mhr3) wrote :

And unity also just complained about:

ERROR 2012-04-26 10:42:25 unity <unknown>:0 on_view_proxy_destroyed: assertion `BAMF_IS_VIEW (view)' failed

Revision history for this message
Michal Hruby (mhr3) wrote :

And one more thing - wouldn't it be better to use an enum in the bamf_factory_view_for_path_type() method?

479. By Marco Trevisan (Treviño)

libbamf, bamfview: disconect to the destroyed signal when needed

480. By Marco Trevisan (Treviño)

BamfFactory: use BamfFactoryViewType instead of strings comparisons when possible.

This cleans the code and is for sure more safe.

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Ok, updated ;)

Revision history for this message
Michal Hruby (mhr3) wrote :

Looking good to me, do we want to have this in SRU1?

review: Approve
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Well... I'd like to.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/libbamf/Makefile.am'
--- lib/libbamf/Makefile.am 2012-01-20 15:33:59 +0000
+++ lib/libbamf/Makefile.am 2012-04-26 17:14:21 +0000
@@ -40,6 +40,7 @@
4040
41libbamf_la_SOURCES = \41libbamf_la_SOURCES = \
42 bamf-factory.h \42 bamf-factory.h \
43 bamf-application-private.h \
43 bamf-view-private.h \44 bamf-view-private.h \
44 $(sources_h) \45 $(sources_h) \
45 $(libbamf_sources) \46 $(libbamf_sources) \
4647
=== added file 'lib/libbamf/bamf-application-private.h'
--- lib/libbamf/bamf-application-private.h 1970-01-01 00:00:00 +0000
+++ lib/libbamf/bamf-application-private.h 2012-04-26 17:14:21 +0000
@@ -0,0 +1,30 @@
1/*
2 * bamf-application-private.h
3 * This file is part of BAMF
4 *
5 * Copyright (C) 2012 - Marco Trevisan (Treviño)
6 *
7 * BAMF is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * BAMF is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with BAMF; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301 USA
21 */
22
23#ifndef _BAMF_APPLICATION_PRIVATE_H_
24#define _BAMF_APPLICATION_PRIVATE_H_
25
26#include <libbamf/bamf-application.h>
27
28GList *bamf_application_get_cached_xids (BamfApplication *app);
29
30#endif
031
=== modified file 'lib/libbamf/bamf-application.c'
--- lib/libbamf/bamf-application.c 2012-04-10 08:57:06 +0000
+++ lib/libbamf/bamf-application.c 2012-04-26 17:14:21 +0000
@@ -37,6 +37,7 @@
37#include "bamf-application.h"37#include "bamf-application.h"
38#include "bamf-window.h"38#include "bamf-window.h"
39#include "bamf-factory.h"39#include "bamf-factory.h"
40#include "bamf-application-private.h"
40#include "bamf-view-private.h"41#include "bamf-view-private.h"
4142
42#include <gio/gdesktopappinfo.h>43#include <gio/gdesktopappinfo.h>
@@ -66,6 +67,7 @@
66 DBusGProxy *proxy;67 DBusGProxy *proxy;
67 gchar *application_type;68 gchar *application_type;
68 gchar *desktop_file;69 gchar *desktop_file;
70 GList *cached_xids;
69 int show_stubs;71 int show_stubs;
70};72};
7173
@@ -98,6 +100,12 @@
98 return NULL;100 return NULL;
99 }101 }
100102
103 if (file && file[0] == '\0')
104 {
105 g_free (file);
106 file = NULL;
107 }
108
101 priv->desktop_file = file;109 priv->desktop_file = file;
102 return file;110 return file;
103}111}
@@ -185,6 +193,7 @@
185 }193 }
186 }194 }
187195
196 g_list_free (children);
188 return windows;197 return windows;
189}198}
190199
@@ -238,20 +247,48 @@
238bamf_application_on_window_added (DBusGProxy *proxy, char *path, BamfApplication *self)247bamf_application_on_window_added (DBusGProxy *proxy, char *path, BamfApplication *self)
239{248{
240 BamfView *view;249 BamfView *view;
241250 BamfFactory *factory;
242 view = bamf_factory_view_for_path (bamf_factory_get_default (), path);251
243252 factory = bamf_factory_get_default ();
244 g_signal_emit (G_OBJECT (self), application_signals[WINDOW_ADDED], 0, view);253 view = bamf_factory_view_for_path_type (factory, path, BAMF_FACTORY_WINDOW);
254
255 if (BAMF_IS_WINDOW (view))
256 {
257 guint32 xid = bamf_window_get_xid (BAMF_WINDOW (view));
258
259 if (!g_list_find (self->priv->cached_xids, GUINT_TO_POINTER (xid)))
260 {
261 self->priv->cached_xids = g_list_prepend (self->priv->cached_xids, GUINT_TO_POINTER (xid));
262 }
263
264 g_signal_emit (G_OBJECT (self), application_signals[WINDOW_ADDED], 0, view);
265 }
245}266}
246267
247static void268static void
248bamf_application_on_window_removed (DBusGProxy *proxy, char *path, BamfApplication *self)269bamf_application_on_window_removed (DBusGProxy *proxy, char *path, BamfApplication *self)
249{270{
250 BamfView *view;271 BamfView *view;
251272 BamfFactory *factory;
252 view = bamf_factory_view_for_path (bamf_factory_get_default (), path);273
253274 factory = bamf_factory_get_default ();
254 g_signal_emit (G_OBJECT (self), application_signals[WINDOW_REMOVED], 0, view);275 view = bamf_factory_view_for_path_type (factory, path, BAMF_FACTORY_WINDOW);
276
277 if (BAMF_IS_WINDOW (view))
278 {
279 guint32 xid = bamf_window_get_xid (BAMF_WINDOW (view));
280 self->priv->cached_xids = g_list_remove (self->priv->cached_xids, GUINT_TO_POINTER (xid));
281
282 g_signal_emit (G_OBJECT (self), application_signals[WINDOW_REMOVED], 0, view);
283 }
284}
285
286GList *
287bamf_application_get_cached_xids (BamfApplication *self)
288{
289 g_return_val_if_fail (BAMF_IS_APPLICATION (self), NULL);
290
291 return self->priv->cached_xids;
255}292}
256293
257static void294static void
@@ -291,6 +328,12 @@
291 priv->proxy = NULL;328 priv->proxy = NULL;
292 }329 }
293330
331 if (priv->cached_xids)
332 {
333 g_list_free (priv->cached_xids);
334 priv->cached_xids = NULL;
335 }
336
294 if (G_OBJECT_CLASS (bamf_application_parent_class)->dispose)337 if (G_OBJECT_CLASS (bamf_application_parent_class)->dispose)
295 G_OBJECT_CLASS (bamf_application_parent_class)->dispose (object);338 G_OBJECT_CLASS (bamf_application_parent_class)->dispose (object);
296}339}
@@ -335,6 +378,26 @@
335 (GCallback) bamf_application_on_window_removed,378 (GCallback) bamf_application_on_window_removed,
336 self,379 self,
337 NULL);380 NULL);
381
382 GList *children, *l;
383 children = bamf_view_get_children (view);
384
385 if (priv->cached_xids)
386 {
387 g_list_free (priv->cached_xids);
388 priv->cached_xids = NULL;
389 }
390
391 for (l = children; l; l = l->next)
392 {
393 if (!BAMF_IS_WINDOW (l->data))
394 continue;
395
396 guint32 xid = bamf_window_get_xid (BAMF_WINDOW (l->data));
397 priv->cached_xids = g_list_prepend (priv->cached_xids, GUINT_TO_POINTER (xid));
398 }
399
400 g_list_free (children);
338}401}
339402
340static void403static void
341404
=== modified file 'lib/libbamf/bamf-factory.c'
--- lib/libbamf/bamf-factory.c 2012-04-18 12:28:41 +0000
+++ lib/libbamf/bamf-factory.c 2012-04-26 17:14:21 +0000
@@ -39,6 +39,7 @@
39#include "bamf-view-private.h"39#include "bamf-view-private.h"
40#include "bamf-window.h"40#include "bamf-window.h"
41#include "bamf-application.h"41#include "bamf-application.h"
42#include "bamf-application-private.h"
42#include "bamf-indicator.h"43#include "bamf-indicator.h"
4344
44#include <dbus/dbus.h>45#include <dbus/dbus.h>
@@ -159,68 +160,181 @@
159 return result;160 return result;
160}161}
161162
162BamfView * 163static
163bamf_factory_view_for_path (BamfFactory * factory,164BamfFactoryViewType compute_factory_type_by_str (const char *type)
164 const char * path)165{
166 BamfFactoryViewType factory_type = BAMF_FACTORY_NONE;
167
168 if (type && type[0] != '\0')
169 {
170 if (g_strcmp0 (type, "window") == 0)
171 {
172 factory_type = BAMF_FACTORY_WINDOW;
173 }
174 else if (g_strcmp0 (type, "application") == 0)
175 {
176 factory_type = BAMF_FACTORY_APPLICATION;
177 }
178 else if (g_strcmp0 (type, "indicator") == 0)
179 {
180 factory_type = BAMF_FACTORY_INDICATOR;
181 }
182 else if (g_strcmp0 (type, "view") == 0)
183 {
184 factory_type = BAMF_FACTORY_VIEW;
185 }
186 }
187
188 return factory_type;
189}
190
191BamfView *
192bamf_factory_view_for_path (BamfFactory * factory, const char * path)
193{
194 return bamf_factory_view_for_path_type (factory, path, BAMF_FACTORY_NONE);
195}
196
197BamfView *
198bamf_factory_view_for_path_type_str (BamfFactory * factory, const char * path,
199 const char * type)
200{
201 g_return_val_if_fail (BAMF_IS_FACTORY (factory), NULL);
202 BamfFactoryViewType factory_type = compute_factory_type_by_str (type);
203
204 return bamf_factory_view_for_path_type (factory, path, factory_type);
205}
206
207BamfView *
208bamf_factory_view_for_path_type (BamfFactory * factory, const char * path,
209 BamfFactoryViewType type)
165{210{
166 GHashTable *views;211 GHashTable *views;
167 BamfView *view;212 BamfView *view;
168 GList *l;213 GList *l;
169 gchar *type;
170 gboolean created = FALSE;214 gboolean created = FALSE;
171215
172 g_return_val_if_fail (BAMF_IS_FACTORY (factory), NULL);216 g_return_val_if_fail (BAMF_IS_FACTORY (factory), NULL);
173 217
174 if (!path || strlen (path) == 0)218 if (!path || path[0] == '\0')
175 return NULL;219 return NULL;
176 220
177 views = factory->priv->views;221 views = factory->priv->views;
178
179 view = g_hash_table_lookup (views, path);222 view = g_hash_table_lookup (views, path);
180 223
181 if (BAMF_IS_VIEW (view))224 if (BAMF_IS_VIEW (view))
182 return view;225 return view;
183 226
184 view = g_object_new (BAMF_TYPE_VIEW, NULL);227 if (type == BAMF_FACTORY_NONE)
185 bamf_view_set_path (view, path);228 {
186 type = g_strdup (bamf_view_get_view_type (view));229 view = g_object_new (BAMF_TYPE_VIEW, NULL);
187 g_object_unref (view);230 bamf_view_set_path (view, path);
188 231 type = compute_factory_type_by_str (bamf_view_get_view_type (view));
189 view = NULL;232 g_object_unref (view);
190 if (g_strcmp0 (type, "application") == 0)233 view = NULL;
191 view = BAMF_VIEW (bamf_application_new (path));234 }
192 else if (g_strcmp0 (type, "window") == 0)235
193 view = BAMF_VIEW (bamf_window_new (path));236 switch (type)
194 else if (g_strcmp0 (type, "indicator") == 0)237 {
195 view = BAMF_VIEW (bamf_indicator_new (path));238 case BAMF_FACTORY_VIEW:
196 239 view = g_object_new (BAMF_TYPE_VIEW, NULL);
240 break;
241 case BAMF_FACTORY_WINDOW:
242 view = BAMF_VIEW (bamf_window_new (path));
243 break;
244 case BAMF_FACTORY_APPLICATION:
245 view = BAMF_VIEW (bamf_application_new (path));
246 break;
247 case BAMF_FACTORY_INDICATOR:
248 view = BAMF_VIEW (bamf_indicator_new (path));
249 break;
250 case BAMF_FACTORY_NONE:
251 view = NULL;
252 }
253
197 created = TRUE;254 created = TRUE;
198 255 BamfView *matched_view = NULL;
256
199 if (BAMF_IS_APPLICATION (view))257 if (BAMF_IS_APPLICATION (view))
200 {258 {
201 /* handle case where a favorite exists and this matches it */259 /* handle case where a favorite exists and this matches it */
202 const char *local_desktop_file = bamf_application_get_desktop_file (BAMF_APPLICATION (view));260 const char *local_desktop_file = bamf_application_get_desktop_file (BAMF_APPLICATION (view));
203 for (l = factory->priv->local_views; l; l = l->next)261 GList *local_children = bamf_view_get_children (view);
204 {262
205 /* remote ready views are already matched */263 for (l = factory->priv->local_views; l; l = l->next)
206 if (bamf_view_remote_ready (BAMF_VIEW (l->data)) || !BAMF_IS_APPLICATION (l->data))264 {
207 continue;265 if (!BAMF_IS_APPLICATION (l->data))
208 266 continue;
209 const char *list_desktop_file = bamf_application_get_desktop_file (BAMF_APPLICATION (l->data));267
210 268 BamfView *list_view = BAMF_VIEW (l->data);
211 if (g_strcmp0 (local_desktop_file, list_desktop_file) == 0)269 BamfApplication *list_app = BAMF_APPLICATION (l->data);
212 {270
213 created = FALSE;271 const char *list_desktop_file = bamf_application_get_desktop_file (list_app);
214 g_object_unref (view);272
215273 /* We try to match applications by desktop files */
216 view = BAMF_VIEW (l->data);274 if (local_desktop_file && g_strcmp0 (local_desktop_file, list_desktop_file) == 0)
217 bamf_view_set_path (view, path);275 {
218 g_object_ref_sink (view);276 matched_view = list_view;
219 break;277 break;
220 }278 }
221 }279
222 }280 /* If the primary search doesn't give out any result, we fallback
223 281 * to children window comparison */
282 if (!matched_view)
283 {
284 GList *list_children, *ll;
285 list_children = bamf_application_get_cached_xids (list_app);
286
287 for (ll = local_children; ll; ll = ll->next)
288 {
289 if (!BAMF_IS_WINDOW (ll->data))
290 continue;
291
292 guint32 local_xid = bamf_window_get_xid (BAMF_WINDOW (ll->data));
293
294 if (g_list_find (list_children, GUINT_TO_POINTER (local_xid)))
295 {
296 matched_view = list_view;
297 break;
298 }
299 }
300 }
301 }
302
303 g_list_free (local_children);
304 }
305 else if (BAMF_IS_WINDOW (view))
306 {
307 guint32 local_xid = bamf_window_get_xid (BAMF_WINDOW (view));
308
309 for (l = factory->priv->local_views; l; l = l->next)
310 {
311 if (!BAMF_IS_WINDOW (l->data))
312 continue;
313
314 BamfView *list_view = BAMF_VIEW (l->data);
315 BamfWindow *list_win = BAMF_WINDOW (l->data);
316
317 guint32 list_xid = bamf_window_get_xid (list_win);
318
319 /* We try to match windows by xid */
320 if (local_xid != 0 && local_xid == list_xid)
321 {
322 matched_view = list_view;
323 break;
324 }
325 }
326 }
327
328 if (matched_view)
329 {
330 created = FALSE;
331 g_object_unref (view);
332
333 view = matched_view;
334 bamf_view_set_path (view, path);
335 g_object_ref_sink (view);
336 }
337
224 if (view)338 if (view)
225 {339 {
226 bamf_factory_register_view (factory, view, path);340 bamf_factory_register_view (factory, view, path);
@@ -231,8 +345,7 @@
231 g_object_ref_sink (view);345 g_object_ref_sink (view);
232 }346 }
233 }347 }
234 348
235 g_free (type);
236 return view;349 return view;
237}350}
238351
239352
=== modified file 'lib/libbamf/bamf-factory.h'
--- lib/libbamf/bamf-factory.h 2010-10-26 03:48:12 +0000
+++ lib/libbamf/bamf-factory.h 2012-04-26 17:14:21 +0000
@@ -54,6 +54,15 @@
54typedef struct _BamfFactoryClass BamfFactoryClass;54typedef struct _BamfFactoryClass BamfFactoryClass;
55typedef struct _BamfFactoryPrivate BamfFactoryPrivate;55typedef struct _BamfFactoryPrivate BamfFactoryPrivate;
5656
57typedef enum
58{
59 BAMF_FACTORY_VIEW,
60 BAMF_FACTORY_WINDOW,
61 BAMF_FACTORY_APPLICATION,
62 BAMF_FACTORY_INDICATOR,
63 BAMF_FACTORY_NONE
64} BamfFactoryViewType;
65
57struct _BamfFactory66struct _BamfFactory
58{67{
59 GObject parent;68 GObject parent;
@@ -71,6 +80,14 @@
71BamfView * bamf_factory_view_for_path (BamfFactory * factory,80BamfView * bamf_factory_view_for_path (BamfFactory * factory,
72 const char * path);81 const char * path);
7382
83BamfView * bamf_factory_view_for_path_type (BamfFactory * factory,
84 const char * path,
85 BamfFactoryViewType type);
86
87BamfView * bamf_factory_view_for_path_type_str (BamfFactory * factory,
88 const char * path,
89 const char * type);
90
74BamfApplication * bamf_factory_app_for_file (BamfFactory * factory,91BamfApplication * bamf_factory_app_for_file (BamfFactory * factory,
75 const char * path,92 const char * path,
76 gboolean create);93 gboolean create);
7794
=== modified file 'lib/libbamf/bamf-matcher.c'
--- lib/libbamf/bamf-matcher.c 2012-04-24 14:14:44 +0000
+++ lib/libbamf/bamf-matcher.c 2012-04-26 17:14:21 +0000
@@ -144,8 +144,12 @@
144 BamfMatcher *matcher)144 BamfMatcher *matcher)
145{145{
146 BamfView *view;146 BamfView *view;
147147 BamfFactory *factory = bamf_factory_get_default ();
148 view = bamf_factory_view_for_path (bamf_factory_get_default (), path);148
149 view = bamf_factory_view_for_path_type_str (factory, path, type);
150
151 if (!BAMF_IS_VIEW (view))
152 return;
149153
150 g_signal_emit (matcher, matcher_signals[VIEW_OPENED], 0, view);154 g_signal_emit (matcher, matcher_signals[VIEW_OPENED], 0, view);
151}155}
@@ -157,8 +161,9 @@
157 BamfMatcher *matcher)161 BamfMatcher *matcher)
158{162{
159 BamfView *view;163 BamfView *view;
164 BamfFactory *factory = bamf_factory_get_default ();
160165
161 view = bamf_factory_view_for_path (bamf_factory_get_default (), path);166 view = bamf_factory_view_for_path_type_str (factory, path, type);
162167
163 if (!BAMF_IS_VIEW (view))168 if (!BAMF_IS_VIEW (view))
164 return;169 return;
@@ -172,14 +177,12 @@
172 char *new_path,177 char *new_path,
173 BamfMatcher *matcher)178 BamfMatcher *matcher)
174{179{
175 BamfView *old_view = NULL;180 BamfView *old_view;
176 BamfView *new_view = NULL;181 BamfView *new_view;
177182
178 if (old_path && strlen (old_path) > 0)183 BamfFactory *factory = bamf_factory_get_default ();
179 old_view = bamf_factory_view_for_path (bamf_factory_get_default (), old_path);184 old_view = bamf_factory_view_for_path_type (factory, old_path, BAMF_FACTORY_APPLICATION);
180185 new_view = bamf_factory_view_for_path_type (factory, new_path, BAMF_FACTORY_APPLICATION);
181 if (new_path && strlen (new_path) > 0)
182 new_view = bamf_factory_view_for_path (bamf_factory_get_default (), new_path);
183186
184 g_signal_emit (matcher, matcher_signals[ACTIVE_APPLICATION_CHANGED], 0, old_view, new_view);187 g_signal_emit (matcher, matcher_signals[ACTIVE_APPLICATION_CHANGED], 0, old_view, new_view);
185}188}
@@ -190,14 +193,12 @@
190 char *new_path,193 char *new_path,
191 BamfMatcher *matcher)194 BamfMatcher *matcher)
192{195{
193 BamfView *old_view = NULL;196 BamfView *old_view;
194 BamfView *new_view = NULL;197 BamfView *new_view;
195198
196 if (old_path && strlen (old_path) > 0)199 BamfFactory *factory = bamf_factory_get_default ();
197 old_view = bamf_factory_view_for_path (bamf_factory_get_default (), old_path);200 old_view = bamf_factory_view_for_path_type (factory, old_path, BAMF_FACTORY_WINDOW);
198201 new_view = bamf_factory_view_for_path_type (factory, new_path, BAMF_FACTORY_WINDOW);
199 if (new_path && strlen (new_path) > 0)
200 new_view = bamf_factory_view_for_path (bamf_factory_get_default (), new_path);
201202
202 g_signal_emit (matcher, matcher_signals[ACTIVE_WINDOW_CHANGED], 0, old_view, new_view);203 g_signal_emit (matcher, matcher_signals[ACTIVE_WINDOW_CHANGED], 0, old_view, new_view);
203}204}
@@ -373,10 +374,17 @@
373 return NULL;374 return NULL;
374 }375 }
375376
377 if (app && app[0] == '\0')
378 {
379 g_free (app);
380 return NULL;
381 }
382
376 if (!app)383 if (!app)
377 return NULL;384 return NULL;
378385
379 view = bamf_factory_view_for_path (bamf_factory_get_default (), app);386 BamfFactory *factory = bamf_factory_get_default ();
387 view = bamf_factory_view_for_path_type (factory, app, BAMF_FACTORY_APPLICATION);
380 g_free (app);388 g_free (app);
381389
382 if (!BAMF_IS_APPLICATION (view))390 if (!BAMF_IS_APPLICATION (view))
@@ -390,7 +398,7 @@
390{398{
391 BamfMatcherPrivate *priv;399 BamfMatcherPrivate *priv;
392 BamfView *view;400 BamfView *view;
393 char *app = NULL;401 char *win = NULL;
394 GError *error = NULL;402 GError *error = NULL;
395403
396 g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);404 g_return_val_if_fail (BAMF_IS_MATCHER (matcher), NULL);
@@ -400,7 +408,7 @@
400 "ActiveWindow",408 "ActiveWindow",
401 &error,409 &error,
402 G_TYPE_INVALID,410 G_TYPE_INVALID,
403 G_TYPE_STRING, &app,411 G_TYPE_STRING, &win,
404 G_TYPE_INVALID))412 G_TYPE_INVALID))
405 {413 {
406 g_warning ("Failed to fetch path: %s", error->message);414 g_warning ("Failed to fetch path: %s", error->message);
@@ -408,11 +416,18 @@
408 return NULL;416 return NULL;
409 }417 }
410418
411 if (!app)419 if (win && win[0] == '\0')
420 {
421 g_free (win);
422 return NULL;
423 }
424
425 if (!win)
412 return NULL;426 return NULL;
413427
414 view = bamf_factory_view_for_path (bamf_factory_get_default (), app);428 BamfFactory *factory = bamf_factory_get_default ();
415 g_free (app);429 view = bamf_factory_view_for_path_type (factory, win, BAMF_FACTORY_WINDOW);
430 g_free (win);
416431
417 if (!BAMF_IS_WINDOW (view))432 if (!BAMF_IS_WINDOW (view))
418 return NULL;433 return NULL;
@@ -455,10 +470,17 @@
455 return NULL;470 return NULL;
456 }471 }
457472
473 if (app && app[0] == '\0')
474 {
475 g_free (app);
476 return NULL;
477 }
478
458 if (!app)479 if (!app)
459 return NULL;480 return NULL;
460481
461 view = bamf_factory_view_for_path (bamf_factory_get_default (), app);482 BamfFactory *factory = bamf_factory_get_default ();
483 view = bamf_factory_view_for_path_type (factory, app, BAMF_FACTORY_APPLICATION);
462 484
463 g_free (app);485 g_free (app);
464486
@@ -522,14 +544,16 @@
522 return NULL;544 return NULL;
523 }545 }
524546
525 g_return_val_if_fail (array, NULL);547 if (!array)
548 return NULL;
526549
550 BamfFactory *factory = bamf_factory_get_default ();
527 len = g_strv_length (array);551 len = g_strv_length (array);
528 for (i = len-1; i >= 0; i--)552 for (i = len-1; i >= 0; i--)
529 {553 {
530 view = bamf_factory_view_for_path (bamf_factory_get_default (), array[i]);554 view = bamf_factory_view_for_path_type (factory, array[i], BAMF_FACTORY_APPLICATION);
531555
532 if (view)556 if (BAMF_IS_APPLICATION (view))
533 result = g_list_prepend (result, view);557 result = g_list_prepend (result, view);
534 }558 }
535 559
@@ -563,14 +587,16 @@
563 return NULL;587 return NULL;
564 }588 }
565589
566 g_return_val_if_fail (array, NULL);590 if (!array)
591 return NULL;
567592
593 BamfFactory *factory = bamf_factory_get_default ();
568 len = g_strv_length (array);594 len = g_strv_length (array);
569 for (i = len-1; i >= 0; i--)595 for (i = len-1; i >= 0; i--)
570 {596 {
571 view = bamf_factory_view_for_path (bamf_factory_get_default (), array[i]);597 view = bamf_factory_view_for_path_type (factory, array[i], BAMF_FACTORY_WINDOW);
572598
573 if (view)599 if (BAMF_IS_WINDOW (view))
574 result = g_list_prepend (result, view);600 result = g_list_prepend (result, view);
575 }601 }
576 602
@@ -606,14 +632,16 @@
606 return NULL;632 return NULL;
607 }633 }
608634
609 g_return_val_if_fail (array, NULL);635 if (!array)
636 return NULL;
610637
638 BamfFactory *factory = bamf_factory_get_default ();
611 len = g_strv_length (array);639 len = g_strv_length (array);
612 for (i = len-1; i >= 0; i--)640 for (i = len-1; i >= 0; i--)
613 {641 {
614 view = bamf_factory_view_for_path (bamf_factory_get_default (), array[i]);642 view = bamf_factory_view_for_path_type (factory, array[i], BAMF_FACTORY_WINDOW);
615643
616 if (view)644 if (BAMF_IS_WINDOW (view))
617 result = g_list_prepend (result, view);645 result = g_list_prepend (result, view);
618 }646 }
619 647
@@ -664,14 +692,16 @@
664 return NULL;692 return NULL;
665 }693 }
666694
667 g_return_val_if_fail (array, NULL);695 if (!array)
696 return NULL;
668697
698 BamfFactory *factory = bamf_factory_get_default ();
669 len = g_strv_length (array);699 len = g_strv_length (array);
670 for (i = len-1; i >= 0; i--)700 for (i = len-1; i >= 0; i--)
671 {701 {
672 view = bamf_factory_view_for_path (bamf_factory_get_default (), array[i]);702 view = bamf_factory_view_for_path_type (factory, array[i], BAMF_FACTORY_APPLICATION);
673703
674 if (view)704 if (BAMF_IS_APPLICATION (view))
675 result = g_list_prepend (result, view);705 result = g_list_prepend (result, view);
676 }706 }
677707
678708
=== modified file 'lib/libbamf/bamf-view-private.h'
--- lib/libbamf/bamf-view-private.h 2010-11-01 05:07:11 +0000
+++ lib/libbamf/bamf-view-private.h 2012-04-26 17:14:21 +0000
@@ -31,6 +31,8 @@
3131
32gboolean bamf_view_remote_ready (BamfView *view);32gboolean bamf_view_remote_ready (BamfView *view);
3333
34void bamf_view_reset_flags (BamfView *view);
35
34void bamf_view_set_name (BamfView *view, const char *name);36void bamf_view_set_name (BamfView *view, const char *name);
3537
36void bamf_view_set_icon (BamfView *view, const char *icon);38void bamf_view_set_icon (BamfView *view, const char *icon);
3739
=== modified file 'lib/libbamf/bamf-view.c'
--- lib/libbamf/bamf-view.c 2012-04-22 15:10:47 +0000
+++ lib/libbamf/bamf-view.c 2012-04-26 17:14:21 +0000
@@ -111,7 +111,7 @@
111 if (value)111 if (value)
112 priv->set_flags |= flag;112 priv->set_flags |= flag;
113 else113 else
114 priv->set_flags = priv->set_flags & ~flag;114 priv->set_flags &= ~flag;
115 115
116 priv->checked_flags |= flag;116 priv->checked_flags |= flag;
117}117}
@@ -386,7 +386,7 @@
386 return BAMF_VIEW_GET_CLASS (self)->get_name (self);386 return BAMF_VIEW_GET_CLASS (self)->get_name (self);
387387
388 if (!bamf_view_remote_ready (self))388 if (!bamf_view_remote_ready (self))
389 return g_strdup(priv->local_name);389 return g_strdup (priv->local_name);
390 390
391 if (!dbus_g_proxy_call (priv->proxy,391 if (!dbus_g_proxy_call (priv->proxy,
392 "Name",392 "Name",
@@ -439,7 +439,7 @@
439 G_TYPE_STRING, &type,439 G_TYPE_STRING, &type,
440 G_TYPE_INVALID))440 G_TYPE_INVALID))
441 {441 {
442 g_warning ("Failed to fetch view type at %s: %s", dbus_g_proxy_get_path (priv->proxy), error->message);442 g_warning ("Failed to fetch view type at %s: %s", dbus_g_proxy_get_path (priv->proxy), error ? error->message : "");
443 g_error_free (error);443 g_error_free (error);
444 return NULL;444 return NULL;
445 }445 }
@@ -543,6 +543,16 @@
543}543}
544544
545static void545static void
546on_view_proxy_destroyed (GObject *proxy, gpointer user_data)
547{
548 BamfView *view = user_data;
549 g_return_if_fail (BAMF_IS_VIEW (view));
550
551 view->priv->checked_flags = 0x0;
552 view->priv->proxy = NULL;
553}
554
555static void
546bamf_view_on_closed (DBusGProxy *proxy, BamfView *self)556bamf_view_on_closed (DBusGProxy *proxy, BamfView *self)
547{557{
548 BamfViewPrivate *priv;558 BamfViewPrivate *priv;
@@ -593,6 +603,8 @@
593 "UserVisibleChanged",603 "UserVisibleChanged",
594 (GCallback) bamf_view_on_user_visible_changed,604 (GCallback) bamf_view_on_user_visible_changed,
595 self);605 self);
606
607 g_signal_handlers_disconnect_by_func (priv->proxy, on_view_proxy_destroyed, self);
596 g_object_unref (priv->proxy);608 g_object_unref (priv->proxy);
597 priv->proxy = NULL;609 priv->proxy = NULL;
598 }610 }
@@ -737,6 +749,7 @@
737 (GCallback) bamf_view_on_name_changed,749 (GCallback) bamf_view_on_name_changed,
738 view);750 view);
739751
752 g_signal_handlers_disconnect_by_func (priv->proxy, on_view_proxy_destroyed, view);
740 g_object_unref (priv->proxy);753 g_object_unref (priv->proxy);
741 priv->proxy = NULL;754 priv->proxy = NULL;
742 }755 }
@@ -753,6 +766,40 @@
753}766}
754767
755void768void
769bamf_view_reset_flags (BamfView *view)
770{
771 BamfViewPrivate *priv;
772 g_return_if_fail (BAMF_IS_VIEW (view));
773
774 priv = view->priv;
775 priv->checked_flags = 0x0;
776
777 if (bamf_view_user_visible (view))
778 {
779 g_signal_emit (G_OBJECT(view), view_signals[VISIBLE_CHANGED], 0, TRUE);
780 g_object_notify (G_OBJECT (view), "user-visible");
781 }
782
783 if (bamf_view_is_active (view))
784 {
785 g_signal_emit (G_OBJECT(view), view_signals[ACTIVE_CHANGED], 0, TRUE);
786 g_object_notify (G_OBJECT (view), "active");
787 }
788
789 if (bamf_view_is_running (view))
790 {
791 g_signal_emit (G_OBJECT(view), view_signals[RUNNING_CHANGED], 0, TRUE);
792 g_object_notify (G_OBJECT (view), "running");
793 }
794
795 if (bamf_view_is_urgent (view))
796 {
797 g_signal_emit (G_OBJECT(view), view_signals[URGENT_CHANGED], 0, TRUE);
798 g_object_notify (G_OBJECT (view), "urgent");
799 }
800}
801
802void
756bamf_view_set_path (BamfView *view, const char *path)803bamf_view_set_path (BamfView *view, const char *path)
757{804{
758 BamfViewPrivate *priv;805 BamfViewPrivate *priv;
@@ -766,18 +813,27 @@
766 {813 {
767 g_free (priv->path);814 g_free (priv->path);
768 }815 }
769 816
817 if (priv->proxy)
818 {
819 g_signal_handlers_disconnect_by_func (priv->proxy, on_view_proxy_destroyed, view);
820 g_object_unref (priv->proxy);
821 }
822
770 priv->path = g_strdup (path);823 priv->path = g_strdup (path);
771 priv->proxy = dbus_g_proxy_new_for_name (priv->connection,824 priv->proxy = dbus_g_proxy_new_for_name (priv->connection,
772 "org.ayatana.bamf",825 "org.ayatana.bamf",
773 priv->path,826 priv->path,
774 "org.ayatana.bamf.view");827 "org.ayatana.bamf.view");
828
775 if (priv->proxy == NULL)829 if (priv->proxy == NULL)
776 {830 {
777 g_critical ("Unable to get org.ayatana.bamf.view view");831 g_critical ("Unable to get org.ayatana.bamf.view view");
778 return;832 return;
779 }833 }
780834
835 g_signal_connect (priv->proxy, "destroy", G_CALLBACK (on_view_proxy_destroyed), view);
836
781 dbus_g_proxy_add_signal (priv->proxy,837 dbus_g_proxy_add_signal (priv->proxy,
782 "ActiveChanged",838 "ActiveChanged",
783 G_TYPE_BOOLEAN,839 G_TYPE_BOOLEAN,
@@ -868,32 +924,9 @@
868924
869 if (bamf_view_is_sticky (view))925 if (bamf_view_is_sticky (view))
870 {926 {
871 priv->checked_flags = 0x0;927 bamf_view_reset_flags (view);
872
873 if (bamf_view_user_visible (view))
874 {
875 g_signal_emit (G_OBJECT(view), view_signals[VISIBLE_CHANGED], 0, TRUE);
876 g_object_notify (G_OBJECT (view), "user-visible");
877 }
878
879 if (bamf_view_is_active (view))
880 {
881 g_signal_emit (G_OBJECT(view), view_signals[ACTIVE_CHANGED], 0, TRUE);
882 g_object_notify (G_OBJECT (view), "active");
883 }
884
885 if (bamf_view_is_running (view))
886 {
887 g_signal_emit (G_OBJECT(view), view_signals[RUNNING_CHANGED], 0, TRUE);
888 g_object_notify (G_OBJECT (view), "running");
889 }
890
891 if (bamf_view_is_urgent (view))
892 {
893 g_signal_emit (G_OBJECT(view), view_signals[URGENT_CHANGED], 0, TRUE);
894 g_object_notify (G_OBJECT (view), "urgent");
895 }
896 }928 }
929
897 if (BAMF_VIEW_GET_CLASS (view)->set_path)930 if (BAMF_VIEW_GET_CLASS (view)->set_path)
898 BAMF_VIEW_GET_CLASS (view)->set_path (view, path);931 BAMF_VIEW_GET_CLASS (view)->set_path (view, path);
899}932}
900933
=== modified file 'lib/libbamf/bamf-window.c'
--- lib/libbamf/bamf-window.c 2012-02-27 18:34:30 +0000
+++ lib/libbamf/bamf-window.c 2012-04-26 17:14:21 +0000
@@ -103,7 +103,8 @@
103 if (!path)103 if (!path)
104 return NULL;104 return NULL;
105105
106 transient = bamf_factory_view_for_path (bamf_factory_get_default (), path);106 BamfFactory *factory = bamf_factory_get_default ();
107 transient = bamf_factory_view_for_path_type (factory, path, BAMF_FACTORY_WINDOW);
107 g_free (path); 108 g_free (path);
108109
109 if (!BAMF_IS_WINDOW (transient))110 if (!BAMF_IS_WINDOW (transient))

Subscribers

People subscribed via source and target branches