From a13a17e71c9610cf2357a2793f26e978f348069e Mon Sep 17 00:00:00 2001 From: Daniel <101683475+Koranir@users.noreply.github.com> Date: Fri, 14 Feb 2025 21:28:13 +1100 Subject: [PATCH] Rename to edge_snap_threshold, pass by value --- cosmic-comp-config/src/lib.rs | 4 ++-- src/config/mod.rs | 8 +++---- src/input/mod.rs | 6 +++++- src/shell/element/stack.rs | 2 +- src/shell/element/window.rs | 2 +- src/shell/grabs/menu/default.rs | 8 +++---- src/shell/layout/floating/grabs/resize.rs | 26 +++++++++++------------ src/shell/layout/floating/mod.rs | 5 ++--- src/shell/mod.rs | 10 ++++----- src/wayland/handlers/xdg_shell/mod.rs | 2 +- src/xwayland.rs | 2 +- 11 files changed, 39 insertions(+), 36 deletions(-) diff --git a/cosmic-comp-config/src/lib.rs b/cosmic-comp-config/src/lib.rs index f926124c1..aaf05c619 100644 --- a/cosmic-comp-config/src/lib.rs +++ b/cosmic-comp-config/src/lib.rs @@ -32,7 +32,7 @@ pub struct CosmicCompConfig { /// Let X11 applications scale themselves pub descale_xwayland: bool, /// The threshold before windows snap themselves to output edges - pub window_snap_threshold: u32, + pub edge_snap_threshold: u32, } impl Default for CosmicCompConfig { @@ -62,7 +62,7 @@ impl Default for CosmicCompConfig { cursor_follows_focus: false, focus_follows_cursor_delay: 250, descale_xwayland: false, - window_snap_threshold: 0, + edge_snap_threshold: 0, } } } diff --git a/src/config/mod.rs b/src/config/mod.rs index 9a27ba0b7..a133181f3 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -756,10 +756,10 @@ fn config_changed(config: cosmic_config::Config, keys: Vec, state: &mut state.common.config.cosmic_conf.focus_follows_cursor_delay = new; } } - "window_snap_threshold" => { - let new = get_config::(&config, "window_snap_threshold"); - if new != state.common.config.cosmic_conf.window_snap_threshold { - state.common.config.cosmic_conf.window_snap_threshold = new; + "edge_snap_threshold" => { + let new = get_config::(&config, "edge_snap_threshold"); + if new != state.common.config.cosmic_conf.edge_snap_threshold { + state.common.config.cosmic_conf.edge_snap_threshold = new; } } _ => {} diff --git a/src/input/mod.rs b/src/input/mod.rs index bf80fed41..b48ca027e 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -740,11 +740,15 @@ impl State { } }; let res = shell.resize_request( - &state.common.config, &surface, &seat_clone, serial, edge, + state + .common + .config + .cosmic_conf + .edge_snap_threshold, false, ); drop(shell); diff --git a/src/shell/element/stack.rs b/src/shell/element/stack.rs index 340985f11..9ee25a6d2 100644 --- a/src/shell/element/stack.rs +++ b/src/shell/element/stack.rs @@ -1355,7 +1355,6 @@ impl PointerTarget for CosmicStack { }; self.0.loop_handle().insert_idle(move |state| { let res = state.common.shell.write().unwrap().resize_request( - &state.common.config, &surface, &seat, serial, @@ -1370,6 +1369,7 @@ impl PointerTarget for CosmicStack { Focus::ResizeRight => ResizeEdge::RIGHT, Focus::Header => unreachable!(), }, + state.common.config.cosmic_conf.edge_snap_threshold, false, ); if let Some((grab, focus)) = res { diff --git a/src/shell/element/window.rs b/src/shell/element/window.rs index d58790db5..ac27add13 100644 --- a/src/shell/element/window.rs +++ b/src/shell/element/window.rs @@ -745,7 +745,6 @@ impl PointerTarget for CosmicWindow { }; self.0.loop_handle().insert_idle(move |state| { let res = state.common.shell.write().unwrap().resize_request( - &state.common.config, &surface, &seat, serial, @@ -760,6 +759,7 @@ impl PointerTarget for CosmicWindow { Focus::ResizeRight => ResizeEdge::RIGHT, Focus::Header => unreachable!(), }, + state.common.config.cosmic_conf.edge_snap_threshold, false, ); diff --git a/src/shell/grabs/menu/default.rs b/src/shell/grabs/menu/default.rs index 774551d3f..4d821d259 100644 --- a/src/shell/grabs/menu/default.rs +++ b/src/shell/grabs/menu/default.rs @@ -289,10 +289,10 @@ pub fn window_items( let mut shell = state.common.shell.write().unwrap(); let seat = shell.seats.last_active().clone(); let res = shell.menu_resize_request( - &state.common.config, &resize_clone, &seat, ResizeEdge::TOP, + state.common.config.cosmic_conf.edge_snap_threshold, ); std::mem::drop(shell); @@ -324,10 +324,10 @@ pub fn window_items( let mut shell = state.common.shell.write().unwrap(); let seat = shell.seats.last_active().clone(); let res = shell.menu_resize_request( - &state.common.config, &resize_clone, &seat, ResizeEdge::LEFT, + state.common.config.cosmic_conf.edge_snap_threshold, ); std::mem::drop(shell); @@ -359,10 +359,10 @@ pub fn window_items( let mut shell = state.common.shell.write().unwrap(); let seat = shell.seats.last_active().clone(); let res = shell.menu_resize_request( - &state.common.config, &resize_clone, &seat, ResizeEdge::RIGHT, + state.common.config.cosmic_conf.edge_snap_threshold, ); std::mem::drop(shell); @@ -394,10 +394,10 @@ pub fn window_items( let mut shell = state.common.shell.write().unwrap(); let seat = shell.seats.last_active().clone(); let res = shell.menu_resize_request( - &state.common.config, &resize_clone, &seat, ResizeEdge::BOTTOM, + state.common.config.cosmic_conf.edge_snap_threshold, ); std::mem::drop(shell); diff --git a/src/shell/layout/floating/grabs/resize.rs b/src/shell/layout/floating/grabs/resize.rs index eae6758ff..52d61880a 100644 --- a/src/shell/layout/floating/grabs/resize.rs +++ b/src/shell/layout/floating/grabs/resize.rs @@ -58,7 +58,7 @@ pub struct ResizeSurfaceGrab { window: CosmicMapped, edges: ResizeEdge, output: Output, - window_snap_threshold: i32, + edge_snap_threshold: u32, initial_window_location: Point, initial_window_size: Size, last_window_size: Size, @@ -97,18 +97,18 @@ impl ResizeSurfaceGrab { // If the resizing vertical edge is close to our output's edge in the same direction, snap to it. let output_geom = self.output.geometry().to_local(&self.output); if self.edges.intersects(ResizeEdge::LEFT) { - if (self.initial_window_location.x - dx as i32 - output_geom.loc.x).abs() - < self.window_snap_threshold + if ((self.initial_window_location.x - dx as i32 - output_geom.loc.x).abs() as u32) + < self.edge_snap_threshold { new_window_width = self.initial_window_size.w - output_geom.loc.x + self.initial_window_location.x; } } else { - if (self.initial_window_location.x + self.initial_window_size.w + dx as i32 + if ((self.initial_window_location.x + self.initial_window_size.w + dx as i32 - output_geom.loc.x - output_geom.size.w) - .abs() - < self.window_snap_threshold + .abs() as u32) + < self.edge_snap_threshold { new_window_width = output_geom.loc.x - self.initial_window_location.x + output_geom.size.w; @@ -126,18 +126,18 @@ impl ResizeSurfaceGrab { // If the resizing horizontal edge is close to our output's edge in the same direction, snap to it. let output_geom = self.output.geometry().to_local(&self.output); if self.edges.intersects(ResizeEdge::TOP) { - if (self.initial_window_location.y - dy as i32 - output_geom.loc.y).abs() - < self.window_snap_threshold + if ((self.initial_window_location.y - dy as i32 - output_geom.loc.y).abs() as u32) + < self.edge_snap_threshold { new_window_height = self.initial_window_size.h - output_geom.loc.y + self.initial_window_location.y; } } else { - if (self.initial_window_location.y + self.initial_window_size.h + dy as i32 + if ((self.initial_window_location.y + self.initial_window_size.h + dy as i32 - output_geom.loc.y - output_geom.size.h) - .abs() - < self.window_snap_threshold + .abs() as u32) + < self.edge_snap_threshold { new_window_height = output_geom.loc.y - self.initial_window_location.y + output_geom.size.h; @@ -419,7 +419,7 @@ impl ResizeSurfaceGrab { mapped: CosmicMapped, edges: ResizeEdge, output: Output, - window_snap_threshold: i32, + edge_snap_threshold: u32, initial_window_location: Point, initial_window_size: Size, seat: &Seat, @@ -463,7 +463,7 @@ impl ResizeSurfaceGrab { initial_window_size, last_window_size: initial_window_size, release, - window_snap_threshold, + edge_snap_threshold, } } diff --git a/src/shell/layout/floating/mod.rs b/src/shell/layout/floating/mod.rs index f1293cb53..20c72d6d7 100644 --- a/src/shell/layout/floating/mod.rs +++ b/src/shell/layout/floating/mod.rs @@ -25,7 +25,6 @@ use smithay::{ use crate::{ backend::render::{element::AsGlowRenderer, IndicatorShader, Key, Usage}, - config::Config, shell::{ element::{ resize_indicator::ResizeIndicator, @@ -885,11 +884,11 @@ impl FloatingLayout { pub fn resize_request( &mut self, - config: &Config, mapped: &CosmicMapped, seat: &Seat, start_data: GrabStartData, edges: ResizeEdge, + edge_snap_threshold: u32, release: ReleaseMode, ) -> Option { if seat.get_pointer().is_some() { @@ -902,7 +901,7 @@ impl FloatingLayout { mapped.clone(), edges, self.space.outputs().next().cloned().unwrap(), - config.cosmic_conf.window_snap_threshold as i32, + edge_snap_threshold, location, size, seat, diff --git a/src/shell/mod.rs b/src/shell/mod.rs index 7b566db59..ae080d34f 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -2866,7 +2866,7 @@ impl Shell { initial_window_location, cursor_output, active_hint, - config.cosmic_conf.window_snap_threshold as f64, + config.cosmic_conf.edge_snap_threshold as f64, layer, release, evlh.clone(), @@ -3118,10 +3118,10 @@ impl Shell { pub fn menu_resize_request( &mut self, - config: &Config, mapped: &CosmicMapped, seat: &Seat, edge: ResizeEdge, + edge_snap_threshold: u32, ) -> Option<( ( Option<(PointerFocusTarget, Point)>, @@ -3185,11 +3185,11 @@ impl Shell { start_data.set_focus(focus.clone()); let grab: ResizeGrab = if let Some(grab) = floating_layer.resize_request( - config, mapped, seat, start_data.clone(), edge, + edge_snap_threshold, ReleaseMode::Click, ) { grab.into() @@ -3361,11 +3361,11 @@ impl Shell { pub fn resize_request( &mut self, - config: &Config, surface: &WlSurface, seat: &Seat, serial: impl Into>, edges: ResizeEdge, + edge_snap_threshold: u32, client_initiated: bool, ) -> Option<(ResizeGrab, Focus)> { let serial = serial.into(); @@ -3389,11 +3389,11 @@ impl Shell { }; let grab: ResizeGrab = if let Some(grab) = floating_layer.resize_request( - config, &mapped, seat, start_data.clone(), edges, + edge_snap_threshold, ReleaseMode::NoMouseButtons, ) { grab.into() diff --git a/src/wayland/handlers/xdg_shell/mod.rs b/src/wayland/handlers/xdg_shell/mod.rs index e37f1f9fc..4b59a1d2d 100644 --- a/src/wayland/handlers/xdg_shell/mod.rs +++ b/src/wayland/handlers/xdg_shell/mod.rs @@ -190,11 +190,11 @@ impl XdgShellHandler for State { let seat = Seat::from_resource(&seat).unwrap(); let mut shell = self.common.shell.write().unwrap(); if let Some((grab, focus)) = shell.resize_request( - &self.common.config, surface.wl_surface(), &seat, serial, edges.into(), + self.common.config.cosmic_conf.edge_snap_threshold, true, ) { std::mem::drop(shell); diff --git a/src/xwayland.rs b/src/xwayland.rs index 44a6a275f..1c24e1b25 100644 --- a/src/xwayland.rs +++ b/src/xwayland.rs @@ -550,11 +550,11 @@ impl XwmHandler for State { let mut shell = self.common.shell.write().unwrap(); let seat = shell.seats.last_active().clone(); if let Some((grab, focus)) = shell.resize_request( - &self.common.config, &wl_surface, &seat, None, resize_edge.into(), + self.common.config.cosmic_conf.edge_snap_threshold, true, ) { std::mem::drop(shell);