[dconf-editor] Re-rework night mode init.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] Re-rework night mode init.
- Date: Wed, 19 Dec 2018 17:19:21 +0000 (UTC)
commit a8e08b9eae94b95da0b4513e67ab8c10066104c3
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Mon Dec 10 15:48:54 2018 +0100
Re-rework night mode init.
editor/adaptative-window.vala | 90 ++++++++++++++++++-------------------------
editor/browser-headerbar.ui | 2 +-
editor/browser-headerbar.vala | 2 +-
editor/browser-window.vala | 2 +-
editor/dconf-editor.vala | 6 +--
editor/dconf-headerbar.vala | 5 +++
editor/dconf-window.vala | 6 +--
7 files changed, 49 insertions(+), 64 deletions(-)
---
diff --git a/editor/adaptative-window.vala b/editor/adaptative-window.vala
index 2082ce0..b67caa5 100644
--- a/editor/adaptative-window.vala
+++ b/editor/adaptative-window.vala
@@ -68,37 +68,53 @@ private interface AdaptativeWidget : Object
internal abstract void set_window_size (WindowSize new_size);
}
-private abstract class AdaptativeHeaderBar : HeaderBar
+private abstract class NightTimeAwareHeaderBar : HeaderBar
{
+ private bool night_time = false; // no need to use NightTime here (that allows an "Unknown"
value)
+ private bool dark_theme = false;
+ private bool automatic_night_mode = false;
+
/*\
- * * manage night mode
+ * * construct
\*/
- private bool night_time = false; // no need to use NightTime here (that allows an "Unknown" value)
- internal void set_night_time (bool _night_time)
+ [CCode (notify = false)] public NightLightMonitor night_light_monitor
{
- night_time = _night_time;
- update_hamburger_menu ();
+ protected construct
+ {
+ night_time = NightLightMonitor.NightTime.should_use_dark_theme (value.night_time);
+ dark_theme = value.dark_theme;
+ automatic_night_mode = value.automatic_night_mode;
+ // menu is already updated three times at startup, let's not add one
+
+ ulong night_time_handler = value.notify ["night-time"].connect (night_time_changed);
+ ulong dark_theme_handler = value.notify ["dark-theme"].connect (dark_theme_changed);
+ ulong auto_night_handler = value.notify ["automatic-night-mode"].connect
(automatic_night_mode_changed);
+
+ destroy.connect (() => {
+ value.disconnect (night_time_handler);
+ value.disconnect (dark_theme_handler);
+ value.disconnect (auto_night_handler);
+ });
+ }
}
- private bool dark_theme = false;
- internal void set_dark_theme (bool _dark_theme)
+
+ private void night_time_changed (Object nlm, ParamSpec thing)
{
- dark_theme = _dark_theme;
+ night_time = NightLightMonitor.NightTime.should_use_dark_theme (((NightLightMonitor)
nlm).night_time);
update_hamburger_menu ();
}
- private bool automatic_night_mode = false;
- internal void set_automatic_night_mode (bool _automatic_night_mode)
+
+ private void dark_theme_changed (Object nlm, ParamSpec thing)
{
- automatic_night_mode = _automatic_night_mode;
- // menu update not needed
+ dark_theme = ((NightLightMonitor) nlm).dark_theme;
+ update_hamburger_menu ();
}
- internal void init_night_mode (bool _night_time, bool _dark_theme, bool _automatic_night_mode)
+ private void automatic_night_mode_changed (Object nlm, ParamSpec thing)
{
- night_time = _night_time;
- dark_theme = _dark_theme;
- automatic_night_mode = _automatic_night_mode;
- // menu is already updated three times at startup, let's not add one
+ automatic_night_mode = ((NightLightMonitor) nlm).automatic_night_mode;
+ // menu update not needed
}
/*\
@@ -132,7 +148,7 @@ private abstract class AdaptativeHeaderBar : HeaderBar
private abstract class AdaptativeWindow : ApplicationWindow
{
- [CCode (notify = false)] public AdaptativeHeaderBar adaptative_headerbar { protected get; protected
construct; }
+ [CCode (notify = false)] public NightTimeAwareHeaderBar nta_headerbar { protected get; protected
construct; }
private StyleContext context;
@@ -141,10 +157,8 @@ private abstract class AdaptativeWindow : ApplicationWindow
context = get_style_context ();
context.add_class ("startup");
- adaptative_headerbar.show ();
- set_titlebar (adaptative_headerbar);
-
- init_night_mode ();
+ nta_headerbar.show ();
+ set_titlebar (nta_headerbar);
manage_high_contrast ();
@@ -340,34 +354,4 @@ private abstract class AdaptativeWindow : ApplicationWindow
else
context.remove_class ("hc-theme");
}
-
- /*\
- * * manage night mode
- \*/
-
- // for construct only
- [CCode (notify = false)] public bool initial_night_time { private get; protected construct; }
- [CCode (notify = false)] public bool initial_dark_theme { private get; protected construct; }
- [CCode (notify = false)] public bool initial_automatic_night_mode { private get; protected construct; }
-
- private void init_night_mode ()
- {
- adaptative_headerbar.init_night_mode (initial_night_time, initial_dark_theme,
initial_automatic_night_mode);
- }
-
- // for updates
- internal void night_time_changed (Object nlm, ParamSpec thing)
- {
- adaptative_headerbar.set_night_time (NightLightMonitor.NightTime.should_use_dark_theme
(((NightLightMonitor) nlm).night_time));
- }
-
- internal void dark_theme_changed (Object nlm, ParamSpec thing)
- {
- adaptative_headerbar.set_dark_theme (((NightLightMonitor) nlm).dark_theme);
- }
-
- internal void automatic_night_mode_changed (Object nlm, ParamSpec thing)
- {
- adaptative_headerbar.set_automatic_night_mode (((NightLightMonitor) nlm).automatic_night_mode);
- }
}
diff --git a/editor/browser-headerbar.ui b/editor/browser-headerbar.ui
index fb8532c..1c7cbc8 100644
--- a/editor/browser-headerbar.ui
+++ b/editor/browser-headerbar.ui
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="dconf-editor">
<!-- interface-requires gtk+ 3.0 -->
- <template class="BrowserHeaderBar" parent="AdaptativeHeaderBar">
+ <template class="BrowserHeaderBar" parent="NightTimeAwareHeaderBar">
<property name="show-close-button">True</property>
<property name="has-subtitle">False</property>
<child>
diff --git a/editor/browser-headerbar.vala b/editor/browser-headerbar.vala
index 3f0cc11..fdc048c 100644
--- a/editor/browser-headerbar.vala
+++ b/editor/browser-headerbar.vala
@@ -18,7 +18,7 @@
using Gtk;
[GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/browser-headerbar.ui")]
-private abstract class BrowserHeaderBar : AdaptativeHeaderBar, AdaptativeWidget
+private abstract class BrowserHeaderBar : NightTimeAwareHeaderBar, AdaptativeWidget
{
[GtkChild] protected MenuButton info_button;
[GtkChild] protected PathWidget path_widget;
diff --git a/editor/browser-window.vala b/editor/browser-window.vala
index 16a5793..d873a49 100644
--- a/editor/browser-window.vala
+++ b/editor/browser-window.vala
@@ -33,7 +33,7 @@ private abstract class BrowserWindow : AdaptativeWindow, AdaptativeWidget
construct
{
- headerbar = (BrowserHeaderBar) adaptative_headerbar;
+ headerbar = (BrowserHeaderBar) nta_headerbar;
headerbar.search_changed.connect (search_changed_cb);
headerbar.search_stopped.connect (search_stopped_cb);
diff --git a/editor/dconf-editor.vala b/editor/dconf-editor.vala
index e8cd740..c437b27 100644
--- a/editor/dconf-editor.vala
+++ b/editor/dconf-editor.vala
@@ -512,13 +512,9 @@ private class ConfigurationEditor : Gtk.Application
private Gtk.Window get_new_window (string? schema, string? path, string? key_name)
{
- DConfWindow window = new DConfWindow (disable_warning, schema, path, key_name,
NightLightMonitor.NightTime.should_use_dark_theme (night_light_monitor.night_time),
night_light_monitor.dark_theme, night_light_monitor.automatic_night_mode);
+ DConfWindow window = new DConfWindow (disable_warning, schema, path, key_name, night_light_monitor);
add_window (window);
- night_light_monitor.notify ["night-time"].connect (window.night_time_changed);
- night_light_monitor.notify ["dark-theme"].connect (window.dark_theme_changed);
- night_light_monitor.notify ["automatic-night-mode"].connect (window.automatic_night_mode_changed);
-
return (Gtk.Window) window;
}
diff --git a/editor/dconf-headerbar.vala b/editor/dconf-headerbar.vala
index 7c4a503..d904770 100644
--- a/editor/dconf-headerbar.vala
+++ b/editor/dconf-headerbar.vala
@@ -46,6 +46,11 @@ private class DConfHeaderBar : BrowserHeaderBar
construct_modifications_actions_button_menu ();
}
+ internal DConfHeaderBar (NightLightMonitor _night_light_monitor)
+ {
+ Object (night_light_monitor: _night_light_monitor);
+ }
+
/*\
* * bookmarks revealer
\*/
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 9933782..58a5b6b 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -119,10 +119,10 @@ private class DConfWindow : BrowserWindow
bookmarks_selection_changed_handler = browser_view.bookmarks_selection_changed.connect
(on_bookmarks_selection_changed);
}
- internal DConfWindow (bool disable_warning, string? schema, string? path, string? key_name, bool
night_time, bool dark_theme, bool automatic_night_mode)
+ internal DConfWindow (bool disable_warning, string? schema, string? path, string? key_name,
NightLightMonitor night_light_monitor)
{
- DConfHeaderBar _headerbar = new DConfHeaderBar ();
- Object (initial_night_time: night_time, initial_dark_theme: dark_theme,
initial_automatic_night_mode: automatic_night_mode, adaptative_headerbar: (AdaptativeHeaderBar) _headerbar);
+ DConfHeaderBar _headerbar = new DConfHeaderBar (night_light_monitor);
+ Object (nta_headerbar: (NightTimeAwareHeaderBar) _headerbar);
headerbar = _headerbar;
headerbar_update_bookmarks_icons_handler = headerbar.update_bookmarks_icons.connect
(update_bookmarks_icons_from_variant);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]