[gnome-flashback] desktop: add size-changed signal to GfDummyIcon
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-flashback] desktop: add size-changed signal to GfDummyIcon
- Date: Wed, 13 Nov 2019 22:33:05 +0000 (UTC)
commit 705c8843486e6c622b39c2a3a7c6792e36a7528b
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Wed Nov 13 17:35:40 2019 +0200
desktop: add size-changed signal to GfDummyIcon
gnome-flashback/libdesktop/gf-dummy-icon.c | 126 +++++++++++++++++++++++++++++
gnome-flashback/libdesktop/gf-dummy-icon.h | 6 +-
gnome-flashback/libdesktop/gf-icon.c | 34 +++++++-
3 files changed, 163 insertions(+), 3 deletions(-)
---
diff --git a/gnome-flashback/libdesktop/gf-dummy-icon.c b/gnome-flashback/libdesktop/gf-dummy-icon.c
index 2a69d4c..8f6f6a7 100644
--- a/gnome-flashback/libdesktop/gf-dummy-icon.c
+++ b/gnome-flashback/libdesktop/gf-dummy-icon.c
@@ -21,18 +21,132 @@
struct _GfDummyIcon
{
GfIcon parent;
+
+ guint size_id;
+
+ int width;
+ int height;
};
+enum
+{
+ SIZE_CHANGED,
+
+ LAST_SIGNAL
+};
+
+static guint icon_signals[LAST_SIGNAL] = { 0 };
+
G_DEFINE_TYPE (GfDummyIcon, gf_dummy_icon, GF_TYPE_ICON)
+static gboolean
+size_cb (gpointer user_data)
+{
+ GfDummyIcon *self;
+ GtkRequisition icon_size;
+
+ self = GF_DUMMY_ICON (user_data);
+
+ gtk_widget_get_preferred_size (GTK_WIDGET (self), &icon_size, NULL);
+
+ if (self->width != icon_size.width ||
+ self->height != icon_size.height)
+ {
+ self->width = icon_size.width;
+ self->height = icon_size.height;
+
+ g_signal_emit (self, icon_signals[SIZE_CHANGED], 0);
+ }
+
+ self->size_id = 0;
+
+ return G_SOURCE_REMOVE;
+}
+
+static void
+recalculate_size (GfDummyIcon *self)
+{
+ if (self->size_id != 0)
+ return;
+
+ self->size_id = g_idle_add (size_cb, self);
+ g_source_set_name_by_id (self->size_id, "[gnome-flashback] size_cb");
+}
+
+static void
+icon_size_cb (GdkMonitor *monitor,
+ GParamSpec *pspec,
+ GfDummyIcon *self)
+{
+ recalculate_size (self);
+}
+
+static void
+extra_text_width_cb (GdkMonitor *monitor,
+ GParamSpec *pspec,
+ GfDummyIcon *self)
+{
+ recalculate_size (self);
+}
+
+static void
+gf_dummy_icon_dispose (GObject *object)
+{
+ GfDummyIcon *self;
+
+ self = GF_DUMMY_ICON (object);
+
+ if (self->size_id != 0)
+ {
+ g_source_remove (self->size_id);
+ self->size_id = 0;
+ }
+
+ G_OBJECT_CLASS (gf_dummy_icon_parent_class)->dispose (object);
+}
+
+static void
+gf_dummy_icon_style_updated (GtkWidget *widget)
+{
+ GTK_WIDGET_CLASS (gf_dummy_icon_parent_class)->style_updated (widget);
+ recalculate_size (GF_DUMMY_ICON (widget));
+}
+
+static void
+install_signals (void)
+{
+ icon_signals[SIZE_CHANGED] =
+ g_signal_new ("size-changed", GF_TYPE_DUMMY_ICON,
+ G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL,
+ G_TYPE_NONE, 0);
+}
+
static void
gf_dummy_icon_class_init (GfDummyIconClass *self_class)
{
+ GObjectClass *object_class;
+ GtkWidgetClass *widget_class;
+
+ object_class = G_OBJECT_CLASS (self_class);
+ widget_class = GTK_WIDGET_CLASS (self_class);
+
+ object_class->dispose = gf_dummy_icon_dispose;
+
+ widget_class->style_updated = gf_dummy_icon_style_updated;
+
+ install_signals ();
}
static void
gf_dummy_icon_init (GfDummyIcon *self)
{
+ g_signal_connect (self, "notify::icon-size",
+ G_CALLBACK (icon_size_cb),
+ self);
+
+ g_signal_connect (self, "notify::extra-text-width",
+ G_CALLBACK (extra_text_width_cb),
+ self);
}
GtkWidget *
@@ -68,3 +182,15 @@ gf_dummy_icon_new (void)
return widget;
}
+
+int
+gf_dummy_icon_get_width (GfDummyIcon *self)
+{
+ return self->width;
+}
+
+int
+gf_dummy_icon_get_height (GfDummyIcon *self)
+{
+ return self->height;
+}
diff --git a/gnome-flashback/libdesktop/gf-dummy-icon.h b/gnome-flashback/libdesktop/gf-dummy-icon.h
index e774410..95fa3ab 100644
--- a/gnome-flashback/libdesktop/gf-dummy-icon.h
+++ b/gnome-flashback/libdesktop/gf-dummy-icon.h
@@ -25,7 +25,11 @@ G_BEGIN_DECLS
#define GF_TYPE_DUMMY_ICON (gf_dummy_icon_get_type ())
G_DECLARE_FINAL_TYPE (GfDummyIcon, gf_dummy_icon, GF, DUMMY_ICON, GfIcon)
-GtkWidget *gf_dummy_icon_new (void);
+GtkWidget *gf_dummy_icon_new (void);
+
+int gf_dummy_icon_get_width (GfDummyIcon *self);
+
+int gf_dummy_icon_get_height (GfDummyIcon *self);
G_END_DECLS
diff --git a/gnome-flashback/libdesktop/gf-icon.c b/gnome-flashback/libdesktop/gf-icon.c
index bccad7e..37899ca 100644
--- a/gnome-flashback/libdesktop/gf-icon.c
+++ b/gnome-flashback/libdesktop/gf-icon.c
@@ -313,6 +313,35 @@ gf_icon_finalize (GObject *object)
G_OBJECT_CLASS (gf_icon_parent_class)->finalize (object);
}
+static void
+gf_icon_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+
+ GfIcon *self;
+ GfIconPrivate *priv;
+
+ self = GF_ICON (object);
+ priv = gf_icon_get_instance_private (self);
+
+ switch (property_id)
+ {
+ case PROP_ICON_SIZE:
+ g_value_set_enum (value, priv->icon_size);
+ break;
+
+ case PROP_EXTRA_TEXT_WIDTH:
+ g_value_set_uint (value, priv->extra_text_width);
+ break;
+
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
static void
gf_icon_set_property (GObject *object,
guint property_id,
@@ -401,7 +430,7 @@ install_properties (GObjectClass *object_class)
GF_TYPE_ICON_SIZE,
GF_ICON_SIZE_48PX,
G_PARAM_CONSTRUCT |
- G_PARAM_WRITABLE |
+ G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
icon_properties[PROP_EXTRA_TEXT_WIDTH] =
@@ -410,7 +439,7 @@ install_properties (GObjectClass *object_class)
"extra-text-width",
0, 100, 48,
G_PARAM_CONSTRUCT |
- G_PARAM_WRITABLE |
+ G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, LAST_PROP, icon_properties);
@@ -441,6 +470,7 @@ gf_icon_class_init (GfIconClass *self_class)
object_class->constructed = gf_icon_constructed;
object_class->dispose = gf_icon_dispose;
object_class->finalize = gf_icon_finalize;
+ object_class->get_property = gf_icon_get_property;
object_class->set_property = gf_icon_set_property;
widget_class->get_preferred_width = gf_icon_get_preferred_width;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]