From f627a9221b932b04fb96778b64dd3a210f042f00 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 071767f1..1f941500 100644 --- a/cosmic-comp-config/src/lib.rs +++ b/cosmic-comp-config/src/lib.rs @@ -47,7 +47,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 { @@ -78,7 +78,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 8c59856e..0f080c5e 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -846,10 +846,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 343c8365..327f23ef 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -756,11 +756,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 340985f1..9ee25a6d 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 d58790db..ac27add1 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 774551d3..4d821d25 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 eae6758f..52d61880 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 c12106f0..e86ed545 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 bc5b65f1..e5a2c68f 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -2896,7 +2896,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(), @@ -3148,10 +3148,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)>, @@ -3215,11 +3215,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() @@ -3391,11 +3391,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(); @@ -3419,11 +3419,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 e864e55b..c8695e22 100644 --- a/src/wayland/handlers/xdg_shell/mod.rs +++ b/src/wayland/handlers/xdg_shell/mod.rs @@ -198,11 +198,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 151dcca6..fd146aae 100644 --- a/src/xwayland.rs +++ b/src/xwayland.rs @@ -557,11 +557,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);