@@ -23,6 +23,8 @@ public class Calendar.SourceRow : Gtk.ListBoxRow {
2323 private Gtk . Label message_label;
2424 private Gtk . CheckButton visible_checkbutton;
2525
26+ private static Gee . HashMap<string, Gtk . CssProvider > ? providers;
27+
2628 public SourceRow (E .Source source ) {
2729 this . source = source;
2830
@@ -58,7 +60,7 @@ public class Calendar.SourceRow : Gtk.ListBoxRow {
5860 }
5961 });
6062
61- style_calendar_color (cal. dup_color ());
63+ set_accent_color (cal. dup_color ());
6264
6365 delete_button = new Gtk .Button .from_icon_name (" edit-delete-symbolic" , MENU ) {
6466 sensitive = source. removable,
@@ -125,16 +127,46 @@ public class Calendar.SourceRow : Gtk.ListBoxRow {
125127 source.changed.connect (source_has_changed );
126128 }
127129
128- private void style_calendar_color (string color ) {
129- var css_color = " @define-color accent_color %s ;" . printf (color. slice (0 , 7 ));
130+ static construct {
131+ providers = new Gee .HashMap<string, Gtk . CssProvider > ();
132+ }
130133
131- var style_provider = new Gtk .CssProvider ();
134+ private void set_accent_color (string ? color ) {
135+ if (color == null ) {
136+ /* We automatically use the accent color */
137+ return ;
138+ }
139+
140+ var color_class = color. replace (" #" , " color-" );
141+ // FIXME: in GTK4 use css_classes to make sure we remove old ones
142+ visible_checkbutton. get_style_context (). add_class (color_class);
132143
144+ if (providers. has_key (color)) {
145+ return ;
146+ }
147+
148+ var bg_rgba = Gdk . RGBA ();
149+ bg_rgba. parse (color);
150+
151+ string style = @"
152+ checkbutton:checked.$color_class check {
153+ background-color: $color ;
154+ -gtk-icon-shadow: 0 1px 1px shade($color , 0.7);
155+ }
156+ " ;
157+
158+ var style_provider = new Gtk .CssProvider ();
133159 try {
134- style_provider. load_from_data (css_color, css_color. length);
135- visible_checkbutton. get_style_context (). add_provider (style_provider, Gtk . STYLE_PROVIDER_PRIORITY_APPLICATION );
160+ style_provider. load_from_data (style);
161+
162+ providers[color] = style_provider;
163+ Gtk . StyleContext . add_provider_for_screen (
164+ Gdk . Screen . get_default (),
165+ providers[color],
166+ Gtk . STYLE_PROVIDER_PRIORITY_APPLICATION
167+ );
136168 } catch (Error e) {
137- warning (" Could not create CSS Provider : %s\n Stylesheet: \n%s " , e. message, css_color );
169+ critical (" couldn't set source check color : %s " , e. message);
138170 }
139171 }
140172
@@ -144,7 +176,7 @@ public class Calendar.SourceRow : Gtk.ListBoxRow {
144176
145177 E . SourceCalendar cal = (E . SourceCalendar )source. get_extension (E . SOURCE_EXTENSION_CALENDAR );
146178
147- style_calendar_color (cal. dup_color ());
179+ set_accent_color (cal. dup_color ());
148180
149181 visible_checkbutton. active = cal. selected;
150182 }
0 commit comments