Skip to content

Commit

Permalink
Rename to edge_snap_threshold, pass by value
Browse files Browse the repository at this point in the history
  • Loading branch information
Koranir committed Feb 14, 2025
1 parent c9f8318 commit f627a92
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 36 deletions.
4 changes: 2 additions & 2 deletions cosmic-comp-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,10 +846,10 @@ fn config_changed(config: cosmic_config::Config, keys: Vec<String>, state: &mut
state.common.config.cosmic_conf.focus_follows_cursor_delay = new;
}
}
"window_snap_threshold" => {
let new = get_config::<u32>(&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::<u32>(&config, "edge_snap_threshold");
if new != state.common.config.cosmic_conf.edge_snap_threshold {
state.common.config.cosmic_conf.edge_snap_threshold = new;
}
}
_ => {}
Expand Down
6 changes: 5 additions & 1 deletion src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/shell/element/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,6 @@ impl PointerTarget<State> 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,
Expand All @@ -1370,6 +1369,7 @@ impl PointerTarget<State> for CosmicStack {
Focus::ResizeRight => ResizeEdge::RIGHT,
Focus::Header => unreachable!(),
},
state.common.config.cosmic_conf.edge_snap_threshold,
false,
);
if let Some((grab, focus)) = res {
Expand Down
2 changes: 1 addition & 1 deletion src/shell/element/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,6 @@ impl PointerTarget<State> 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,
Expand All @@ -760,6 +759,7 @@ impl PointerTarget<State> for CosmicWindow {
Focus::ResizeRight => ResizeEdge::RIGHT,
Focus::Header => unreachable!(),
},
state.common.config.cosmic_conf.edge_snap_threshold,
false,
);

Expand Down
8 changes: 4 additions & 4 deletions src/shell/grabs/menu/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
26 changes: 13 additions & 13 deletions src/shell/layout/floating/grabs/resize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<i32, Local>,
initial_window_size: Size<i32, Logical>,
last_window_size: Size<i32, Logical>,
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -419,7 +419,7 @@ impl ResizeSurfaceGrab {
mapped: CosmicMapped,
edges: ResizeEdge,
output: Output,
window_snap_threshold: i32,
edge_snap_threshold: u32,
initial_window_location: Point<i32, Local>,
initial_window_size: Size<i32, Logical>,
seat: &Seat<State>,
Expand Down Expand Up @@ -463,7 +463,7 @@ impl ResizeSurfaceGrab {
initial_window_size,
last_window_size: initial_window_size,
release,
window_snap_threshold,
edge_snap_threshold,
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/shell/layout/floating/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use smithay::{

use crate::{
backend::render::{element::AsGlowRenderer, IndicatorShader, Key, Usage},
config::Config,
shell::{
element::{
resize_indicator::ResizeIndicator,
Expand Down Expand Up @@ -885,11 +884,11 @@ impl FloatingLayout {

pub fn resize_request(
&mut self,
config: &Config,
mapped: &CosmicMapped,
seat: &Seat<State>,
start_data: GrabStartData,
edges: ResizeEdge,
edge_snap_threshold: u32,
release: ReleaseMode,
) -> Option<ResizeSurfaceGrab> {
if seat.get_pointer().is_some() {
Expand All @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -3148,10 +3148,10 @@ impl Shell {

pub fn menu_resize_request(
&mut self,
config: &Config,
mapped: &CosmicMapped,
seat: &Seat<State>,
edge: ResizeEdge,
edge_snap_threshold: u32,
) -> Option<(
(
Option<(PointerFocusTarget, Point<f64, Logical>)>,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -3391,11 +3391,11 @@ impl Shell {

pub fn resize_request(
&mut self,
config: &Config,
surface: &WlSurface,
seat: &Seat<State>,
serial: impl Into<Option<Serial>>,
edges: ResizeEdge,
edge_snap_threshold: u32,
client_initiated: bool,
) -> Option<(ResizeGrab, Focus)> {
let serial = serial.into();
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion src/wayland/handlers/xdg_shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/xwayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f627a92

Please sign in to comment.