Bind GtkSettings dark property to GSettings
Now you can switch between dark and light on the fly
This commit is contained in:
parent
ef2286dca4
commit
f56fac6877
@ -1,13 +1,13 @@
|
|||||||
#![allow(new_without_default)]
|
#![allow(new_without_default)]
|
||||||
|
#![allow(unused)]
|
||||||
|
|
||||||
use gio::{
|
use gio::{
|
||||||
self, ActionMapExt, ApplicationExt, ApplicationExtManual, ApplicationFlags, SettingsExt,
|
self, ActionMapExt, ApplicationExt, ApplicationExtManual, ApplicationFlags,
|
||||||
SimpleAction, SimpleActionExt,
|
SettingsBindFlags, SettingsExt, SimpleAction, SimpleActionExt,
|
||||||
};
|
};
|
||||||
use glib;
|
use glib;
|
||||||
use gtk;
|
use gtk;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::SettingsExt as GtkSettingsExt;
|
|
||||||
|
|
||||||
use crossbeam_channel::{unbounded, Receiver, Sender};
|
use crossbeam_channel::{unbounded, Receiver, Sender};
|
||||||
use hammond_data::Show;
|
use hammond_data::Show;
|
||||||
@ -150,9 +150,12 @@ impl App {
|
|||||||
|
|
||||||
fn setup_dark_theme(&self) {
|
fn setup_dark_theme(&self) {
|
||||||
let gtk_settings = gtk::Settings::get_default().unwrap();
|
let gtk_settings = gtk::Settings::get_default().unwrap();
|
||||||
let enabled = self.settings.get_boolean("dark-theme");
|
self.settings.bind(
|
||||||
|
"dark-theme",
|
||||||
gtk_settings.set_property_gtk_application_prefer_dark_theme(enabled);
|
>k_settings,
|
||||||
|
"gtk-application-prefer-dark-theme",
|
||||||
|
SettingsBindFlags::DEFAULT,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup_refresh_on_startup(&self) {
|
fn setup_refresh_on_startup(&self) {
|
||||||
@ -187,6 +190,7 @@ impl App {
|
|||||||
let win = &self.window;
|
let win = &self.window;
|
||||||
let instance = &self.instance;
|
let instance = &self.instance;
|
||||||
let header = &self.headerbar;
|
let header = &self.headerbar;
|
||||||
|
let settings = &self.settings;
|
||||||
|
|
||||||
// Create the `refresh` action.
|
// Create the `refresh` action.
|
||||||
//
|
//
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
#![allow(dead_code)]
|
||||||
|
|
||||||
use gio;
|
use gio;
|
||||||
use gio::{Settings, SettingsExt};
|
use gio::{Settings, SettingsExt};
|
||||||
use gtk;
|
use gtk;
|
||||||
@ -87,7 +89,7 @@ impl Prefs {
|
|||||||
let store = gtk::ListStore::new(&[gtk::Type::String]);
|
let store = gtk::ListStore::new(&[gtk::Type::String]);
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
for item in ["Seconds", "Minutes", "Hours", "Days", "Weeks"].iter() {
|
for item in ["Seconds", "Minutes", "Hours", "Days", "Weeks"].iter() {
|
||||||
let row = [&(item) as &ToValue];
|
let row: &[&ToValue] = &[item];
|
||||||
if item.to_lowercase() == refresh_p {
|
if item.to_lowercase() == refresh_p {
|
||||||
refresh_pos = i;
|
refresh_pos = i;
|
||||||
}
|
}
|
||||||
@ -95,7 +97,7 @@ impl Prefs {
|
|||||||
cleanup_pos = i;
|
cleanup_pos = i;
|
||||||
}
|
}
|
||||||
store.insert_with_values(None, &[0], &row);
|
store.insert_with_values(None, &[0], &row);
|
||||||
i += 1 ;
|
i += 1;
|
||||||
}
|
}
|
||||||
for combo in [self.refresh_type.clone(), self.cleanup_type.clone()].iter() {
|
for combo in [self.refresh_type.clone(), self.cleanup_type.clone()].iter() {
|
||||||
combo.set_model(Some(&store));
|
combo.set_model(Some(&store));
|
||||||
@ -119,7 +121,7 @@ impl Prefs {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn show(&self, parent: >k::Window) {
|
pub fn show(&self, parent: >k::ApplicationWindow) {
|
||||||
self.dialog.set_transient_for(Some(parent));
|
self.dialog.set_transient_for(Some(parent));
|
||||||
self.dialog.set_modal(true);
|
self.dialog.set_modal(true);
|
||||||
self.dialog.show_all();
|
self.dialog.show_all();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user