From e14b6433147666969f678b84d9df3e5d1d9d63db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Meyer?= Date: Sun, 10 Nov 2019 11:46:52 +0100 Subject: [PATCH 2/6] Fix color modifications in search entries The current code has no effect anymore in gtk3. This makes it work again. Instead of manually changing colors, however, use the "error" CSS class, so that things work consistently with the chosen gtk theme. --- mousepad/mousepad-util.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/mousepad/mousepad-util.c b/mousepad/mousepad-util.c index afdc640..72415e0 100644 --- a/mousepad/mousepad-util.c +++ b/mousepad/mousepad-util.c @@ -378,12 +378,31 @@ mousepad_util_image_button (const gchar *icon_name, +static void +mousepad_util_entry_error_modify_colors (GtkWidget *widget, + gboolean error) +{ +#if GTK_CHECK_VERSION(3, 0, 0) + /* See http://gtk.10911.n7.nabble.com/set-custom-entry-background-td88472.html#a88489 */ + if (error) + gtk_style_context_add_class (gtk_widget_get_style_context (widget), GTK_STYLE_CLASS_ERROR); + else + gtk_style_context_remove_class (gtk_widget_get_style_context (widget), GTK_STYLE_CLASS_ERROR); +#else + const GdkColor red = {0, 0xffff, 0x6666, 0x6666}; + const GdkColor white = {0, 0xffff, 0xffff, 0xffff}; + + gtk_widget_modify_base (widget, GTK_STATE_NORMAL, error ? &red : NULL); + gtk_widget_modify_text (widget, GTK_STATE_NORMAL, error ? &white : NULL); +#endif +} + + + void mousepad_util_entry_error (GtkWidget *widget, gboolean error) { - const GdkColor red = {0, 0xffff, 0x6666, 0x6666}; - const GdkColor white = {0, 0xffff, 0xffff, 0xffff}; gpointer pointer; g_return_if_fail (GTK_IS_WIDGET (widget)); @@ -395,8 +414,7 @@ mousepad_util_entry_error (GtkWidget *widget, if (GPOINTER_TO_INT (pointer) != error) { /* set the widget style */ - gtk_widget_modify_base (widget, GTK_STATE_NORMAL, error ? &red : NULL); - gtk_widget_modify_text (widget, GTK_STATE_NORMAL, error ? &white : NULL); + mousepad_util_entry_error_modify_colors (widget, error); /* set the new state */ mousepad_object_set_data (G_OBJECT (widget), "error-state", GINT_TO_POINTER (error)); -- 2.21.0