From 755316ab027daa81e873da1191933e5e6fb7b9b4 Mon Sep 17 00:00:00 2001 From: Simon Steinbeiss Date: Tue, 30 May 2017 00:00:30 +0200 Subject: [PATCH] Make arrowbuttons blink with a CSS animation (Bug #13599) --- libxfce4panel/xfce-arrow-button.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/libxfce4panel/xfce-arrow-button.c b/libxfce4panel/xfce-arrow-button.c index 7d17a575..e728a5a7 100644 --- a/libxfce4panel/xfce-arrow-button.c +++ b/libxfce4panel/xfce-arrow-button.c @@ -107,8 +107,10 @@ struct _XfceArrowButtonPrivate * MAX_BLINKING_COUNT is reached */ guint blinking_counter; +#if !GTK_CHECK_VERSION (3, 0, 0) /* button relief when the blinking starts */ GtkReliefStyle last_relief; +#endif }; @@ -195,7 +197,9 @@ xfce_arrow_button_init (XfceArrowButton *button) button->priv->arrow_type = GTK_ARROW_UP; button->priv->blinking_timeout_id = 0; button->priv->blinking_counter = 0; +#if !GTK_CHECK_VERSION (3, 0, 0) button->priv->last_relief = GTK_RELIEF_NORMAL; +#endif /* set some widget properties */ gtk_widget_set_has_window (GTK_WIDGET (button), FALSE); @@ -207,7 +211,7 @@ xfce_arrow_button_init (XfceArrowButton *button) launcher buttons to overlap when panels have a fairly normal size */ context = gtk_widget_get_style_context (GTK_WIDGET (button)); provider = gtk_css_provider_new (); - gtk_css_provider_load_from_data (provider, ".xfce4-panel button { padding: 0; }", -1, NULL); + gtk_css_provider_load_from_data (provider, "@keyframes blink { from { opacity: 1.0; } 50% { opacity: 0.4; } to { opacity: 0.8; } } .xfce4-panel button { padding: 0; } .xfce4-panel button.blinking { animation-name: blink; animation: blink 2s linear infinite; }", -1, NULL); gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); @@ -590,6 +594,13 @@ static gboolean xfce_arrow_button_blinking_timeout (gpointer user_data) { XfceArrowButton *button = XFCE_ARROW_BUTTON (user_data); + +#if GTK_CHECK_VERSION (3, 0, 0) + GtkStyleContext *context; + + context = gtk_widget_get_style_context (GTK_WIDGET (button)); + gtk_style_context_add_class (context, "blinking"); +#else GtkStyle *style; GtkRcStyle *rc; @@ -609,6 +620,7 @@ xfce_arrow_button_blinking_timeout (gpointer user_data) rc->bg[GTK_STATE_NORMAL] = style->bg[GTK_STATE_SELECTED]; gtk_widget_modify_style(GTK_WIDGET (button), rc); } +#endif return (button->priv->blinking_counter++ < MAX_BLINKING_COUNT); } @@ -619,12 +631,20 @@ static void xfce_arrow_button_blinking_timeout_destroyed (gpointer user_data) { XfceArrowButton *button = XFCE_ARROW_BUTTON (user_data); + +#if GTK_CHECK_VERSION (3, 0, 0) + GtkStyleContext *context; + + context = gtk_widget_get_style_context (GTK_WIDGET (button)); + gtk_style_context_remove_class (context, "blinking"); +#else GtkRcStyle *rc; rc = gtk_widget_get_modifier_style (GTK_WIDGET (button)); gtk_button_set_relief (GTK_BUTTON (button), button->priv->last_relief); PANEL_UNSET_FLAG (rc->color_flags[GTK_STATE_NORMAL], GTK_RC_BG); gtk_widget_modify_style (GTK_WIDGET (button), rc); +#endif button->priv->blinking_timeout_id = 0; button->priv->blinking_counter = 0; @@ -738,8 +758,10 @@ xfce_arrow_button_set_blinking (XfceArrowButton *button, if (blinking) { +#if !GTK_CHECK_VERSION (3, 0, 0) /* store the relief of the button */ button->priv->last_relief = gtk_button_get_relief (GTK_BUTTON (button)); +#endif if (button->priv->blinking_timeout_id == 0) { -- 2.11.0