diff --git a/cosmic-settings/src/pages/desktop/appearance/mod.rs b/cosmic-settings/src/pages/desktop/appearance/mod.rs index 1bf3b77..1e67038 100644 --- a/cosmic-settings/src/pages/desktop/appearance/mod.rs +++ b/cosmic-settings/src/pages/desktop/appearance/mod.rs @@ -1784,7 +1784,7 @@ pub fn interface_density() -> Section { Section::default() .title(fl!("interface-density")) .descriptions(descriptions) - .view::(move |_binder, page, section| { + .view::(move |_binder, _page, section| { let descriptions = §ion.descriptions; let density = cosmic::config::interface_density(); diff --git a/cosmic-settings/src/pages/desktop/mod.rs b/cosmic-settings/src/pages/desktop/mod.rs index d3b0e44..a6f2de2 100644 --- a/cosmic-settings/src/pages/desktop/mod.rs +++ b/cosmic-settings/src/pages/desktop/mod.rs @@ -8,33 +8,15 @@ pub mod wallpaper; pub mod window_management; pub mod workspaces; -use cosmic::{config::CosmicTk, cosmic_config::CosmicConfigEntry}; use cosmic_settings_page as page; #[derive(Debug)] #[allow(clippy::struct_excessive_bools)] -pub struct Page { - pub cosmic_config: Option, - pub cosmic_tk: CosmicTk, -} +pub struct Page {} impl Default for Page { fn default() -> Self { - let (cosmic_tk, cosmic_config) = CosmicTk::config().map_or_else( - |why| { - tracing::error!(?why, "failed to read CosmicTk config"); - (CosmicTk::default(), None) - }, - |config| match CosmicTk::get_entry(&config) { - Ok(tk) => (tk, Some(config)), - Err((_errors, tk)) => (tk, Some(config)), - }, - ); - - Self { - cosmic_config, - cosmic_tk, - } + Self {} } } @@ -56,25 +38,8 @@ impl page::AutoBind for Page { } #[derive(Copy, Clone, Debug)] -pub enum Message { - ShowMaximizeButton(bool), - ShowMinimizeButton(bool), -} +pub enum Message {} impl Page { - pub fn update(&mut self, message: Message) { - match message { - Message::ShowMaximizeButton(value) => { - if let Some(config) = self.cosmic_config.as_mut() { - let _res = self.cosmic_tk.set_show_maximize(config, value); - } - } - - Message::ShowMinimizeButton(value) => { - if let Some(config) = self.cosmic_config.as_mut() { - let _res = self.cosmic_tk.set_show_minimize(config, value); - } - } - } - } + pub fn update(&mut self, _message: Message) {} } diff --git a/cosmic-settings/src/pages/desktop/window_management.rs b/cosmic-settings/src/pages/desktop/window_management.rs index fa22cb1..527a1ff 100644 --- a/cosmic-settings/src/pages/desktop/window_management.rs +++ b/cosmic-settings/src/pages/desktop/window_management.rs @@ -22,6 +22,9 @@ pub enum Message { SaveFocusFollowsCursorDelay(bool), SetFocusFollowsCursorDelay(String), SetCursorFollowsFocus(bool), + ShowActiveWindowHint(bool), + ShowMaximizeButton(bool), + ShowMinimizeButton(bool), } pub struct Page { @@ -32,6 +35,7 @@ pub struct Page { focus_follows_cursor_delay: u64, focus_delay_text: String, cursor_follows_focus: bool, + show_active_hint: bool, } impl Default for Page { @@ -63,6 +67,15 @@ impl Default for Page { }) .unwrap_or(250); + let show_active_hint = comp_config + .get("active_hint") + .inspect_err(|err| { + if !matches!(err, cosmic_config::Error::NoConfigDirectory) { + error!(?err, "Failed to read config 'active_hint'") + } + }) + .unwrap_or(true); + Page { super_key_selections: vec![ fl!("super-key", "launcher"), @@ -76,6 +89,7 @@ impl Default for Page { focus_follows_cursor_delay, focus_delay_text: format!("{focus_follows_cursor_delay}"), cursor_follows_focus, + show_active_hint, } } } @@ -132,6 +146,28 @@ impl Page { error!(?err, "Failed to set config 'cursor_follows_focus'"); } } + Message::ShowMaximizeButton(value) => { + if let Ok(config) = cosmic::config::CosmicTk::config() { + let _res = cosmic::config::COSMIC_TK + .write() + .unwrap() + .set_show_maximize(&config, value); + } + } + Message::ShowMinimizeButton(value) => { + if let Ok(config) = cosmic::config::CosmicTk::config() { + let _res = cosmic::config::COSMIC_TK + .write() + .unwrap() + .set_show_minimize(&config, value); + } + } + Message::ShowActiveWindowHint(value) => { + self.show_active_hint = value; + if let Err(err) = self.comp_config.set("active_hint", value) { + error!(?err, "Failed to set config 'active_hint'"); + } + } } } } @@ -194,36 +230,38 @@ pub fn window_controls() -> Section { let maximize = descriptions.insert(fl!("window-controls", "maximize")); let minimize = descriptions.insert(fl!("window-controls", "minimize")); + let active_window_hint = descriptions.insert(fl!("window-controls", "active-window-hint")); Section::default() .title(fl!("window-controls")) .descriptions(descriptions) - .view::(move |binder, _page, section| { - let desktop = binder - .page::() - .expect("desktop page not found"); + .view::(move |_binder, page, section| { let descriptions = §ion.descriptions; settings::section() .title(§ion.title) + .add(settings::item( + &descriptions[active_window_hint], + toggler(None, page.show_active_hint, Message::ShowActiveWindowHint), + )) .add(settings::item( &descriptions[maximize], toggler( None, - desktop.cosmic_tk.show_maximize, - super::Message::ShowMaximizeButton, + cosmic::config::show_maximize(), + Message::ShowMaximizeButton, ), )) .add(settings::item( &descriptions[minimize], toggler( None, - desktop.cosmic_tk.show_minimize, - super::Message::ShowMinimizeButton, + cosmic::config::show_minimize(), + Message::ShowMinimizeButton, ), )) .apply(Element::from) - .map(crate::pages::Message::Desktop) + .map(crate::pages::Message::WindowManagement) }) } diff --git a/i18n/en/cosmic_settings.ftl b/i18n/en/cosmic_settings.ftl index 1bac41f..09ce0c9 100644 --- a/i18n/en/cosmic_settings.ftl +++ b/i18n/en/cosmic_settings.ftl @@ -307,6 +307,7 @@ super-key = Super key action window-controls = Window Controls .maximize = Show maximize button .minimize = Show minimize button + .active-window-hint = Show active window hint focus-navigation = Focus Navigation .focus-follows-cursor = Focus follows cursor