From c299748997812d0bc0f0ea7dd662b07d607b8c4d Mon Sep 17 00:00:00 2001 From: Victoria Brekenfeld Date: Fri, 2 Aug 2024 20:40:44 +0200 Subject: [PATCH] config: Load toolkit config on start --- src/config/mod.rs | 23 +++++++++++++++++------ src/shell/mod.rs | 37 +++++++++++++++++++++++++++++++++++-- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index ef0acb80..d8a5e0fa 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -165,16 +165,27 @@ impl Config { // Listen for updates to the toolkit config if let Ok(tk_config) = cosmic_config::Config::new("com.system76.CosmicTk", 1) { + fn handle_new_toolkit_config(config: CosmicTk, state: &mut State) { + let mut workspace_guard = state.common.workspace_state.update(); + state.common.shell.write().unwrap().update_toolkit( + config, + &state.common.xdg_activation_state, + &mut workspace_guard, + ); + } + + if let Ok(config) = CosmicTk::get_entry(&tk_config) { + let _ = loop_handle.insert_idle(move |state| { + handle_new_toolkit_config(config, state); + }); + } + match cosmic_config::calloop::ConfigWatchSource::new(&tk_config) { Ok(source) => { if let Err(err) = - loop_handle.insert_source(source, |(config, _keys), (), _state| { + 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); + handle_new_toolkit_config(config, state); } }) { diff --git a/src/shell/mod.rs b/src/shell/mod.rs index 09974de7..bc58ece5 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -1028,9 +1028,7 @@ impl Workspaces { s.sticky_layer.theme = theme.clone(); s.sticky_layer.mapped().for_each(|m| { m.update_theme(theme.clone()); - m.force_redraw(); }); - s.sticky_layer.refresh(); for w in &mut s.workspaces { w.tiling_layer.theme = theme.clone(); @@ -1038,6 +1036,22 @@ impl Workspaces { w.mapped().for_each(|m| { m.update_theme(theme.clone()); + }); + } + } + + self.force_redraw(xdg_activation_state); + } + + pub fn force_redraw(&mut self, xdg_activation_state: &XdgActivationState) { + for (_, s) in &mut self.sets { + s.sticky_layer.mapped().for_each(|m| { + m.force_redraw(); + }); + s.sticky_layer.refresh(); + + for w in &mut s.workspaces { + w.mapped().for_each(|m| { m.force_redraw(); }); @@ -3313,6 +3327,25 @@ impl Shell { } } + pub fn update_toolkit( + &mut self, + toolkit: cosmic::config::CosmicTk, + xdg_activation_state: &XdgActivationState, + workspace_state: &mut WorkspaceUpdateGuard<'_, State>, + ) { + if cosmic::icon_theme::default() != toolkit.icon_theme { + cosmic::icon_theme::set_default(toolkit.icon_theme.clone()); + } + + let mut container = cosmic::config::COSMIC_TK.lock().unwrap(); + if &*container != &toolkit { + *container = toolkit; + drop(container); + self.refresh(xdg_activation_state, workspace_state); + self.workspaces.force_redraw(xdg_activation_state); + } + } + pub fn set_theme( &mut self, theme: cosmic::Theme,