[libwnck/wip/muktupavels/icons: 4/5] application: get icons in getters
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libwnck/wip/muktupavels/icons: 4/5] application: get icons in getters
- Date: Sun, 26 Dec 2021 14:47:22 +0000 (UTC)
commit d00b32cae5c2678432eb442382faf03767b2eb06
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Sun Dec 19 22:16:20 2021 +0200
application: get icons in getters
libwnck users might not use icons at all or might use only normal
or mini icon. Redo code to get icons only when getters are used.
libwnck/application.c | 89 ++++++++++++++++++++-------------------------------
libwnck/private.h | 2 +-
libwnck/util.c | 2 +-
3 files changed, 36 insertions(+), 57 deletions(-)
---
diff --git a/libwnck/application.c b/libwnck/application.c
index 7c607d9..a30f1b2 100644
--- a/libwnck/application.c
+++ b/libwnck/application.c
@@ -74,8 +74,6 @@ struct _WnckApplicationPrivate
char *startup_id;
guint name_from_leader : 1; /* name is from group leader */
-
- guint need_emit_icon_changed : 1;
};
G_DEFINE_TYPE_WITH_PRIVATE (WnckApplication, wnck_application, G_TYPE_OBJECT);
@@ -87,7 +85,6 @@ enum {
};
static void emit_name_changed (WnckApplication *app);
-static void emit_icon_changed (WnckApplication *app);
static void reset_name (WnckApplication *app);
static void update_name (WnckApplication *app);
@@ -332,60 +329,50 @@ wnck_application_get_pid (WnckApplication *app)
}
static void
-get_icons (WnckApplication *app)
+get_icon (WnckApplication *app)
{
- GdkPixbuf *icon;
- GdkPixbuf *mini_icon;
-
- icon = NULL;
- mini_icon = NULL;
-
- if (_wnck_read_icon (app->priv->screen,
- app->priv->xwindow,
- app->priv->icon_cache,
- &icon,
- _wnck_get_default_icon_size ()))
- {
- app->priv->need_emit_icon_changed = TRUE;
-
- if (app->priv->icon)
- g_object_unref (G_OBJECT (app->priv->icon));
+ if (app->priv->icon != NULL)
+ return;
- app->priv->icon = icon;
- }
+ _wnck_read_icon (app->priv->screen,
+ app->priv->xwindow,
+ app->priv->icon_cache,
+ &app->priv->icon,
+ _wnck_get_default_icon_size ());
- if (_wnck_read_icon (app->priv->screen,
- app->priv->xwindow,
- app->priv->mini_icon_cache,
- &mini_icon,
- _wnck_get_default_mini_icon_size ()))
- {
- app->priv->need_emit_icon_changed = TRUE;
+ /* FIXME we should really fall back to using the icon
+ * for one of the windows. But then we need to be more
+ * complicated about icon_changed and when the icon
+ * needs updating and all that.
+ */
+}
- if (app->priv->mini_icon)
- g_object_unref (G_OBJECT (app->priv->mini_icon));
+static void
+get_mini_icon (WnckApplication *app)
+{
+ if (app->priv->mini_icon != NULL)
+ return;
- app->priv->mini_icon = mini_icon;
- }
+ _wnck_read_icon (app->priv->screen,
+ app->priv->xwindow,
+ app->priv->mini_icon_cache,
+ &app->priv->mini_icon,
+ _wnck_get_default_mini_icon_size ());
/* FIXME we should really fall back to using the icon
* for one of the windows. But then we need to be more
* complicated about icon_changed and when the icon
* needs updating and all that.
*/
-
- g_assert ((app->priv->icon && app->priv->mini_icon) ||
- !(app->priv->icon || app->priv->mini_icon));
}
void
-_wnck_application_load_icons (WnckApplication *app)
+_wnck_application_icon_changed (WnckApplication *app)
{
- g_return_if_fail (WNCK_IS_APPLICATION (app));
+ g_clear_object (&app->priv->icon);
+ g_clear_object (&app->priv->mini_icon);
- get_icons (app);
- if (app->priv->need_emit_icon_changed)
- emit_icon_changed (app);
+ g_signal_emit (app, signals[ICON_CHANGED], 0);
}
/* Prefer to get group icon from a window of type "normal" */
@@ -428,7 +415,7 @@ wnck_application_get_icon (WnckApplication *app)
{
g_return_val_if_fail (WNCK_IS_APPLICATION (app), NULL);
- _wnck_application_load_icons (app);
+ get_icon (app);
if (app->priv->icon)
return app->priv->icon;
@@ -459,7 +446,7 @@ wnck_application_get_mini_icon (WnckApplication *app)
{
g_return_val_if_fail (WNCK_IS_APPLICATION (app), NULL);
- _wnck_application_load_icons (app);
+ get_mini_icon (app);
if (app->priv->mini_icon)
return app->priv->mini_icon;
@@ -615,7 +602,7 @@ _wnck_application_add_window (WnckApplication *app,
/* see if we're using icon from a window */
if (app->priv->icon == NULL ||
app->priv->mini_icon == NULL)
- emit_icon_changed (app);
+ _wnck_application_icon_changed (app);
}
void
@@ -639,7 +626,7 @@ _wnck_application_remove_window (WnckApplication *app,
/* see if we're using icon from a window */
if (app->priv->icon == NULL ||
app->priv->mini_icon == NULL)
- emit_icon_changed (app);
+ _wnck_application_icon_changed (app);
}
void
@@ -676,7 +663,8 @@ _wnck_application_process_property_notify (WnckApplication *app,
xevent->xproperty.atom);
_wnck_icon_cache_property_changed (app->priv->mini_icon_cache,
xevent->xproperty.atom);
- emit_icon_changed (app);
+
+ _wnck_application_icon_changed (app);
}
else if (xevent->xproperty.atom ==
_wnck_atom_get ("_NET_STARTUP_ID"))
@@ -693,15 +681,6 @@ emit_name_changed (WnckApplication *app)
0);
}
-static void
-emit_icon_changed (WnckApplication *app)
-{
- app->priv->need_emit_icon_changed = FALSE;
- g_signal_emit (G_OBJECT (app),
- signals[ICON_CHANGED],
- 0);
-}
-
static void
reset_name (WnckApplication *app)
{
diff --git a/libwnck/private.h b/libwnck/private.h
index f1a4af2..fb6594f 100644
--- a/libwnck/private.h
+++ b/libwnck/private.h
@@ -95,7 +95,7 @@ void _wnck_application_remove_window (WnckApplication *app,
WnckApplication* _wnck_application_create (Window xwindow,
WnckScreen *screen);
void _wnck_application_destroy (WnckApplication *app);
-void _wnck_application_load_icons (WnckApplication *app);
+void _wnck_application_icon_changed (WnckApplication *app);
void _wnck_application_shutdown_all (void);
WnckClassGroup *_wnck_class_group_create (WnckScreen *screen,
diff --git a/libwnck/util.c b/libwnck/util.c
index e908a1c..9cf5b11 100644
--- a/libwnck/util.c
+++ b/libwnck/util.c
@@ -733,7 +733,7 @@ wnck_set_default_mini_icon_size (gsize size)
_wnck_window_load_icons (window);
if (WNCK_IS_APPLICATION (application))
- _wnck_application_load_icons (application);
+ _wnck_application_icon_changed (application);
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]