config: watch CosmicTk
This commit is contained in:
parent
61f11d1363
commit
fdde46febd
1 changed files with 57 additions and 20 deletions
|
|
@ -38,6 +38,7 @@ pub mod key_bindings;
|
||||||
pub use key_bindings::{Action, PrivateAction};
|
pub use key_bindings::{Action, PrivateAction};
|
||||||
mod types;
|
mod types;
|
||||||
pub use self::types::*;
|
pub use self::types::*;
|
||||||
|
use cosmic::config::CosmicTk;
|
||||||
use cosmic_comp_config::{
|
use cosmic_comp_config::{
|
||||||
input::InputConfig, workspace::WorkspaceConfig, CosmicCompConfig, TileBehavior, XkbConfig,
|
input::InputConfig, workspace::WorkspaceConfig, CosmicCompConfig, TileBehavior, XkbConfig,
|
||||||
};
|
};
|
||||||
|
|
@ -162,8 +163,33 @@ impl Config {
|
||||||
c
|
c
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Listen for updates to the toolkit config
|
||||||
|
if let Ok(tk_config) = cosmic_config::Config::new("com.system76.CosmicTk", 1) {
|
||||||
|
match cosmic_config::calloop::ConfigWatchSource::new(&tk_config) {
|
||||||
|
Ok(source) => {
|
||||||
|
if let Err(err) =
|
||||||
|
loop_handle.insert_source(source, |(config, _keys), (), _state| {
|
||||||
|
if let Ok(config) = CosmicTk::get_entry(&config) {
|
||||||
|
if cosmic::icon_theme::default() != config.icon_theme {
|
||||||
|
cosmic::icon_theme::set_default(config.icon_theme.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
cosmic::config::COSMIC_TK.with(move |tk| *tk.borrow_mut() = config);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
{
|
||||||
|
warn!(?err, "Failed to watch com.system76.CosmicTk config");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => warn!(
|
||||||
|
?err,
|
||||||
|
"failed to create config watch source for com.system76.CosmicTk"
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Source key bindings from com.system76.CosmicSettings.Shortcuts
|
// Source key bindings from com.system76.CosmicSettings.Shortcuts
|
||||||
let settings_context = shortcuts::context().unwrap();
|
let settings_context = shortcuts::context().expect("Failed to load shortcuts config");
|
||||||
let system_actions = shortcuts::system_actions(&config);
|
let system_actions = shortcuts::system_actions(&config);
|
||||||
let mut shortcuts = shortcuts::shortcuts(&settings_context);
|
let mut shortcuts = shortcuts::shortcuts(&settings_context);
|
||||||
|
|
||||||
|
|
@ -171,29 +197,40 @@ impl Config {
|
||||||
key_bindings::add_default_bindings(&mut shortcuts, workspace.workspace_layout);
|
key_bindings::add_default_bindings(&mut shortcuts, workspace.workspace_layout);
|
||||||
|
|
||||||
// Listen for updates to the keybindings config.
|
// Listen for updates to the keybindings config.
|
||||||
let source = cosmic_config::calloop::ConfigWatchSource::new(&settings_context).expect(
|
match cosmic_config::calloop::ConfigWatchSource::new(&settings_context) {
|
||||||
"failed to create config watch source for com.system76.CosmicSettings.Shortcuts",
|
Ok(source) => {
|
||||||
);
|
if let Err(err) = loop_handle.insert_source(source, |(config, keys), (), state| {
|
||||||
_ = loop_handle.insert_source(source, |(config, keys), (), state| {
|
for key in keys {
|
||||||
for key in keys {
|
match key.as_str() {
|
||||||
match key.as_str() {
|
// Reload the keyboard shortcuts config.
|
||||||
// Reload the keyboard shortcuts config.
|
"custom" | "defaults" => {
|
||||||
"custom" | "defaults" => {
|
let mut shortcuts = shortcuts::shortcuts(&config);
|
||||||
let mut shortcuts = shortcuts::shortcuts(&config);
|
let layout = get_config::<WorkspaceConfig>(&config, "workspaces")
|
||||||
let layout =
|
.workspace_layout;
|
||||||
get_config::<WorkspaceConfig>(&config, "workspaces").workspace_layout;
|
key_bindings::add_default_bindings(&mut shortcuts, layout);
|
||||||
key_bindings::add_default_bindings(&mut shortcuts, layout);
|
state.common.config.shortcuts = shortcuts;
|
||||||
state.common.config.shortcuts = shortcuts;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
"system_actions" => {
|
"system_actions" => {
|
||||||
state.common.config.system_actions = shortcuts::system_actions(&config);
|
state.common.config.system_actions =
|
||||||
}
|
shortcuts::system_actions(&config);
|
||||||
|
}
|
||||||
|
|
||||||
_ => (),
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}) {
|
||||||
|
warn!(
|
||||||
|
?err,
|
||||||
|
"Failed to watch com.system76.CosmicSettings.Shortcuts config"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
Err(err) => warn!(
|
||||||
|
?err,
|
||||||
|
"failed to create config watch source for com.system76.CosmicSettings.Shortcuts"
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
Config {
|
Config {
|
||||||
dynamic_conf: Self::load_dynamic(xdg.as_ref()),
|
dynamic_conf: Self::load_dynamic(xdg.as_ref()),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue