Skip to content

Commit

Permalink
floating: Limit resizing to current output
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakulix committed Oct 23, 2023
1 parent 7667d60 commit b5ef37d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
19 changes: 18 additions & 1 deletion src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use crate::{
shell::{
focus::{target::PointerFocusTarget, FocusDirection},
grabs::{ResizeEdge, SeatMoveGrabState},
layout::tiling::{SwapWindowGrab, TilingLayout},
layout::{
floating::ResizeGrabMarker,
tiling::{SwapWindowGrab, TilingLayout},
},
Direction, FocusResult, MoveResult, OverviewMode, ResizeDirection, ResizeMode, Trigger,
Workspace,
},
Expand Down Expand Up @@ -620,6 +623,20 @@ impl State {
.find(|output| output.geometry().to_f64().contains(position))
.cloned()
.unwrap_or(current_output.clone());

if ptr.is_grabbed()
&& seat
.user_data()
.get::<ResizeGrabMarker>()
.map(|marker| marker.get())
.unwrap_or(false)
{
if output != current_output {
ptr.frame(self);
return;
}
}

let output_geometry = output.geometry();

let workspace = self.common.shell.workspaces.active_mut(&output);
Expand Down
43 changes: 38 additions & 5 deletions src/shell/layout/floating/grabs/resize.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-only

use std::sync::atomic::{AtomicBool, Ordering};

use crate::{
shell::{
element::CosmicMapped, focus::target::PointerFocusTarget, grabs::ResizeEdge, CosmicSurface,
Expand All @@ -8,11 +10,15 @@ use crate::{
};
use smithay::{
desktop::space::SpaceElement,
input::pointer::{
AxisFrame, ButtonEvent, GestureHoldBeginEvent, GestureHoldEndEvent, GesturePinchBeginEvent,
GesturePinchEndEvent, GesturePinchUpdateEvent, GestureSwipeBeginEvent,
GestureSwipeEndEvent, GestureSwipeUpdateEvent, GrabStartData as PointerGrabStartData,
MotionEvent, PointerGrab, PointerInnerHandle, RelativeMotionEvent,
input::{
pointer::{
AxisFrame, ButtonEvent, GestureHoldBeginEvent, GestureHoldEndEvent,
GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent,
GestureSwipeBeginEvent, GestureSwipeEndEvent, GestureSwipeUpdateEvent,
GrabStartData as PointerGrabStartData, MotionEvent, PointerGrab, PointerInnerHandle,
RelativeMotionEvent,
},
Seat,
},
utils::{IsAlive, Logical, Point, Rectangle, Size},
};
Expand All @@ -39,6 +45,7 @@ pub enum ResizeState {

pub struct ResizeSurfaceGrab {
start_data: PointerGrabStartData<State>,
seat: Seat<State>,
window: CosmicMapped,
edges: ResizeEdge,
initial_window_size: Size<i32, Logical>,
Expand All @@ -58,6 +65,12 @@ impl PointerGrab<State> for ResizeSurfaceGrab {

// It is impossible to get `min_size` and `max_size` of dead toplevel, so we return early.
if !self.window.alive() {
self.seat
.user_data()
.get::<ResizeGrabMarker>()
.unwrap()
.0
.store(false, Ordering::SeqCst);
handle.unset_grab(data, event.serial, event.time, true);
return;
}
Expand Down Expand Up @@ -129,6 +142,12 @@ impl PointerGrab<State> for ResizeSurfaceGrab {
handle.button(data, event);
if handle.current_pressed().is_empty() {
// No more buttons are pressed, release the grab.
self.seat
.user_data()
.get::<ResizeGrabMarker>()
.unwrap()
.0
.store(false, Ordering::SeqCst);
handle.unset_grab(data, event.serial, event.time, true);

// If toplevel is dead, we can't resize it, so we return early.
Expand Down Expand Up @@ -245,13 +264,22 @@ impl PointerGrab<State> for ResizeSurfaceGrab {
}
}

pub struct ResizeGrabMarker(AtomicBool);

impl ResizeGrabMarker {
pub fn get(&self) -> bool {
self.0.load(Ordering::SeqCst)
}
}

impl ResizeSurfaceGrab {
pub fn new(
start_data: PointerGrabStartData<State>,
mapped: CosmicMapped,
edges: ResizeEdge,
initial_window_location: Point<i32, Logical>,
initial_window_size: Size<i32, Logical>,
seat: &Seat<State>,
) -> ResizeSurfaceGrab {
let resize_state = ResizeState::Resizing(ResizeData {
edges,
Expand All @@ -260,9 +288,14 @@ impl ResizeSurfaceGrab {
});

*mapped.resize_state.lock().unwrap() = Some(resize_state);
seat.user_data()
.get_or_insert::<ResizeGrabMarker, _>(|| ResizeGrabMarker(AtomicBool::new(true)))
.0
.store(true, Ordering::SeqCst);

ResizeSurfaceGrab {
start_data,
seat: seat.clone(),
window: mapped,
edges,
initial_window_size,
Expand Down
1 change: 1 addition & 0 deletions src/shell/layout/floating/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ impl FloatingLayout {
edges,
location,
size,
seat,
))
} else {
None
Expand Down

0 comments on commit b5ef37d

Please sign in to comment.