diff --git a/cosmic-settings/src/pages/desktop/window_management.rs b/cosmic-settings/src/pages/desktop/window_management.rs index d9c7e54..2fb4989 100644 --- a/cosmic-settings/src/pages/desktop/window_management.rs +++ b/cosmic-settings/src/pages/desktop/window_management.rs @@ -25,6 +25,7 @@ pub enum Message { ShowActiveWindowHint(bool), ShowMaximizeButton(bool), ShowMinimizeButton(bool), + SetEdgeSnapThreshold(u32), } pub struct Page { @@ -36,6 +37,7 @@ pub struct Page { focus_delay_text: String, cursor_follows_focus: bool, show_active_hint: bool, + edge_snap_threshold: u32, } impl Default for Page { @@ -76,6 +78,15 @@ impl Default for Page { }) .unwrap_or(true); + let edge_snap_threshold = comp_config + .get("edge_snap_threshold") + .inspect_err(|err| { + if !matches!(err, cosmic_config::Error::NoConfigDirectory) { + error!(?err, "Failed to read config 'edge_snap_threshold'") + } + }) + .unwrap_or(0); + Page { super_key_selections: vec![ fl!("super-key", "launcher"), @@ -90,6 +101,7 @@ impl Default for Page { focus_delay_text: format!("{focus_follows_cursor_delay}"), cursor_follows_focus, show_active_hint, + edge_snap_threshold, } } } @@ -168,6 +180,12 @@ impl Page { error!(?err, "Failed to set config 'active_hint'"); } } + Message::SetEdgeSnapThreshold(value) => { + self.edge_snap_threshold = value; + if let Err(err) = self.comp_config.set("edge_snap_threshold", value) { + error!(?err, "Failed to set config 'edge_snap_threshold'"); + } + } } } } @@ -179,7 +197,7 @@ impl page::Page for Page { sections: &mut SlotMap>, ) -> Option { Some(vec![ - sections.insert(super_key_action()), + sections.insert(window_management()), sections.insert(window_controls()), sections.insert(focus_navigation()), ]) @@ -197,7 +215,7 @@ impl page::Page for Page { impl page::AutoBind for Page {} -pub fn super_key_action() -> Section { +pub fn window_management() -> Section { let mut descriptions = Slab::new(); let super_key = descriptions.insert(fl!("super-key")); @@ -206,6 +224,8 @@ pub fn super_key_action() -> Section { let _applications = descriptions.insert(fl!("super-key", "applications")); let _disable = descriptions.insert(fl!("super-key", "disable")); + let edge_gravity = descriptions.insert(fl!("edge-gravity")); + Section::default() .descriptions(descriptions) .view::(move |_binder, page, section| { @@ -220,6 +240,12 @@ pub fn super_key_action() -> Section { Message::SuperKey, )), ) + .add(settings::item( + &descriptions[edge_gravity], + toggler(page.edge_snap_threshold != 0).on_toggle(|is_enabled| { + Message::SetEdgeSnapThreshold(if is_enabled { 10 } else { 0 }) + }), + )) .apply(Element::from) .map(crate::pages::Message::WindowManagement) }) diff --git a/i18n/en/cosmic_settings.ftl b/i18n/en/cosmic_settings.ftl index f9779c1..454c5fd 100644 --- a/i18n/en/cosmic_settings.ftl +++ b/i18n/en/cosmic_settings.ftl @@ -302,6 +302,8 @@ super-key = Super key action .applications = Open Applications .disable = Disable +edge-gravity = Floating windows gravitate to nearby edges + window-controls = Window Controls .maximize = Show maximize button .minimize = Show minimize button