Bind GtkSettings dark property to GSettings

Now you can switch between dark and light on the fly
This commit is contained in:
Zander Brown 2018-05-21 23:32:23 +01:00 committed by Jordan Petridis
parent ef2286dca4
commit f56fac6877
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
2 changed files with 15 additions and 9 deletions

View File

@ -1,13 +1,13 @@
#![allow(new_without_default)]
#![allow(unused)]
use gio::{
self, ActionMapExt, ApplicationExt, ApplicationExtManual, ApplicationFlags, SettingsExt,
SimpleAction, SimpleActionExt,
self, ActionMapExt, ApplicationExt, ApplicationExtManual, ApplicationFlags,
SettingsBindFlags, SettingsExt, SimpleAction, SimpleActionExt,
};
use glib;
use gtk;
use gtk::prelude::*;
use gtk::SettingsExt as GtkSettingsExt;
use crossbeam_channel::{unbounded, Receiver, Sender};
use hammond_data::Show;
@ -150,9 +150,12 @@ impl App {
fn setup_dark_theme(&self) {
let gtk_settings = gtk::Settings::get_default().unwrap();
let enabled = self.settings.get_boolean("dark-theme");
gtk_settings.set_property_gtk_application_prefer_dark_theme(enabled);
self.settings.bind(
"dark-theme",
&gtk_settings,
"gtk-application-prefer-dark-theme",
SettingsBindFlags::DEFAULT,
);
}
fn setup_refresh_on_startup(&self) {
@ -187,6 +190,7 @@ impl App {
let win = &self.window;
let instance = &self.instance;
let header = &self.headerbar;
let settings = &self.settings;
// Create the `refresh` action.
//

View File

@ -1,3 +1,5 @@
#![allow(dead_code)]
use gio;
use gio::{Settings, SettingsExt};
use gtk;
@ -87,7 +89,7 @@ impl Prefs {
let store = gtk::ListStore::new(&[gtk::Type::String]);
let mut i = 0;
for item in ["Seconds", "Minutes", "Hours", "Days", "Weeks"].iter() {
let row = [&(item) as &ToValue];
let row: &[&ToValue] = &[item];
if item.to_lowercase() == refresh_p {
refresh_pos = i;
}
@ -119,7 +121,7 @@ impl Prefs {
}));
}
pub fn show(&self, parent: &gtk::Window) {
pub fn show(&self, parent: &gtk::ApplicationWindow) {
self.dialog.set_transient_for(Some(parent));
self.dialog.set_modal(true);
self.dialog.show_all();