config: Load toolkit config on start
This commit is contained in:
parent
24462f728b
commit
c299748997
2 changed files with 52 additions and 8 deletions
|
|
@ -165,16 +165,27 @@ impl Config {
|
||||||
|
|
||||||
// Listen for updates to the toolkit config
|
// Listen for updates to the toolkit config
|
||||||
if let Ok(tk_config) = cosmic_config::Config::new("com.system76.CosmicTk", 1) {
|
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) {
|
match cosmic_config::calloop::ConfigWatchSource::new(&tk_config) {
|
||||||
Ok(source) => {
|
Ok(source) => {
|
||||||
if let Err(err) =
|
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 let Ok(config) = CosmicTk::get_entry(&config) {
|
||||||
if cosmic::icon_theme::default() != config.icon_theme {
|
handle_new_toolkit_config(config, state);
|
||||||
cosmic::icon_theme::set_default(config.icon_theme.clone());
|
|
||||||
}
|
|
||||||
|
|
||||||
cosmic::config::COSMIC_TK.with(move |tk| *tk.borrow_mut() = config);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1028,9 +1028,7 @@ impl Workspaces {
|
||||||
s.sticky_layer.theme = theme.clone();
|
s.sticky_layer.theme = theme.clone();
|
||||||
s.sticky_layer.mapped().for_each(|m| {
|
s.sticky_layer.mapped().for_each(|m| {
|
||||||
m.update_theme(theme.clone());
|
m.update_theme(theme.clone());
|
||||||
m.force_redraw();
|
|
||||||
});
|
});
|
||||||
s.sticky_layer.refresh();
|
|
||||||
|
|
||||||
for w in &mut s.workspaces {
|
for w in &mut s.workspaces {
|
||||||
w.tiling_layer.theme = theme.clone();
|
w.tiling_layer.theme = theme.clone();
|
||||||
|
|
@ -1038,6 +1036,22 @@ impl Workspaces {
|
||||||
|
|
||||||
w.mapped().for_each(|m| {
|
w.mapped().for_each(|m| {
|
||||||
m.update_theme(theme.clone());
|
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();
|
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(
|
pub fn set_theme(
|
||||||
&mut self,
|
&mut self,
|
||||||
theme: cosmic::Theme,
|
theme: cosmic::Theme,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue