Skip to content

Commit 82cb64c

Browse files
authored
Sync with system color scheme instead of ModeSwitch (#403)
1 parent 8fbdaf5 commit 82cb64c

File tree

5 files changed

+20
-28
lines changed

5 files changed

+20
-28
lines changed

schemas/com.github.alecaddd.sequeler.gschema.xml.in

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@
5454
<description>Automatically Save a Quick Connections into the Database Library.</description>
5555
</key>
5656

57-
<key name="dark-theme" type="b">
58-
<default>false</default>
59-
<summary>Use dark theme</summary>
60-
<description>Switch between Light and Dark theme.</description>
61-
</key>
62-
6357
<key name="version" type="s">
6458
<default>""</default>
6559
<summary>Current Version</summary>

src/Application.vala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,26 @@ public class Sequeler.Application : Gtk.Application {
9999
return window;
100100
}
101101

102+
private static bool granite_color_scheme_to_gtk_dark_theme (Binding binding, Value granite_prop, ref Value gtk_prop) {
103+
gtk_prop.set_boolean ((Granite.Settings.ColorScheme) granite_prop == Granite.Settings.ColorScheme.DARK);
104+
return true;
105+
}
106+
107+
protected override void startup () {
108+
base.startup ();
109+
110+
// Follow OS-wide dark preference
111+
unowned var granite_settings = Granite.Settings.get_default ();
112+
unowned var gtk_settings = Gtk.Settings.get_default ();
113+
114+
granite_settings.bind_property ("prefers-color-scheme", gtk_settings, "gtk-application-prefer-dark-theme",
115+
BindingFlags.DEFAULT | BindingFlags.SYNC_CREATE,
116+
// FIXME: Using the lambda expression here causes Window not being freed when it's destroyed.
117+
// Maybe due to this issue in vala: https://gitlab.gnome.org/GNOME/vala/-/issues/957
118+
(BindingTransformFunc) granite_color_scheme_to_gtk_dark_theme
119+
);
120+
}
121+
102122
protected override void activate () {
103123
this.add_new_window ();
104124
}

src/Layouts/HeaderBar.vala

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public class Sequeler.Layouts.HeaderBar : Gtk.HeaderBar {
2626
private Gtk.Button new_db_button;
2727
private Gtk.Button delete_db_button;
2828
private Gtk.Button edit_db_button;
29-
private Granite.ModeSwitch mode_switch;
3029
private Gtk.Popover menu_popover;
3130

3231
public bool logged_out { get; set; }
@@ -85,19 +84,6 @@ public class Sequeler.Layouts.HeaderBar : Gtk.HeaderBar {
8584
delete_db_button.visible = false;
8685
delete_db_button.no_show_all = true;
8786

88-
mode_switch = new Granite.ModeSwitch.from_icon_name ("display-brightness-symbolic", "weather-clear-night-symbolic");
89-
mode_switch.primary_icon_tooltip_text = _("Light background");
90-
mode_switch.secondary_icon_tooltip_text = _("Dark background");
91-
mode_switch.valign = Gtk.Align.CENTER;
92-
mode_switch.bind_property ("active", settings, "dark-theme");
93-
mode_switch.notify.connect (() => {
94-
Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = settings.dark_theme;
95-
});
96-
97-
if (settings.dark_theme) {
98-
mode_switch.active = true;
99-
}
100-
10187
var new_window_item = new_menuitem (_("New Window"), "<Control>n");
10288
new_window_item.action_name = Sequeler.Services.ActionManager.ACTION_PREFIX + Sequeler.Services.ActionManager.ACTION_NEW_WINDOW;
10389

@@ -140,8 +126,6 @@ public class Sequeler.Layouts.HeaderBar : Gtk.HeaderBar {
140126
pack_start (delete_db_button);
141127

142128
pack_end (open_menu);
143-
pack_end (headerbar_separator ());
144-
pack_end (mode_switch);
145129
}
146130

147131
private Gtk.ModelButton new_menuitem (string label, string accels) {

src/Services/Settings.vala

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ public class Sequeler.Services.Settings : GLib.Settings {
5252
get { return get_int ("limit-results"); }
5353
set { set_int ("limit-results", value); }
5454
}
55-
public bool dark_theme {
56-
get { return get_boolean ("dark-theme"); }
57-
set { set_boolean ("dark-theme", value); }
58-
}
5955
public bool save_quick {
6056
get { return get_boolean ("save-quick"); }
6157
set { set_boolean ("save-quick", value); }

src/Window.vala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ public class Sequeler.Window : Gtk.ApplicationWindow {
6060
}
6161

6262
private void build_ui () {
63-
Gtk.Settings.get_default ().gtk_application_prefer_dark_theme = settings.dark_theme;
64-
6563
var css_provider = new Gtk.CssProvider ();
6664
css_provider.load_from_resource ("/com/github/alecaddd/sequeler/stylesheet.css");
6765

0 commit comments

Comments
 (0)