From 3606fd0844d7da743ce4ad386a3dc99fbd7f3a4f Mon Sep 17 00:00:00 2001 From: Matt Harris Date: Mon, 22 Oct 2018 22:39:21 +0100 Subject: [PATCH 1/3] initial dark mode toggle --- data/Application.css | 4 ++++ data/com.github.mdh34.hackup.gschema.xml | 5 +++++ src/MainWindow.vala | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/data/Application.css b/data/Application.css index 04aac58..04ea7a2 100644 --- a/data/Application.css +++ b/data/Application.css @@ -15,6 +15,10 @@ row:selected { background-color: #e6e6e6; } +.dark row:selected { + background-color: #5e5e5e +} + /* Label styling */ .accent { color: @colorAccent; diff --git a/data/com.github.mdh34.hackup.gschema.xml b/data/com.github.mdh34.hackup.gschema.xml index 2717d83..49fe96b 100644 --- a/data/com.github.mdh34.hackup.gschema.xml +++ b/data/com.github.mdh34.hackup.gschema.xml @@ -38,5 +38,10 @@ cookies storage Stores whether to keep cookies + + false + dark mode state + stores the last known dark mode state + \ No newline at end of file diff --git a/src/MainWindow.vala b/src/MainWindow.vala index a8eaec6..06213ed 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -64,6 +64,13 @@ public class MainWindow : Gtk.Window { back_button.no_show_all = true; header.pack_start (back_button); + var gtk_settings = Gtk.Settings.get_default (); + var theme_switch = new Granite.ModeSwitch.from_icon_name ("display-brightness-symbolic", "weather-clear-night-symbolic"); + theme_switch.row_homogeneous = true; + theme_switch.active = HackUp.settings.get_boolean ("dark"); + theme_switch.bind_property ("active", gtk_settings, "gtk_application_prefer_dark_theme"); + header.pack_end (theme_switch); + var window_width = HackUp.settings.get_int ("width"); var window_height = HackUp.settings.get_int ("height"); set_default_size (window_width, window_height); From 530077ff2762b7fafd9118373ff302f06c731259 Mon Sep 17 00:00:00 2001 From: Matt Harris Date: Mon, 22 Oct 2018 22:50:44 +0100 Subject: [PATCH 2/3] update css on theme change --- data/Application.css | 2 +- src/MainWindow.vala | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/data/Application.css b/data/Application.css index 04ea7a2..d146964 100644 --- a/data/Application.css +++ b/data/Application.css @@ -16,7 +16,7 @@ row:selected { } .dark row:selected { - background-color: #5e5e5e + background-color: #666666 } /* Label styling */ diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 06213ed..ac188cb 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -64,11 +64,20 @@ public class MainWindow : Gtk.Window { back_button.no_show_all = true; header.pack_start (back_button); + PostList list; var gtk_settings = Gtk.Settings.get_default (); var theme_switch = new Granite.ModeSwitch.from_icon_name ("display-brightness-symbolic", "weather-clear-night-symbolic"); theme_switch.row_homogeneous = true; theme_switch.active = HackUp.settings.get_boolean ("dark"); theme_switch.bind_property ("active", gtk_settings, "gtk_application_prefer_dark_theme"); + theme_switch.notify["active"].connect(() => { + if (theme_switch.active) { + list.get_style_context ().add_class("dark"); + } + else { + list.get_style_context ().remove_class("dark"); + } + }); header.pack_end (theme_switch); var window_width = HackUp.settings.get_int ("width"); @@ -81,7 +90,7 @@ public class MainWindow : Gtk.Window { move (window_x, window_y); } - var list = new PostList (); + list = new PostList (); var scroller = new Gtk.ScrolledWindow (null, null); scroller.hscrollbar_policy = Gtk.PolicyType.NEVER; scroller.add (list); From 557626ae9501d68aee7a64a8df1f45f834241d81 Mon Sep 17 00:00:00 2001 From: Matt Harris Date: Mon, 22 Oct 2018 22:58:50 +0100 Subject: [PATCH 3/3] save and restore theme state --- src/MainWindow.vala | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index ac188cb..db2b8df 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -70,12 +70,11 @@ public class MainWindow : Gtk.Window { theme_switch.row_homogeneous = true; theme_switch.active = HackUp.settings.get_boolean ("dark"); theme_switch.bind_property ("active", gtk_settings, "gtk_application_prefer_dark_theme"); - theme_switch.notify["active"].connect(() => { + theme_switch.notify["active"].connect (() => { if (theme_switch.active) { - list.get_style_context ().add_class("dark"); - } - else { - list.get_style_context ().remove_class("dark"); + list.get_style_context ().add_class ("dark"); + } else { + list.get_style_context ().remove_class ("dark"); } }); header.pack_end (theme_switch); @@ -95,6 +94,12 @@ public class MainWindow : Gtk.Window { scroller.hscrollbar_policy = Gtk.PolicyType.NEVER; scroller.add (list); + var dark = HackUp.settings.get_boolean ("dark"); + if (dark) { + gtk_settings.set ("gtk-application-prefer-dark-theme", true); + list.get_style_context ().add_class ("dark"); + } + settings_popover.closed.connect (() => { var list_sorting = HackUp.settings.get_string ("listtype"); if (settings_popover.current_sort != list_sorting) { @@ -123,6 +128,7 @@ public class MainWindow : Gtk.Window { int current_x, current_y, width, height; get_position (out current_x, out current_y); get_size (out width, out height); + HackUp.settings.set_boolean ("dark", theme_switch.active); HackUp.settings.set_int ("x", current_x); HackUp.settings.set_int ("y", current_y); HackUp.settings.set_int ("width", width);