From 9a8a4a8b1479d004d1fb65a9ac6714318129bdad Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sat, 6 Sep 2014 06:41:05 +0200 Subject: [PATCH] widget: Don't assume opacity is 100% ... just because there is no style context instantiated yet. Instead, instantiate a style context during realize() and ask it. Fixes problems with dim labels not being dimmed on first show. Testcase included. https://bugzilla.gnome.org/show_bug.cgi?id=735240 --- gtk/gtkwidget.c | 21 +++++++--------- testsuite/reftests/Makefile.am | 3 +++ testsuite/reftests/opacity-initial.css | 3 +++ testsuite/reftests/opacity-initial.ref.ui | 11 +++++++++ testsuite/reftests/opacity-initial.ui | 29 +++++++++++++++++++++++ 5 files changed, 55 insertions(+), 12 deletions(-) create mode 100644 testsuite/reftests/opacity-initial.css create mode 100644 testsuite/reftests/opacity-initial.ref.ui create mode 100644 testsuite/reftests/opacity-initial.ui diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 6f93a597b3..2593cbf14c 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -5527,9 +5527,7 @@ gtk_widget_realize (GtkWidget *widget) _gtk_widget_enable_device_events (widget); gtk_widget_update_devices_mask (widget, TRUE); - if (gtk_widget_is_toplevel (widget)) - gdk_window_set_opacity (priv->window, - priv->alpha / 255.0); + gtk_widget_update_alpha (widget); if (priv->context) gtk_style_context_set_scale (priv->context, gtk_widget_get_scale_factor (widget)); @@ -15913,6 +15911,7 @@ static void gtk_widget_update_alpha (GtkWidget *widget) { GtkWidgetPrivate *priv; + GtkStyleContext *context; gdouble opacity; guint8 alpha; @@ -15920,15 +15919,13 @@ gtk_widget_update_alpha (GtkWidget *widget) alpha = priv->user_alpha; - if (priv->context) - { - opacity = - _gtk_css_number_value_get (_gtk_style_context_peek_property (priv->context, - GTK_CSS_PROPERTY_OPACITY), - 100); - opacity = CLAMP (opacity, 0.0, 1.0); - alpha = round (priv->user_alpha * opacity); - } + context = gtk_widget_get_style_context (widget); + opacity = + _gtk_css_number_value_get (_gtk_style_context_peek_property (context, + GTK_CSS_PROPERTY_OPACITY), + 100); + opacity = CLAMP (opacity, 0.0, 1.0); + alpha = round (priv->user_alpha * opacity); if (alpha == priv->alpha) return; diff --git a/testsuite/reftests/Makefile.am b/testsuite/reftests/Makefile.am index 5f84f8c81f..0853a007f5 100644 --- a/testsuite/reftests/Makefile.am +++ b/testsuite/reftests/Makefile.am @@ -314,6 +314,9 @@ testdata = \ opacity.css \ opacity.ui \ opacity.ref.ui \ + opacity-initial.css \ + opacity-initial.ref.ui \ + opacity-initial.ui \ overlay-no-main-widget.ref.ui \ overlay-no-main-widget.ui \ paned-undersized.css \ diff --git a/testsuite/reftests/opacity-initial.css b/testsuite/reftests/opacity-initial.css new file mode 100644 index 0000000000..611a8cd421 --- /dev/null +++ b/testsuite/reftests/opacity-initial.css @@ -0,0 +1,3 @@ +GtkLabel { + opacity: 0; +} diff --git a/testsuite/reftests/opacity-initial.ref.ui b/testsuite/reftests/opacity-initial.ref.ui new file mode 100644 index 0000000000..12403517bd --- /dev/null +++ b/testsuite/reftests/opacity-initial.ref.ui @@ -0,0 +1,11 @@ + + + + + + 200 + 100 + False + popup + + diff --git a/testsuite/reftests/opacity-initial.ui b/testsuite/reftests/opacity-initial.ui new file mode 100644 index 0000000000..9e02798575 --- /dev/null +++ b/testsuite/reftests/opacity-initial.ui @@ -0,0 +1,29 @@ + + + + + + 200 + 100 + False + popup + + + True + False + + + + + + True + False + I'm the invisible label. +Incredible how you can +see right through me. + + + + + +