summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNelson Benítez León <nbenitezl@gmail.com>2019-09-06 23:52:48 -0400
committerNelson Benítez León <nbenitezl@gmail.com>2019-09-07 00:20:28 -0400
commitdad8d2dc1bb9dcabc33357a6e67a3a69d3ab3d71 (patch)
tree660b98da851bd5fbfc813496fccfb5de852d02d9
parentb136c77031f4fbb4f4e7e100a1dcdbeac14dd91a (diff)
downloadgtk+-dad8d2dc1bb9dcabc33357a6e67a3a69d3ab3d71.tar.gz
GtkScaleButton: fix unwanted state propagationBUG_scale_button_propagated_state
GtkScaleButton/GtkVolumeButton use a popover to show content. With the new GTK4 event model clicking or hovering on that child popover produces ACTIVE and PRELIGHT states that are propagated to the main button, this is unwanted behaviour as the button's appearance changes according to those. We connect to the "state-flags-changed" signal of GtkScaleButton, and remove the unwanted state flags after verifying they're coming from the popover. Fixes issue #2063
-rw-r--r--gtk/gtkscalebutton.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/gtk/gtkscalebutton.c b/gtk/gtkscalebutton.c
index fa683db75f..836cc3c8c3 100644
--- a/gtk/gtkscalebutton.c
+++ b/gtk/gtkscalebutton.c
@@ -157,6 +157,9 @@ static gboolean gtk_scale_button_scroll_controller_scroll (GtkEventControllerScr
gdouble dx,
gdouble dy,
GtkScaleButton *button);
+static void gtk_scale_button_state_flags_changed (GtkWidget *widget,
+ GtkStateFlags previous_state,
+ gpointer user_data);
G_DEFINE_TYPE_WITH_CODE (GtkScaleButton, gtk_scale_button, GTK_TYPE_BUTTON,
G_ADD_PRIVATE (GtkScaleButton)
@@ -378,6 +381,8 @@ gtk_scale_button_init (GtkScaleButton *button)
gtk_widget_init_template (GTK_WIDGET (button));
gtk_popover_set_relative_to (GTK_POPOVER (priv->dock), GTK_WIDGET (button));
+ g_signal_connect (button, "state-flags-changed",
+ G_CALLBACK (gtk_scale_button_state_flags_changed), priv->dock);
/* Need a local reference to the adjustment */
priv->adjustment = gtk_adjustment_new (0, 0, 100, 2, 20, 0);
@@ -498,6 +503,7 @@ gtk_scale_button_dispose (GObject *object)
GtkScaleButton *button = GTK_SCALE_BUTTON (object);
GtkScaleButtonPrivate *priv = gtk_scale_button_get_instance_private (button);
+ g_signal_handlers_disconnect_by_func (button, gtk_scale_button_state_flags_changed, priv->dock);
g_clear_pointer (&priv->dock, gtk_widget_unparent);
if (priv->click_id != 0)
@@ -1010,3 +1016,24 @@ gtk_scale_button_size_allocate (GtkWidget *widget,
gtk_native_check_resize (GTK_NATIVE (priv->dock));
}
+
+/* Removes ACTIVE and PRELIGHT states from the main button
+ * if they were propagated from the popover. Issue #2063 */
+static void
+gtk_scale_button_state_flags_changed (GtkWidget *widget,
+ GtkStateFlags previous_state,
+ gpointer user_data)
+{
+ GtkWidget *popover = GTK_WIDGET (user_data);
+ GtkStateFlags state_popover = gtk_widget_get_state_flags (popover);
+ GtkStateFlags flags_to_unset = 0;
+
+ if (state_popover & GTK_STATE_FLAG_ACTIVE)
+ flags_to_unset |= GTK_STATE_FLAG_ACTIVE;
+
+ if (state_popover & GTK_STATE_FLAG_PRELIGHT)
+ flags_to_unset |= GTK_STATE_FLAG_PRELIGHT;
+
+ if (flags_to_unset)
+ gtk_widget_unset_state_flags (widget, flags_to_unset);
+}