Skip to content

Commit ba7d1b5

Browse files
author
Alain M
committed
fix #42
1 parent 0e61b23 commit ba7d1b5

File tree

5 files changed

+102
-189
lines changed

5 files changed

+102
-189
lines changed

data/com.github.alainm23.byte.gschema.xml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@
3232
<enum id="com.github.alainm23.byte.theme">
3333
<value nick="Byte" value="1" />
3434
<value nick="Black" value="2" />
35-
<value nick="Blueberry" value="3" />
36-
<value nick="Turquoise" value="4" />
35+
<value nick="Turquoise" value="3" />
3736
</enum>
3837

3938
<schema path="/com/github/alainm23/byte/" id="com.github.alainm23.byte" gettext-domain="com.github.alainm23.byte">
@@ -108,13 +107,7 @@
108107
<summary>Most recent window position (x, y)</summary>
109108
<description>Most recent window position (x, y)</description>
110109
</key>
111-
112-
<key name="dark-mode" type="b">
113-
<default>false</default>
114-
<summary>If the dark Gtk stylesheet should be used</summary>
115-
<description>If the dark Gtk stylesheet should be used</description>
116-
</key>
117-
110+
118111
<key name="sync-files" type="b">
119112
<default>true</default>
120113
<summary>Look for new music files on start up.</summary>

src/Application.vala

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -108,57 +108,18 @@ public class Byte : Gtk.Application {
108108
add_action (quit_action);
109109
add_action (toggle_playing_action);
110110
add_action (search_action);
111+
112+
// Default Icon Theme
113+
weak Gtk.IconTheme default_theme = Gtk.IconTheme.get_default ();
114+
default_theme.add_resource_path ("/com/github/alainm23/byte");
115+
111116

112117
// Stylesheet
113118
var provider = new Gtk.CssProvider ();
114119
provider.load_from_resource ("/com/github/alainm23/byte/stylesheet.css");
115120
Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
116-
117-
Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = settings.get_boolean ("dark-mode");
118-
119-
if (settings.get_boolean ("dark-mode")) {
120-
var dark_mode_provider = new Gtk.CssProvider ();
121-
var colored_css = """
122-
@define-color colorPrimary %s;
123-
@define-color textColorPrimary %s;
124-
""".printf ("@base_color", "#fe2851");
125-
126-
try {
127-
dark_mode_provider.load_from_data (colored_css, colored_css.length);
128-
129-
Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), dark_mode_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
130-
} catch (GLib.Error e) {
131-
return;
132-
}
133-
}
134-
135-
// Default Icon Theme
136-
weak Gtk.IconTheme default_theme = Gtk.IconTheme.get_default ();
137-
default_theme.add_resource_path ("/com/github/alainm23/byte");
138-
139-
if (Byte.settings.get_boolean ("dark-mode")) {
140-
var provider_theme = new Gtk.CssProvider ();
141-
142-
var colored_css = """
143-
@define-color colorPrimary %s;
144-
@define-color textColorPrimary %s;
145-
""";
146-
147-
colored_css = colored_css.printf (
148-
"@base_color",
149-
"@text_color"
150-
);
151-
152-
try {
153-
provider_theme.load_from_data (colored_css, colored_css.length);
154-
155-
Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), provider_theme, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
156-
} catch (GLib.Error e) {
157-
return;
158-
}
159-
} else {
160-
Byte.utils.apply_theme (Byte.settings.get_enum ("theme"));
161-
}
121+
122+
utils.apply_theme (Byte.settings.get_enum ("theme"));
162123
}
163124

