grabs: Snap Window Edges to Close Output Edges
This commit is contained in:
parent
2678cf41b2
commit
2553810621
12 changed files with 148 additions and 13 deletions
|
|
@ -58,6 +58,8 @@ pub struct ResizeSurfaceGrab {
|
|||
window: CosmicMapped,
|
||||
edges: ResizeEdge,
|
||||
output: Output,
|
||||
edge_snap_threshold: u32,
|
||||
initial_window_location: Point<i32, Local>,
|
||||
initial_window_size: Size<i32, Logical>,
|
||||
last_window_size: Size<i32, Logical>,
|
||||
release: ReleaseMode,
|
||||
|
|
@ -91,6 +93,27 @@ impl ResizeSurfaceGrab {
|
|||
}
|
||||
|
||||
new_window_width = (self.initial_window_size.w as f64 + dx) as i32;
|
||||
|
||||
// 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() 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
|
||||
- output_geom.loc.x
|
||||
- output_geom.size.w)
|
||||
.abs() as u32)
|
||||
< self.edge_snap_threshold
|
||||
{
|
||||
new_window_width =
|
||||
output_geom.loc.x - self.initial_window_location.x + output_geom.size.w;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if self.edges.intersects(top_bottom) {
|
||||
|
|
@ -99,6 +122,27 @@ impl ResizeSurfaceGrab {
|
|||
}
|
||||
|
||||
new_window_height = (self.initial_window_size.h as f64 + dy) as i32;
|
||||
|
||||
// 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() 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
|
||||
- output_geom.loc.y
|
||||
- output_geom.size.h)
|
||||
.abs() as u32)
|
||||
< self.edge_snap_threshold
|
||||
{
|
||||
new_window_height =
|
||||
output_geom.loc.y - self.initial_window_location.y + output_geom.size.h;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let (min_size, max_size) = (self.window.min_size(), self.window.max_size());
|
||||
|
|
@ -375,6 +419,7 @@ impl ResizeSurfaceGrab {
|
|||
mapped: CosmicMapped,
|
||||
edges: ResizeEdge,
|
||||
output: Output,
|
||||
edge_snap_threshold: u32,
|
||||
initial_window_location: Point<i32, Local>,
|
||||
initial_window_size: Size<i32, Logical>,
|
||||
seat: &Seat<State>,
|
||||
|
|
@ -414,9 +459,11 @@ impl ResizeSurfaceGrab {
|
|||
window: mapped,
|
||||
edges,
|
||||
output,
|
||||
initial_window_location,
|
||||
initial_window_size,
|
||||
last_window_size: initial_window_size,
|
||||
release,
|
||||
edge_snap_threshold,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -888,6 +888,7 @@ impl FloatingLayout {
|
|||
seat: &Seat<State>,
|
||||
start_data: GrabStartData,
|
||||
edges: ResizeEdge,
|
||||
edge_snap_threshold: u32,
|
||||
release: ReleaseMode,
|
||||
) -> Option<ResizeSurfaceGrab> {
|
||||
if seat.get_pointer().is_some() {
|
||||
|
|
@ -900,6 +901,7 @@ impl FloatingLayout {
|
|||
mapped.clone(),
|
||||
edges,
|
||||
self.space.outputs().next().cloned().unwrap(),
|
||||
edge_snap_threshold,
|
||||
location,
|
||||
size,
|
||||
seat,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue