Skip to content

Commit 36b0400

Browse files
committed
Rewrite CSS loading
1 parent b754498 commit 36b0400

File tree

5 files changed

+236
-191
lines changed

5 files changed

+236
-191
lines changed

data/Application.css

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,135 @@
1+
@define-color textColorPrimary #323232;
12

3+
window {
4+
transition: background-color 800ms cubic-bezier(0.4, 0, 0.2, 1);
5+
}
6+
7+
undershoot.top {
8+
transition: background 800ms cubic-bezier(0.4, 0, 0.2, 1);
9+
}
10+
11+
undershoot.bottom {
12+
transition: background 800ms cubic-bezier(0.4, 0, 0.2, 1);
13+
}
14+
15+
.jorts-view text selection {
16+
transition: color 800ms cubic-bezier(0.4, 0, 0.2, 1);
17+
transition: background-color 800ms cubic-bezier(0.4, 0, 0.2, 1);
18+
}
19+
20+
.jorts-title image,
21+
.jorts-label {
22+
box-shadow: none;
23+
transition: color 800ms cubic-bezier(0.4, 0, 0.2, 1);
24+
}
25+
26+
.jorts-bar {
27+
box-shadow: none;
28+
background: transparent;
29+
padding: 3px;
30+
}
31+
32+
.jorts-bar image {
33+
padding: 3px;
34+
box-shadow: none;
35+
background-image: none;
36+
}
37+
38+
.jorts-view,
39+
.jorts-view text,
40+
.jorts-title {
41+
background-image: none;
42+
font-weight: 500;
43+
font-size: 1.2em;
44+
box-shadow: none;
45+
transition: background-color 800ms cubic-bezier(0.4, 0, 0.2, 1);
46+
/*transition: color 800ms cubic-bezier(0.4, 0, 0.2, 1);*/
47+
}
48+
49+
entry.flat {
50+
background: transparent;
51+
}
52+
53+
.color-button {
54+
border-radius: 50%;
55+
background-image: none;
56+
border: 1px solid alpha(#333, 0.25);
57+
box-shadow:
58+
inset 0 1px 0 0 alpha (@inset_dark_color, 0.7),
59+
inset 0 0 0 1px alpha (@inset_dark_color, 0.3),
60+
0 1px 0 0 alpha (@bg_highlight_color, 0.3);
61+
}
62+
63+
.color-button:hover,
64+
.color-button:focus {
65+
border: 1px solid @inset_dark_color;
66+
}
67+
68+
.color-button.slate {
69+
background-color: @SLATE_100;
70+
}
71+
72+
.color-button.silver {
73+
background-color: @SILVER_100;
74+
}
75+
76+
.color-button.strawberry {
77+
background-color: @STRAWBERRY_100;
78+
}
79+
80+
.color-button.orange {
81+
background-color: @ORANGE_100;
82+
}
83+
84+
.color-button.banana {
85+
background-color: @BANANA_100;
86+
}
87+
88+
.color-button.lime {
89+
background-color: @LIME_100;
90+
}
91+
92+
.color-button.blueberry {
93+
background-color: @BLUEBERRY_100;
94+
}
95+
96+
.color-button.grape {
97+
background-color: @GRAPE_100;
98+
}
99+
100+
.color-button.cocoa {
101+
background-color: @COCOA_100;
102+
}
103+
104+
.jorts-bar box {
105+
border: none;
106+
}
107+
108+
.image-button,
109+
.titlebutton {
110+
background-color: transparent;
111+
background-image: none;
112+
border: 1px solid transparent;
113+
padding: 3px;
114+
box-shadow: none;
115+
}
116+
117+
.image-button:hover,
118+
.image-button:focus,
119+
.titlebutton:hover,
120+
.titlebutton:focus {
121+
background-color: alpha(@fg_color, 0.3);
122+
background-image: none;
123+
border: 1px solid transparent;
124+
box-shadow: none;
125+
}
126+
127+
.jorts-label {
128+
font-weight: 700;
129+
font-size: 0.88em;
130+
}
131+
132+
.trashcan:hover {
133+
transition: background-color 800ms cubic-bezier(0.4, 0, 0.2, 1);
134+
color: @warning;
135+
}

src/Application.vala

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,51 @@ namespace jorts {
2727
Object (flags: ApplicationFlags.HANDLES_COMMAND_LINE,
2828
application_id: "io.github.ellie_commons.jorts");
2929
}
30-
30+
31+
public override void startup () {
32+
base.startup ();
33+
34+
// This is automatic in GTK4, so can be removed after porting
35+
var app_provider = new Gtk.CssProvider ();
36+
app_provider.load_from_resource ("/io/github/ellie_commons/jorts/Application.css");
37+
Gtk.StyleContext.add_provider_for_screen (
38+
Gdk.Screen.get_default (),
39+
app_provider,
40+
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
41+
);
42+
43+
string[] themes = {
44+
"BANANA",
45+
"BLUEBERRY",
46+
"BUBBLEGUM",
47+
"COCOA",
48+
"GRAPE",
49+
"LIME",
50+
"ORANGE",
51+
"SILVER",
52+
"SLATE",
53+
"STRAWBERRY"
54+
};
55+
56+
foreach (unowned var theme in themes) {
57+
// Palette color
58+
var theme_provider = new Gtk.CssProvider ();
59+
var style = jorts.Themer.generate_css (theme);
60+
61+
try {
62+
theme_provider.load_from_data (style, -1);
63+
} catch (GLib.Error e) {
64+
warning ("Failed to parse css style : %s", e.message);
65+
}
66+
67+
Gtk.StyleContext.add_provider_for_screen (
68+
Gdk.Screen.get_default (),
69+
theme_provider,
70+
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
71+
);
72+
}
73+
}
74+
3175
static construct {
3276
gsettings = new GLib.Settings ("io.github.ellie_commons.jorts");
3377
}
@@ -143,4 +187,4 @@ namespace jorts {
143187
return app.run(args);
144188
}
145189
}
146-
}
190+
}