164125
public void toggle_playing_action_enabled (bool b) {

src/Dialogs/Settings.vala

Lines changed: 62 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,16 @@ public class Dialogs.Settings : Gtk.Dialog {
3333
general_label.margin_start = 6;
3434

3535
/*
36-
Dark Mode
37-
*/
38-
36+
Dark Mode
37+
3938
var settings_01_icon = new Gtk.Image ();
4039
settings_01_icon.gicon = new ThemedIcon ("weather-clear-night-symbolic");
4140
settings_01_icon.pixel_size = 16;
4241
settings_01_icon.get_style_context ().add_class ("settings-icon");
4342
settings_01_icon.valign = Gtk.Align.CENTER;
4443
4544
var settings_01_label = new Gtk.Label (_("Dark mode"));
46-
//settings_01_label.get_style_context ().add_class ("h3");
45+
settings_01_label.get_style_context ().add_class ("h3");
4746
4847
var settings_01_switch = new Gtk.Switch ();
4948
settings_01_switch.get_style_context ().add_class ("active-switch");
@@ -52,14 +51,70 @@ public class Dialogs.Settings : Gtk.Dialog {
5251
var gtk_settings = Gtk.Settings.get_default ();
5352
settings_01_switch.bind_property ("active", gtk_settings, "gtk_application_prefer_dark_theme");
5453
Byte.settings.bind ("dark-mode", settings_01_switch, "active", GLib.SettingsBindFlags.DEFAULT);
55-
54+
5655
var settings_01_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
5756
settings_01_box.hexpand = true;
5857
settings_01_box.margin = 6;
5958
settings_01_box.pack_start (settings_01_icon, false, false, 0);
6059
settings_01_box.pack_start (settings_01_label, false, false, 6);
6160
settings_01_box.pack_end (settings_01_switch, false, false, 0);
6261
62+
/*
63+
Theme
64+
*/
65+
66+
var settings_01_icon = new Gtk.Image ();
67+
settings_01_icon.gicon = new ThemedIcon ("applications-graphics-symbolic");
68+
settings_01_icon.pixel_size = 16;
69+
settings_01_icon.get_style_context ().add_class ("settings-icon");
70+
settings_01_icon.valign = Gtk.Align.CENTER;
71+
72+
var settings_01_label = new Gtk.Label (_("Theme"));
73+
74+
var theme_01 = new Gtk.RadioButton (null);
75+
theme_01.valign = Gtk.Align.START;
76+
theme_01.halign = Gtk.Align.START;
77+
theme_01.tooltip_text = _("Byte");
78+
apply_styles ("01", "#fe2851", theme_01);
79+
80+
var theme_02 = new Gtk.RadioButton.from_widget (theme_01);
81+
theme_02.valign = Gtk.Align.START;
82+
theme_02.halign = Gtk.Align.START;
83+
theme_02.tooltip_text = _("Black");
84+
apply_styles ("02", "#333333", theme_02);
85+
86+
var theme_03 = new Gtk.RadioButton.from_widget (theme_01);
87+
theme_03.valign = Gtk.Align.START;
88+
theme_03.halign = Gtk.Align.START;
89+
theme_03.tooltip_text = _("Turquoise");
90+
apply_styles ("04", "#36E683", theme_03);
91+
92+
var theme_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
93+
theme_box.pack_start (theme_01, false, false, 6);
94+
theme_box.pack_start (theme_02, false, false, 6);
95+
theme_box.pack_start (theme_03, false, false, 6);
96+
97+
// I think switch most better here (redian23)
98+
switch (Byte.settings.get_enum ("theme")) {
99+
case 1 :
100+
theme_01.active = true;
101+
break;
102+
case 2 :
103+
theme_02.active = true;
104+
break;
105+
case 3 :
106+
theme_03.active = true;
107+
break;
108+
}
109+
110+
var settings_01_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
111+
settings_01_box.hexpand = true;
112+
settings_01_box.margin = 6;
113+
settings_01_box.margin_end = 0;
114+
settings_01_box.pack_start (settings_01_icon, false, false, 0);
115+
settings_01_box.pack_start (settings_01_label, false, false, 6);
116+
settings_01_box.pack_end (theme_box, false, false, 0);
117+
63118
/*
64119
Notifications
65120
*/
@@ -108,72 +163,6 @@ public class Dialogs.Settings : Gtk.Dialog {
108163
settings_03_box.pack_start (settings_03_label, false, false, 6);
109164
settings_03_box.pack_end (settings_03_switch, false, false, 0);
110165

111-
/*
112-
Theme
113-
*/
114-
115-
var settings_09_icon = new Gtk.Image ();
116-
settings_09_icon.gicon = new ThemedIcon ("applications-graphics-symbolic");
117-
settings_09_icon.pixel_size = 16;
118-
settings_09_icon.get_style_context ().add_class ("settings-icon");
119-
settings_09_icon.valign = Gtk.Align.CENTER;
120-
121-
var settings_09_label = new Gtk.Label (_("Theme"));
122-
123-
var theme_01 = new Gtk.RadioButton (null);
124-
theme_01.valign = Gtk.Align.START;
125-
theme_01.halign = Gtk.Align.START;
126-
theme_01.tooltip_text = _("Byte");
127-
apply_styles ("01", "#fe2851", theme_01);
128-
129-
var theme_02 = new Gtk.RadioButton.from_widget (theme_01);
130-
theme_02.valign = Gtk.Align.START;
131-
theme_02.halign = Gtk.Align.START;
132-
theme_02.tooltip_text = _("Black");
133-
apply_styles ("02", "#333333", theme_02);
134-
135-
var theme_03 = new Gtk.RadioButton.from_widget (theme_01);
136-
theme_03.valign = Gtk.Align.START;
137-
theme_03.halign = Gtk.Align.START;
138-
theme_03.tooltip_text = _("Blueberry");
139-
apply_styles ("03", "#3689e6", theme_03);
140-
141-
var theme_04 = new Gtk.RadioButton.from_widget (theme_01);
142-
theme_04.valign = Gtk.Align.START;
143-
theme_04.halign = Gtk.Align.START;
144-
theme_04.tooltip_text = _("Turquoise");
145-
apply_styles ("04", "#36E683", theme_04);
146-
147-
var theme_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
148-
theme_box.pack_start (theme_01, false, false, 6);
149-
theme_box.pack_start (theme_02, false, false, 6);
150-
theme_box.pack_start (theme_03, false, false, 6);
151-
theme_box.pack_start (theme_04, false, false, 6);
152-
153-
// I think switch most better here (redian23)
154-
switch (Byte.settings.get_enum ("theme")) {
155-
case 1 :
156-
theme_01.active = true;
157-
break;
158-
case 2 :
159-
theme_02.active = true;
160-
break;
161-
case 3 :
162-
theme_03.active = true;
163-
break;
164-
case 4 :
165-
theme_04.active = true;
166-
break;
167-
}
168-
169-
var settings_09_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0);
170-
settings_09_box.hexpand = true;
171-
settings_09_box.margin = 6;
172-
settings_09_box.margin_end = 0;
173-
settings_09_box.pack_start (settings_09_icon, false, false, 0);
174-
settings_09_box.pack_start (settings_09_label, false, false, 6);
175-
settings_09_box.pack_end (theme_box, false, false, 0);
176-
177166
var general_grid = new Gtk.Grid ();
178167
general_grid.get_style_context ().add_class ("view");
179168
general_grid.orientation = Gtk.Orientation.VERTICAL;
@@ -185,8 +174,8 @@ public class Dialogs.Settings : Gtk.Dialog {
185174
general_grid.add (new Gtk.Separator (Gtk.Orientation.HORIZONTAL));
186175
general_grid.add (settings_03_box);
187176
general_grid.add (new Gtk.Separator (Gtk.Orientation.HORIZONTAL));
188-
general_grid.add (settings_09_box);
189-
general_grid.add (new Gtk.Separator (Gtk.Orientation.HORIZONTAL));
177+
//general_grid.add (settings_09_box);
178+
//general_grid.add (new Gtk.Separator (Gtk.Orientation.HORIZONTAL));
190179

191180
var library_label = new Gtk.Label (_("Library"));
192181
library_label.halign = Gtk.Align.START;
@@ -351,40 +340,6 @@ public class Dialogs.Settings : Gtk.Dialog {
351340
get_action_area ().visible = false;
352341
get_action_area ().no_show_all = true;
353342

354-
//add_button (_("Close"), Gtk.ResponseType.CLOSE);
355-
/*
356-
response.connect ((response_id) => {
357-
destroy ();
358-
});
359-
*/
360-
361-
settings_01_switch.notify["active"].connect (() => {
362-
theme_box.sensitive = !settings_01_switch.active;
363-
364-
var provider = new Gtk.CssProvider ();
365-
var colored_css = """
366-
@define-color colorPrimary %s;
367-
@define-color textColorPrimary %s;
368-
""";
369-
370-
if (settings_01_switch.active) {
371-
colored_css = colored_css.printf (
372-
"@base_color",
373-
"@text_color"
374-
);
375-
} else {
376-
Byte.utils.apply_theme (Byte.settings.get_enum ("theme"));
377-
}
378-
379-
try {
380-
provider.load_from_data (colored_css, colored_css.length);
381-
382-
Gtk.StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
383-
} catch (GLib.Error e) {
384-
return;
385-
}
386-
});
387-
388343
settings_02_switch.notify["active"].connect (() => {
389344
Byte.settings.set_boolean ("notifications-enabled", settings_02_switch.active);
390345
});
@@ -463,11 +418,6 @@ public class Dialogs.Settings : Gtk.Dialog {
463418
Byte.settings.set_enum ("theme", 3);
464419
Byte.utils.apply_theme (3);
465420
});
466-
467-
theme_04.toggled.connect (() => {
468-
Byte.settings.set_enum ("theme", 4);
469-
Byte.utils.apply_theme (4);
470-
});
471421
}
472422

473423
private void apply_styles (string id, string color, Gtk.RadioButton radio) {

src/Utils.vala

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ public class Utils : GLib.Object {
1111

1212
public string MAIN_FOLDER;
1313
public string COVER_FOLDER;
14+
15+
bool dark_mode;
16+
string colorPrimary;
17+
string colorAccent;
18+
string textColorPrimary;
19+
1420
public Utils () {
1521
MAIN_FOLDER = Environment.get_home_dir () + "/.local/share/com.github.alainm23.byte";
1622
COVER_FOLDER = GLib.Path.build_filename (MAIN_FOLDER, "covers");
@@ -340,6 +346,25 @@ public class Utils : GLib.Object {
340346
}
341347

342348
public void apply_theme (int id) {
349+
if (id == 1) {
350+
dark_mode = false;
351+
colorPrimary = "#fe2851";
352+
colorAccent = "#fe2851";
353+
textColorPrimary = "#fff";
354+
} else if (id == 2) {
355+
dark_mode = true;
356+
colorPrimary = "#fe2851";
357+
colorAccent = "#fe2851";
358+
textColorPrimary = "#fff";
359+
} else if (id == 3) {
360+
dark_mode = true;
361+
colorPrimary = "#36E683";
362+
colorAccent = "#36E683";
363+
textColorPrimary = "#333";
364+
}
365+
366+
Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = dark_mode;
367+
343368
string THEME_CSS = """
344369
@define-color colorPrimary %s;
345370
@define-color colorAccent %s;
@@ -349,26 +374,10 @@ public class Utils : GLib.Object {
349374
var provider = new Gtk.CssProvider ();
350375

351376
try {
352-
string colorPrimary = "";
353-
string colorAccent = "";
354-
if (id == 1) {
355-
colorPrimary = "#fe2851";
356-
colorAccent = "#fe2851";
357-
} else if (id == 2) {
358-
colorPrimary = "#4d4d4d";
359-
colorAccent = "@text_color";
360-
} else if (id == 3) {
361-
colorPrimary = "#3689e6";
362-
colorAccent = "#3689e6";
363-
}else {
364-
colorPrimary = "#36E683";
365-
colorAccent = "#36E683";
366-
}
367-
368377
var theme_css = THEME_CSS.printf (
369378
colorPrimary,
370379
colorAccent,
371-
"@base_color"
380+
textColorPrimary
372381
);
373382

374383
provider.load_from_data (theme_css, theme_css.length);

0 commit comments

Comments
 (0)