From 116eb992c13b32c7deda2fc6f87bca06f89ee113 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 28 Apr 2020 01:15:29 -0400 Subject: [PATCH] scalebutton: Add an active property This is set to TRUE while the popup is visible. We will use it to prevent the button from being hidden while the user is interacting with it. --- gtk/gtkscalebutton.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/gtk/gtkscalebutton.c b/gtk/gtkscalebutton.c index 809e790857..896683f2ea 100644 --- a/gtk/gtkscalebutton.c +++ b/gtk/gtkscalebutton.c @@ -98,7 +98,8 @@ enum PROP_VALUE, PROP_SIZE, PROP_ADJUSTMENT, - PROP_ICONS + PROP_ICONS, + PROP_ACTIVE }; typedef struct @@ -248,6 +249,13 @@ gtk_scale_button_class_init (GtkScaleButtonClass *klass) G_TYPE_STRV, GTK_PARAM_READWRITE)); + g_object_class_install_property (gobject_class, + PROP_ACTIVE, + g_param_spec_boolean ("active", + P_("Active"), + P_("Active"), + FALSE, + G_PARAM_READABLE)); /** * GtkScaleButton::value-changed: * @button: the object which received the signal @@ -403,6 +411,14 @@ gtk_scale_button_closed (GtkScaleButton *button) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button), FALSE); } +static void +notify_active (GObject *object, + GParamSpec *pspec, + GObject *button) +{ + g_object_notify (button, "active"); +} + static void gtk_scale_button_init (GtkScaleButton *button) { @@ -416,6 +432,9 @@ gtk_scale_button_init (GtkScaleButton *button) gtk_widget_init_template (GTK_WIDGET (button)); gtk_widget_set_parent (priv->dock, GTK_WIDGET (button)); + g_signal_connect (priv->dock, "notify::visible", + G_CALLBACK (notify_active), button); + /* Need a local reference to the adjustment */ priv->adjustment = gtk_adjustment_new (0, 0, 100, 2, 20, 0); g_object_ref_sink (priv->adjustment); @@ -503,6 +522,9 @@ gtk_scale_button_get_property (GObject *object, case PROP_ICONS: g_value_set_boxed (value, priv->icon_list); break; + case PROP_ACTIVE: + g_value_set_boolean (value, gtk_widget_get_visible (priv->dock)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break;