@@ -592,30 +592,63 @@ caja_location_bar_set_location (CajaLocationBar *bar,
592592 caja_location_bar_update_label (bar );
593593}
594594
595+ static void
596+ override_background_color (GtkWidget * widget ,
597+ GdkRGBA * rgba )
598+ {
599+ gchar * css ;
600+ GtkCssProvider * provider ;
601+
602+ provider = gtk_css_provider_new ();
603+
604+ css = g_strdup_printf ("entry { background-color: %s;}" ,
605+ gdk_rgba_to_string (rgba ));
606+ gtk_css_provider_load_from_data (provider , css , -1 , NULL );
607+ g_free (css );
608+
609+ gtk_style_context_add_provider (gtk_widget_get_style_context (widget ),
610+ GTK_STYLE_PROVIDER (provider ),
611+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION );
612+ g_object_unref (provider );
613+ }
614+
595615/* change background color based on activity state */
596616void
597- caja_location_bar_set_active (CajaLocationBar * location_bar , gboolean is_active )
617+ caja_location_bar_set_active (CajaLocationBar * location_bar , gboolean is_active )
598618{
599- if (is_active )
600- {
601- /* reset style to default */
602- gtk_widget_override_background_color (GTK_WIDGET (location_bar -> details -> entry ), GTK_STATE_FLAG_NORMAL , NULL );
603- }
604- else
605- {
606- GtkStyleContext * style ;
607- GdkRGBA color ;
608- GdkRGBA * c ;
619+ GtkStyleContext * style ;
620+ GdkRGBA color ;
621+ GdkRGBA * c ;
622+ static GdkRGBA bg_active ;
623+ static GdkRGBA bg_inactive ;
609624
610- style = gtk_widget_get_style_context (GTK_WIDGET (location_bar -> details -> entry ));
625+ style = gtk_widget_get_style_context (GTK_WIDGET (location_bar -> details -> entry ));
611626
627+ if (is_active )
628+ gtk_style_context_get (style , GTK_STATE_FLAG_NORMAL ,
629+ GTK_STYLE_PROPERTY_BACKGROUND_COLOR ,
630+ & c , NULL );
631+ else
612632 gtk_style_context_get (style , GTK_STATE_FLAG_INSENSITIVE ,
613633 GTK_STYLE_PROPERTY_BACKGROUND_COLOR ,
614634 & c , NULL );
615- color = * c ;
616- gdk_rgba_free (c );
617635
618- gtk_widget_override_background_color (GTK_WIDGET (location_bar -> details -> entry ), GTK_STATE_FLAG_ACTIVE , & color );
636+ color = * c ;
637+ gdk_rgba_free (c );
638+
639+ if (is_active )
640+ {
641+ if (gdk_rgba_equal (& bg_active , & bg_inactive ))
642+ bg_active = color ;
643+
644+ override_background_color (GTK_WIDGET (location_bar -> details -> entry ), & bg_active );
645+ }
646+ else
647+ {
648+ if (gdk_rgba_equal (& bg_active , & bg_inactive ))
649+ bg_inactive = color ;
650+
651+ override_background_color (GTK_WIDGET (location_bar -> details -> entry ), & bg_inactive );
619652 }
620653}
621654
0 commit comments