grabs: Add ReleaseMode for menu-initiated grabs
This commit is contained in:
parent
85771dff5e
commit
edfb0edda7
11 changed files with 206 additions and 81 deletions
|
|
@ -4,11 +4,15 @@ use std::sync::atomic::{AtomicBool, Ordering};
|
|||
|
||||
use crate::{
|
||||
shell::{
|
||||
element::CosmicMapped, focus::target::PointerFocusTarget, grabs::ResizeEdge, CosmicSurface,
|
||||
element::CosmicMapped,
|
||||
focus::target::PointerFocusTarget,
|
||||
grabs::{ReleaseMode, ResizeEdge},
|
||||
CosmicSurface,
|
||||
},
|
||||
utils::prelude::*,
|
||||
};
|
||||
use smithay::{
|
||||
backend::input::ButtonState,
|
||||
desktop::space::SpaceElement,
|
||||
input::{
|
||||
pointer::{
|
||||
|
|
@ -20,7 +24,7 @@ use smithay::{
|
|||
},
|
||||
Seat,
|
||||
},
|
||||
utils::{IsAlive, Logical, Point, Rectangle, Size},
|
||||
utils::{IsAlive, Logical, Point, Rectangle, Serial, Size},
|
||||
};
|
||||
|
||||
/// Information about the resize operation.
|
||||
|
|
@ -50,6 +54,7 @@ pub struct ResizeSurfaceGrab {
|
|||
edges: ResizeEdge,
|
||||
initial_window_size: Size<i32, Logical>,
|
||||
last_window_size: Size<i32, Logical>,
|
||||
release: ReleaseMode,
|
||||
}
|
||||
|
||||
impl PointerGrab<State> for ResizeSurfaceGrab {
|
||||
|
|
@ -140,36 +145,16 @@ impl PointerGrab<State> for ResizeSurfaceGrab {
|
|||
event: &ButtonEvent,
|
||||
) {
|
||||
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.
|
||||
if !self.window.alive() {
|
||||
return;
|
||||
match self.release {
|
||||
ReleaseMode::NoMouseButtons => {
|
||||
if handle.current_pressed().is_empty() {
|
||||
self.ungrab(data, handle, event.serial, event.time);
|
||||
}
|
||||
}
|
||||
|
||||
self.window.set_resizing(false);
|
||||
self.window.set_geometry(Rectangle::from_loc_and_size(
|
||||
match self.window.active_window() {
|
||||
CosmicSurface::X11(s) => s.geometry().loc.as_global(),
|
||||
_ => (0, 0).into(),
|
||||
},
|
||||
self.last_window_size.as_global(),
|
||||
));
|
||||
self.window.configure();
|
||||
|
||||
let mut resize_state = self.window.resize_state.lock().unwrap();
|
||||
if let Some(ResizeState::Resizing(resize_data)) = *resize_state {
|
||||
*resize_state = Some(ResizeState::WaitingForCommit(resize_data));
|
||||
} else {
|
||||
panic!("invalid resize state: {:?}", resize_state);
|
||||
ReleaseMode::Click => {
|
||||
if event.state == ButtonState::Pressed {
|
||||
self.ungrab(data, handle, event.serial, event.time);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -280,6 +265,7 @@ impl ResizeSurfaceGrab {
|
|||
initial_window_location: Point<i32, Local>,
|
||||
initial_window_size: Size<i32, Logical>,
|
||||
seat: &Seat<State>,
|
||||
release: ReleaseMode,
|
||||
) -> ResizeSurfaceGrab {
|
||||
let resize_state = ResizeState::Resizing(ResizeData {
|
||||
edges,
|
||||
|
|
@ -300,6 +286,7 @@ impl ResizeSurfaceGrab {
|
|||
edges,
|
||||
initial_window_size,
|
||||
last_window_size: initial_window_size,
|
||||
release,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -375,4 +362,43 @@ impl ResizeSurfaceGrab {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn ungrab(
|
||||
&mut self,
|
||||
data: &mut State,
|
||||
handle: &mut PointerInnerHandle<'_, State>,
|
||||
serial: Serial,
|
||||
time: u32,
|
||||
) {
|
||||
// No more buttons are pressed, release the grab.
|
||||
self.seat
|
||||
.user_data()
|
||||
.get::<ResizeGrabMarker>()
|
||||
.unwrap()
|
||||
.0
|
||||
.store(false, Ordering::SeqCst);
|
||||
handle.unset_grab(data, serial, time, true);
|
||||
|
||||
// If toplevel is dead, we can't resize it, so we return early.
|
||||
if !self.window.alive() {
|
||||
return;
|
||||
}
|
||||
|
||||
self.window.set_resizing(false);
|
||||
self.window.set_geometry(Rectangle::from_loc_and_size(
|
||||
match self.window.active_window() {
|
||||
CosmicSurface::X11(s) => s.geometry().loc.as_global(),
|
||||
_ => (0, 0).into(),
|
||||
},
|
||||
self.last_window_size.as_global(),
|
||||
));
|
||||
self.window.configure();
|
||||
|
||||
let mut resize_state = self.window.resize_state.lock().unwrap();
|
||||
if let Some(ResizeState::Resizing(resize_data)) = *resize_state {
|
||||
*resize_state = Some(ResizeState::WaitingForCommit(resize_data));
|
||||
} else {
|
||||
panic!("invalid resize state: {:?}", resize_state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ use crate::{
|
|||
CosmicMapped, CosmicMappedRenderElement, CosmicWindow,
|
||||
},
|
||||
focus::{target::KeyboardFocusTarget, FocusDirection, FocusStackMut},
|
||||
grabs::ResizeEdge,
|
||||
grabs::{ReleaseMode, ResizeEdge},
|
||||
CosmicSurface, Direction, FocusResult, MoveResult, ResizeDirection, ResizeMode,
|
||||
},
|
||||
state::State,
|
||||
|
|
@ -459,6 +459,7 @@ impl FloatingLayout {
|
|||
seat: &Seat<State>,
|
||||
start_data: PointerGrabStartData<State>,
|
||||
edges: ResizeEdge,
|
||||
release: ReleaseMode,
|
||||
) -> Option<ResizeSurfaceGrab> {
|
||||
if seat.get_pointer().is_some() {
|
||||
let location = self.space.element_location(&mapped).unwrap().as_local();
|
||||
|
|
@ -472,6 +473,7 @@ impl FloatingLayout {
|
|||
location,
|
||||
size,
|
||||
seat,
|
||||
release,
|
||||
))
|
||||
} else {
|
||||
None
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use crate::{
|
||||
backend::render::cursor::{CursorShape, CursorState},
|
||||
shell::{focus::target::PointerFocusTarget, layout::Orientation},
|
||||
shell::{focus::target::PointerFocusTarget, grabs::ReleaseMode, layout::Orientation},
|
||||
utils::prelude::*,
|
||||
};
|
||||
use id_tree::{NodeId, Tree};
|
||||
|
|
@ -74,20 +74,19 @@ impl PointerTarget<State> for ResizeForkTarget {
|
|||
let location = pointer.current_location();
|
||||
pointer.set_grab(
|
||||
state,
|
||||
ResizeForkGrab {
|
||||
start_data: PointerGrabStartData {
|
||||
ResizeForkGrab::new(
|
||||
PointerGrabStartData {
|
||||
focus: None,
|
||||
button,
|
||||
location,
|
||||
},
|
||||
old_tree: None,
|
||||
accumulated_delta: 0.0,
|
||||
last_loc: location,
|
||||
location.as_global(),
|
||||
node,
|
||||
output,
|
||||
left_up_idx,
|
||||
orientation,
|
||||
},
|
||||
output,
|
||||
ReleaseMode::NoMouseButtons,
|
||||
),
|
||||
serial,
|
||||
Focus::Clear,
|
||||
)
|
||||
|
|
@ -117,13 +116,38 @@ impl PointerTarget<State> for ResizeForkTarget {
|
|||
|
||||
pub struct ResizeForkGrab {
|
||||
start_data: PointerGrabStartData<State>,
|
||||
last_loc: Point<f64, Logical>,
|
||||
last_loc: Point<f64, Global>,
|
||||
old_tree: Option<Tree<Data>>,
|
||||
accumulated_delta: f64,
|
||||
node: NodeId,
|
||||
output: WeakOutput,
|
||||
left_up_idx: usize,
|
||||
orientation: Orientation,
|
||||
release: ReleaseMode,
|
||||
}
|
||||
|
||||
impl ResizeForkGrab {
|
||||
pub fn new(
|
||||
start_data: PointerGrabStartData<State>,
|
||||
pointer_loc: Point<f64, Global>,
|
||||
node: NodeId,
|
||||
idx: usize,
|
||||
orientation: Orientation,
|
||||
output: WeakOutput,
|
||||
release: ReleaseMode,
|
||||
) -> ResizeForkGrab {
|
||||
ResizeForkGrab {
|
||||
start_data,
|
||||
last_loc: pointer_loc,
|
||||
old_tree: None,
|
||||
accumulated_delta: 0.0,
|
||||
node,
|
||||
output,
|
||||
left_up_idx: idx,
|
||||
orientation,
|
||||
release,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PointerGrab<State> for ResizeForkGrab {
|
||||
|
|
@ -137,7 +161,7 @@ impl PointerGrab<State> for ResizeForkGrab {
|
|||
// While the grab is active, no client has pointer focus
|
||||
handle.motion(data, None, event);
|
||||
|
||||
let delta = event.location - self.last_loc;
|
||||
let delta = event.location - self.last_loc.as_logical();
|
||||
|
||||
if let Some(output) = self.output.upgrade() {
|
||||
let tiling_layer = &mut data.common.shell.active_space_mut(&output).tiling_layer;
|
||||
|
|
@ -234,7 +258,7 @@ impl PointerGrab<State> for ResizeForkGrab {
|
|||
_ => unreachable!(),
|
||||
}
|
||||
|
||||
self.last_loc = event.location;
|
||||
self.last_loc = event.location.as_global();
|
||||
let blocker = TilingLayout::update_positions(&output, tree, gaps);
|
||||
tiling_layer.pending_blockers.extend(blocker);
|
||||
} else {
|
||||
|
|
@ -261,9 +285,17 @@ impl PointerGrab<State> for ResizeForkGrab {
|
|||
event: &ButtonEvent,
|
||||
) {
|
||||
handle.button(data, event);
|
||||
if handle.current_pressed().is_empty() {
|
||||
// No more buttons are pressed, release the grab.
|
||||
handle.unset_grab(data, event.serial, event.time, true);
|
||||
match self.release {
|
||||
ReleaseMode::NoMouseButtons => {
|
||||
if handle.current_pressed().is_empty() {
|
||||
handle.unset_grab(data, event.serial, event.time, true);
|
||||
}
|
||||
}
|
||||
ReleaseMode::Click => {
|
||||
if event.state == ButtonState::Pressed {
|
||||
handle.unset_grab(data, event.serial, event.time, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue