Skip to content
Permalink
Browse files

caja-location-bar: Fix: change background color based on activity state

and avoid deprecated 'gtk_widget_override_background_color'
  • Loading branch information...
sc0w committed Jun 25, 2018
1 parent 6b2d8e5 commit 2d179e43f3cfd3c187b375aa57e2b05a4037124a
Showing with 48 additions and 15 deletions.
  1. +48 −15 src/caja-location-bar.c
@@ -592,30 +592,63 @@ caja_location_bar_set_location (CajaLocationBar *bar,
caja_location_bar_update_label (bar);
}

static void
override_background_color (GtkWidget *widget,
GdkRGBA *rgba)
{
gchar *css;
GtkCssProvider *provider;

provider = gtk_css_provider_new ();

css = g_strdup_printf ("entry { background-color: %s;}",
gdk_rgba_to_string (rgba));
gtk_css_provider_load_from_data (provider, css, -1, NULL);
g_free (css);

gtk_style_context_add_provider (gtk_widget_get_style_context (widget),
GTK_STYLE_PROVIDER (provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
g_object_unref (provider);
}

/* change background color based on activity state */
void
caja_location_bar_set_active(CajaLocationBar *location_bar, gboolean is_active)
caja_location_bar_set_active (CajaLocationBar *location_bar, gboolean is_active)
{
if (is_active)
{
/* reset style to default */
gtk_widget_override_background_color (GTK_WIDGET (location_bar->details->entry), GTK_STATE_FLAG_NORMAL, NULL);
}
else
{
GtkStyleContext *style;
GdkRGBA color;
GdkRGBA *c;
GtkStyleContext *style;
GdkRGBA color;
GdkRGBA *c;
static GdkRGBA bg_active;
static GdkRGBA bg_inactive;

style = gtk_widget_get_style_context (GTK_WIDGET (location_bar->details->entry));
style = gtk_widget_get_style_context (GTK_WIDGET (location_bar->details->entry));

if (is_active)
gtk_style_context_get (style, GTK_STATE_FLAG_NORMAL,
GTK_STYLE_PROPERTY_BACKGROUND_COLOR,
&c, NULL);
else
gtk_style_context_get (style, GTK_STATE_FLAG_INSENSITIVE,
GTK_STYLE_PROPERTY_BACKGROUND_COLOR,
&c, NULL);
color = *c;
gdk_rgba_free (c);

gtk_widget_override_background_color (GTK_WIDGET (location_bar->details->entry), GTK_STATE_FLAG_ACTIVE, &color);
color = *c;
gdk_rgba_free (c);

if (is_active)
{
if (gdk_rgba_equal (&bg_active, &bg_inactive))
bg_active = color;

override_background_color (GTK_WIDGET (location_bar->details->entry), &bg_active);
}
else
{
if (gdk_rgba_equal (&bg_active, &bg_inactive))
bg_inactive = color;

override_background_color(GTK_WIDGET (location_bar->details->entry), &bg_inactive);
}
}

0 comments on commit 2d179e4

Please sign in to comment.
You can’t perform that action at this time.