src/MainWindow.vala

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ namespace jorts {
238238
color_button_strawberry.width_request = 24;
239239
color_button_strawberry.tooltip_text = _("Strawberry");
240240
color_button_strawberry.get_style_context ().add_class ("color-button");
241-
color_button_strawberry.get_style_context ().add_class ("color-strawberry");
241+
color_button_strawberry.get_style_context ().add_class ("strawberry");
242242

243243
var color_button_orange = new Gtk.Button ();
244244
color_button_orange.has_focus = false;
@@ -249,7 +249,7 @@ namespace jorts {
249249

250250
var color_button_orange_context = color_button_orange.get_style_context ();
251251
color_button_orange_context.add_class ("color-button");
252-
color_button_orange_context.add_class ("color-orange");
252+
color_button_orange_context.add_class ("orange");
253253

254254
var color_button_banana = new Gtk.Button ();
255255
color_button_banana.has_focus = false;
@@ -260,7 +260,7 @@ namespace jorts {
260260

261261
var color_button_banana_context = color_button_banana.get_style_context ();
262262
color_button_banana_context.add_class ("color-button");
263-
color_button_banana_context.add_class ("color-banana");
263+
color_button_banana_context.add_class ("banana");
264264

265265
var color_button_lime = new Gtk.Button ();
266266
color_button_lime.has_focus = false;
@@ -271,7 +271,7 @@ namespace jorts {
271271

272272
var color_button_lime_context = color_button_lime.get_style_context ();
273273
color_button_lime_context.add_class ("color-button");
274-
color_button_lime_context.add_class ("color-lime");
274+
color_button_lime_context.add_class ("lime");
275275

276276
var color_button_blueberry = new Gtk.Button ();
277277
color_button_blueberry.has_focus = false;
@@ -282,7 +282,7 @@ namespace jorts {
282282

283283
var color_button_blueberry_context = color_button_blueberry.get_style_context ();
284284
color_button_blueberry_context.add_class ("color-button");
285-
color_button_blueberry_context.add_class ("color-blueberry");
285+
color_button_blueberry_context.add_class ("blueberry");
286286

287287

288288
var color_button_bubblegum = new Gtk.Button ();
@@ -294,7 +294,7 @@ namespace jorts {
294294

295295
var color_button_bubblegum_context = color_button_blueberry.get_style_context ();
296296
color_button_bubblegum_context.add_class ("color-button");
297-
color_button_bubblegum_context.add_class ("color-bubblegum");
297+
color_button_bubblegum_context.add_class ("bubblegum");
298298

299299

300300
var color_button_grape = new Gtk.Button ();
@@ -306,7 +306,7 @@ namespace jorts {
306306

307307
var color_button_grape_context = color_button_grape.get_style_context ();
308308
color_button_grape_context.add_class ("color-button");
309-
color_button_grape_context.add_class ("color-grape");
309+
color_button_grape_context.add_class ("grape");
310310

311311
var color_button_cocoa = new Gtk.Button ();
312312
color_button_cocoa.has_focus = false;
@@ -317,7 +317,7 @@ namespace jorts {
317317

318318
var color_button_cocoa_context = color_button_cocoa.get_style_context ();
319319
color_button_cocoa_context.add_class ("color-button");
320-
color_button_cocoa_context.add_class ("color-cocoa");
320+
color_button_cocoa_context.add_class ("cocoa");
321321

322322
var color_button_silver = new Gtk.Button ();
323323
color_button_silver.has_focus = false;
@@ -328,7 +328,7 @@ namespace jorts {
328328

329329
var color_button_silver_context = color_button_silver.get_style_context ();
330330
color_button_silver_context.add_class ("color-button");
331-
color_button_silver_context.add_class ("color-silver");
331+
color_button_silver_context.add_class ("silver");
332332

333333

334334
var color_button_slate = new Gtk.Button ();
@@ -340,7 +340,7 @@ namespace jorts {
340340

341341
var color_button_slate_context = color_button_slate.get_style_context ();
342342
color_button_slate_context.add_class ("color-button");
343-
color_button_slate_context.add_class ("color-slate");
343+
color_button_slate_context.add_class ("slate");
344344

345345
var color_button_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
346346
// GTK4: append
@@ -526,27 +526,26 @@ namespace jorts {
526526
// And then this reconstructs a whole ass theme out of these two
527527
// Either it can be a service, or just all defined in CSS and add/remove css
528528
private void update_theme(string theme) {
529-
print(uid.to_string ());
530529

531-
this.get_style_context().add_class("mainwindow-%d".printf(uid));
532-
this.get_style_context().add_class("window-%d".printf(uid));
533-
534-
// Palette color
535-
var css_provider = new Gtk.CssProvider();
536-
var style = jorts.Themer.generate_css(uid,theme);
537-
538-
try {
539-
css_provider.load_from_data(style, -1);
540-
541-
} catch (GLib.Error e) {
542-
warning ("Failed to parse css style : %s", e.message);
543-
}
530+
// in GTK4 we can replace this with setting css_classes
531+
string[] themes = {
532+
"BANANA",
533+
"BLUEBERRY",
534+
"BUBBLEGUM",
535+
"COCOA",
536+
"GRAPE",
537+
"LIME",
538+
"ORANGE",
539+
"SILVER",
540+
"SLATE",
541+
"STRAWBERRY"
542+
};
543+
544+
foreach (unowned var old_theme in themes) {
545+
get_style_context().remove_class (old_theme);
546+
}
544547

545-
Gtk.StyleContext.add_provider_for_screen (
546-
Gdk.Screen.get_default (),
547-
css_provider,
548-
Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
549-
);
548+
get_style_context().add_class (theme);
550549
}
551550
}
552551

0 commit comments

Comments
 (0)