Commit e4bc262a authored by Bilal Elmoussaoui's avatar Bilal Elmoussaoui

Window: add dark mode to the app menu

parent 7a5a288d
Pipeline #98106 passed with stages
in 7 minutes and 4 seconds
......@@ -3,28 +3,27 @@
<schema path="/org/gnome/design/IconLibrary/" id="@app-id@" gettext-domain="@gettext-package@">
<key name="window-width" type="i">
<default>-1</default>
<summary>Default window width</summary>
<description>Default window width</description>
<summary>Width of the last opened window</summary>
</key>
<key name="window-height" type="i">
<default>-1</default>
<summary>Default window height</summary>
<description>Default window height</description>
<summary>Heigh of the last opened window</summary>
</key>
<key name="window-x" type="i">
<default>-1</default>
<summary>Default window x position</summary>
<description>Default window x position</description>
<summary>Left position of the last opened window</summary>
</key>
<key name="window-y" type="i">
<default>-1</default>
<summary>Default window y position</summary>
<description>Default window y position</description>
<summary>Top position of the last opened window</summary>
</key>
<key name="is-maximized" type="b">
<default>false</default>
<summary>Default window maximized behaviour</summary>
<description></description>
<summary>Maximized state of the last opened window</summary>
</key>
<key name="dark-mode" type="b">
<default>false</default>
<summary>Enable or disable dark mode</summary>
</key>
</schema>
</schemalist>
......@@ -2,14 +2,22 @@
<interface>
<!-- interface-requires gtk+ 3.0 -->
<menu id="popover_menu">
<item>
<attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>
<attribute name="action">win.show-help-overlay</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_About Icon Library</attribute>
<attribute name="action">app.about</attribute>
</item>
<section>
<item>
<attribute name="label" translatable="yes">_Dark Mode</attribute>
<attribute name="action">app.dark-mode</attribute>
</item>
</section>
<section>
<item>
<attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>
<attribute name="action">win.show-help-overlay</attribute>
</item>
<item>
<attribute name="label" translatable="yes">_About Icon Library</attribute>
<attribute name="action">app.about</attribute>
</item>
</section>
</menu>
</interface>
......
......@@ -18,6 +18,13 @@
<property name="accelerator">&lt;Primary&gt;question</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">True</property>
<property name="title" translatable="yes" context="shortcut window">Dark Mode</property>
<property name="accelerator">&lt;Primary&gt;T</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">True</property>
......
......@@ -50,8 +50,24 @@ impl Application {
about_dialog.show();
});
self.app.add_action(&simple_action);
self.app.set_accels_for_action("app.about", &["<primary>comma"]);
// Dark mode
let settings = gio::Settings::new(config::APP_ID);
let gtk_settings = gtk::Settings::get_default().unwrap();
settings.bind("dark-mode", &gtk_settings, "gtk-application-prefer-dark-theme", gio::SettingsBindFlags::DEFAULT);
let is_dark_mode = settings.get_boolean("dark-mode");
let simple_action = gio::SimpleAction::new_stateful("dark-mode", None, &is_dark_mode.to_variant());
simple_action.connect_activate(move |action, _| {
let state = action.get_state().unwrap();
let action_state: bool = state.get().unwrap();
let is_dark_mode = !action_state;
action.set_state(&is_dark_mode.to_variant());
settings.set_boolean("dark-mode", is_dark_mode);
});
self.app.add_action(&simple_action);
self.app.set_accels_for_action("app.dark-mode", &["<primary>T"]);
}
pub fn setup_signals(&self) {
......
use crate::gtk::SettingsExt as gtkSettingsExt;
use gio::prelude::SettingsExt;
use gtk::prelude::GtkWindowExt;
......@@ -18,6 +19,11 @@ pub fn load(window: &gtk::ApplicationWindow, settings: &gio::Settings) {
} else if is_maximized {
window.maximize();
}
// dark mode
let is_dark_mode: bool = settings.get_boolean("dark-mode");
let gtk_settings = gtk::Settings::get_default().unwrap();
gtk_settings.set_property_gtk_application_prefer_dark_theme(is_dark_mode);
}
pub fn save(window: &gtk::ApplicationWindow, settings: &gio::Settings) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment