Skip to content

Commit

Permalink
Update to latest changes, move to general section, update text
Browse files Browse the repository at this point in the history
  • Loading branch information
Koranir committed Feb 14, 2025
1 parent 4523a07 commit 6b81a5d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 44 deletions.
58 changes: 17 additions & 41 deletions cosmic-settings/src/pages/desktop/window_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub enum Message {
ShowActiveWindowHint(bool),
ShowMaximizeButton(bool),
ShowMinimizeButton(bool),
SetWindowSnapThreshold(u32),
SetEdgeSnapThreshold(u32),
}

pub struct Page {
Expand All @@ -37,7 +37,7 @@ pub struct Page {
focus_delay_text: String,
cursor_follows_focus: bool,
show_active_hint: bool,
window_snap_threshold: u32,
edge_snap_threshold: u32,
}

impl Default for Page {
Expand Down Expand Up @@ -101,7 +101,7 @@ impl Default for Page {
focus_delay_text: format!("{focus_follows_cursor_delay}"),
cursor_follows_focus,
show_active_hint,
window_snap_threshold,
edge_snap_threshold: window_snap_threshold,
}
}
}
Expand Down Expand Up @@ -180,10 +180,10 @@ impl Page {
error!(?err, "Failed to set config 'active_hint'");
}
}
Message::SetWindowSnapThreshold(value) => {
self.window_snap_threshold = value;
if let Err(err) = self.comp_config.set("window_snap_threshold", value) {
error!(?err, "Failed to set config 'window_snap_threshold'");
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'");
}
}
}
Expand All @@ -197,10 +197,9 @@ impl page::Page<crate::pages::Message> for Page {
sections: &mut SlotMap<section::Entity, Section<crate::pages::Message>>,
) -> Option<page::Content> {
Some(vec![
sections.insert(super_key_action()),
sections.insert(window_management()),
sections.insert(window_controls()),
sections.insert(focus_navigation()),
sections.insert(floating_layout()),
])
}

Expand All @@ -216,7 +215,7 @@ impl page::Page<crate::pages::Message> for Page {

impl page::AutoBind<crate::pages::Message> for Page {}

pub fn super_key_action() -> Section<crate::pages::Message> {
pub fn window_management() -> Section<crate::pages::Message> {
let mut descriptions = Slab::new();

let super_key = descriptions.insert(fl!("super-key"));
Expand All @@ -225,6 +224,8 @@ pub fn super_key_action() -> Section<crate::pages::Message> {
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::<Page>(move |_binder, page, section| {
Expand All @@ -239,6 +240,12 @@ pub fn super_key_action() -> Section<crate::pages::Message> {
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)
})
Expand Down Expand Up @@ -315,37 +322,6 @@ pub fn focus_navigation() -> Section<crate::pages::Message> {
})
}

pub fn floating_layout() -> Section<crate::pages::Message> {
let mut descriptions = Slab::new();

let window_snap_threshold =
descriptions.insert(fl!("floating-layout", "window-snap-threshold"));

Section::default()
.title(fl!("floating-layout"))
.descriptions(descriptions)
.view::<Page>(move |_binder, page, section| {
let descriptions = &section.descriptions;

settings::section()
.title(&section.title)
.add(
settings::item::builder(&descriptions[window_snap_threshold]).control(
widget::spin_button(
page.window_snap_threshold.to_string(),
page.window_snap_threshold,
5,
0,
500,
Message::SetWindowSnapThreshold,
),
),
)
.apply(Element::from)
.map(crate::pages::Message::WindowManagement)
})
}

fn super_key_active_config() -> Option<usize> {
let super_binding = Binding::new(shortcuts::Modifiers::new().logo(), None);

Expand Down
5 changes: 2 additions & 3 deletions i18n/en/cosmic_settings.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -312,9 +314,6 @@ focus-navigation = Focus Navigation
.focus-follows-cursor-delay = Focus follows cursor delay in ms
.cursor-follows-focus = Cursor follows focus
floating-layout = Floating Layout
.window-snap-threshold = Window snap-to-edge threshold
## Desktop: Workspaces

workspaces = Workspaces
Expand Down

0 comments on commit 6b81a5d

Please sign in to comment.