From 5906717dc8e120bb0c5477f4d05d212349b0ff30 Mon Sep 17 00:00:00 2001 From: Daniel <101683475+Koranir@users.noreply.github.com> Date: Wed, 8 Jan 2025 18:24:25 +1100 Subject: [PATCH 1/4] implement context menu grab on inputs --- src/input/mod.rs | 189 +++++++++++++++++++------- src/shell/element/stack.rs | 2 + src/shell/element/window.rs | 1 + src/shell/grabs/menu/mod.rs | 5 +- src/shell/mod.rs | 3 +- src/wayland/handlers/xdg_shell/mod.rs | 1 + 6 files changed, 148 insertions(+), 53 deletions(-) diff --git a/src/input/mod.rs b/src/input/mod.rs index 813937bd..f7af2d82 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -31,7 +31,7 @@ use crate::{ }; use calloop::{ timer::{TimeoutAction, Timer}, - RegistrationToken, + LoopHandle, RegistrationToken, }; use cosmic_comp_config::workspace::WorkspaceLayout; use cosmic_settings_config::shortcuts; @@ -58,7 +58,8 @@ use smithay::{ }, output::Output, reexports::{ - input::Device as InputDevice, wayland_server::protocol::wl_shm::Format as ShmFormat, + input::Device as InputDevice, + wayland_server::protocol::{wl_shm::Format as ShmFormat, wl_surface::WlSurface}, }, utils::{Point, Rectangle, Serial, SERIAL_COUNTER}, wayland::{ @@ -677,6 +678,66 @@ impl State { } } + fn window_menu( + seat: Seat, + evlh: &LoopHandle, + surface: WlSurface, + serial: Serial, + ) { + evlh.insert_idle(move |state| { + let shell = state.common.shell.write().unwrap(); + + let grab = if let Some(mapped) = + shell.element_for_surface(&surface).cloned() + { + let position = if let Some((output, set)) = + shell.workspaces.sets.iter().find(|(_, set)| { + set.sticky_layer + .mapped() + .any(|m| m == &mapped) + }) { + set.sticky_layer + .element_geometry(&mapped) + .unwrap() + .loc + .to_global(output) + } else if let Some(workspace) = + shell.space_for(&mapped) + { + let Some(elem_geo) = + workspace.element_geometry(&mapped) + else { + return; + }; + elem_geo.loc.to_global(&workspace.output) + } else { + return; + }; + let cursor = seat + .get_pointer() + .unwrap() + .current_location() + .to_i32_round(); + + shell.menu_request( + &surface, + &seat, + serial, + cursor - position.as_logical(), + false, + &state.common.config, + &state.common.event_loop_handle, + false, + ) + } else { + None + }; + drop(shell); + + dispatch_grab(grab, seat, serial, state); + }); + } + if let Some(mouse_button) = mouse_button { match mouse_button { smithay::backend::input::MouseButton::Left => { @@ -703,56 +764,84 @@ impl State { }, ); } - smithay::backend::input::MouseButton::Right => { + smithay::backend::input::MouseButton::Middle => { supress_button(); - self.common.event_loop_handle.insert_idle( - move |state| { - let mut shell = - state.common.shell.write().unwrap(); - let Some(target_elem) = - shell.element_for_surface(&surface) - else { - return; - }; - let Some(geom) = - shell.space_for(target_elem).and_then( - |f| f.element_geometry(target_elem), - ) - else { - return; - }; - let geom = geom.to_f64(); - let center = - geom.loc + geom.size.downscale(2.0); - let offset = center.to_global(&output) - - global_position; - let edge = match ( - offset.x > 0.0, - offset.y > 0.0, - ) { - (true, true) => ResizeEdge::TOP_LEFT, - (false, true) => ResizeEdge::TOP_RIGHT, - (true, false) => { - ResizeEdge::BOTTOM_LEFT - } - (false, false) => { - ResizeEdge::BOTTOM_RIGHT - } - }; - let res = shell.resize_request( - &surface, - &seat_clone, - serial, - edge, - false, - ); - drop(shell); - dispatch_grab( - res, seat_clone, serial, state, - ); - }, + window_menu( + seat_clone, + &self.common.event_loop_handle, + surface, + serial, ); } + smithay::backend::input::MouseButton::Right => { + supress_button(); + if seat + .get_keyboard() + .unwrap() + .modifier_state() + .shift + { + window_menu( + seat_clone, + &self.common.event_loop_handle, + surface, + serial, + ); + } else { + self.common.event_loop_handle.insert_idle( + move |state| { + let mut shell = + state.common.shell.write().unwrap(); + let Some(target_elem) = + shell.element_for_surface(&surface) + else { + return; + }; + let Some(geom) = shell + .space_for(target_elem) + .and_then(|f| { + f.element_geometry(target_elem) + }) + else { + return; + }; + let geom = geom.to_f64(); + let center = + geom.loc + geom.size.downscale(2.0); + let offset = center.to_global(&output) + - global_position; + let edge = match ( + offset.x > 0.0, + offset.y > 0.0, + ) { + (true, true) => { + ResizeEdge::TOP_LEFT + } + (false, true) => { + ResizeEdge::TOP_RIGHT + } + (true, false) => { + ResizeEdge::BOTTOM_LEFT + } + (false, false) => { + ResizeEdge::BOTTOM_RIGHT + } + }; + let res = shell.resize_request( + &surface, + &seat_clone, + serial, + edge, + false, + ); + drop(shell); + dispatch_grab( + res, seat_clone, serial, state, + ); + }, + ); + } + } _ => {} } } @@ -786,8 +875,6 @@ impl State { }, ); ptr.frame(self); - } else if event.state() == ButtonState::Released { - ptr.unset_grab(self, serial, event.time_msec()) } } InputEvent::PointerAxis { event, .. } => { diff --git a/src/shell/element/stack.rs b/src/shell/element/stack.rs index e14b8a58..a8349f85 100644 --- a/src/shell/element/stack.rs +++ b/src/shell/element/stack.rs @@ -872,6 +872,7 @@ impl Program for CosmicStackInternal { true, &state.common.config, &state.common.event_loop_handle, + true, ); std::mem::drop(shell); @@ -914,6 +915,7 @@ impl Program for CosmicStackInternal { false, &state.common.config, &state.common.event_loop_handle, + true, ); std::mem::drop(shell); diff --git a/src/shell/element/window.rs b/src/shell/element/window.rs index 57b52578..d368779d 100644 --- a/src/shell/element/window.rs +++ b/src/shell/element/window.rs @@ -515,6 +515,7 @@ impl Program for CosmicWindowInternal { false, &state.common.config, &state.common.event_loop_handle, + true, ); std::mem::drop(shell); diff --git a/src/shell/grabs/menu/mod.rs b/src/shell/grabs/menu/mod.rs index c1ca0c2b..8e7187fb 100644 --- a/src/shell/grabs/menu/mod.rs +++ b/src/shell/grabs/menu/mod.rs @@ -161,7 +161,10 @@ impl Item { } } -/// Menu that comes up when right-clicking an application header bar +/// Menu that comes up when: +/// - Right-clicking an application header bar +/// - Super + Middle-clicking a window +/// - Super + Shift + Right-clicking a window pub struct ContextMenu { items: Vec, selected: AtomicBool, diff --git a/src/shell/mod.rs b/src/shell/mod.rs index c9f17634..f19e12d7 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -2564,10 +2564,11 @@ impl Shell { target_stack: bool, config: &Config, evlh: &LoopHandle<'static, State>, + client_initiated: bool, ) -> Option<(MenuGrab, Focus)> { let serial = serial.into(); let Some(GrabStartData::Pointer(start_data)) = - check_grab_preconditions(&seat, surface, serial, true) + check_grab_preconditions(&seat, surface, serial, client_initiated) else { return None; }; diff --git a/src/wayland/handlers/xdg_shell/mod.rs b/src/wayland/handlers/xdg_shell/mod.rs index 7f19913c..23cd4c10 100644 --- a/src/wayland/handlers/xdg_shell/mod.rs +++ b/src/wayland/handlers/xdg_shell/mod.rs @@ -439,6 +439,7 @@ impl XdgShellHandler for State { false, &self.common.config, &self.common.event_loop_handle, + true, ); if let Some((grab, focus)) = res { std::mem::drop(shell); From 05880c66f800c0b510a3db2d7e82162145f8652c Mon Sep 17 00:00:00 2001 From: Daniel <101683475+Koranir@users.noreply.github.com> Date: Wed, 8 Jan 2025 19:02:56 +1100 Subject: [PATCH 2/4] Handle ungrabbing correctly --- src/input/mod.rs | 24 ++++++++++++++++++++++-- src/shell/grabs/mod.rs | 18 ++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/input/mod.rs b/src/input/mod.rs index f7af2d82..f27fca36 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -16,7 +16,7 @@ use crate::{ target::{KeyboardFocusTarget, PointerFocusTarget}, Stage, }, - grabs::{ReleaseMode, ResizeEdge}, + grabs::{ReleaseMode, ResizeEdge, UngrabOnPointerUp}, layout::{ floating::ResizeGrabMarker, tiling::{NodeDesc, TilingLayout}, @@ -75,7 +75,7 @@ use xkbcommon::xkb::{Keycode, Keysym}; use std::{ any::Any, borrow::Cow, - cell::RefCell, + cell::{Cell, RefCell}, collections::HashSet, ops::ControlFlow, time::{Duration, Instant}, @@ -757,7 +757,13 @@ impl State { &state.common.xdg_activation_state, false, ); + drop(shell); + + seat_clone + .user_data() + .get_or_insert(UngrabOnPointerUp::new) + .set(true); dispatch_grab( res, seat_clone, serial, state, ); @@ -835,6 +841,13 @@ impl State { false, ); drop(shell); + + seat_clone + .user_data() + .get_or_insert( + UngrabOnPointerUp::new, + ) + .set(true); dispatch_grab( res, seat_clone, serial, state, ); @@ -875,6 +888,13 @@ impl State { }, ); ptr.frame(self); + } else if event.state() == ButtonState::Released { + if let Some(ungrab) = seat.user_data().get::() { + if ungrab.get() { + ungrab.set(false); + ptr.unset_grab(self, serial, event.time_msec()) + } + } } } InputEvent::PointerAxis { event, .. } => { diff --git a/src/shell/grabs/mod.rs b/src/shell/grabs/mod.rs index def21cfe..cafaeff2 100644 --- a/src/shell/grabs/mod.rs +++ b/src/shell/grabs/mod.rs @@ -1,3 +1,5 @@ +use std::cell::Cell; + use cosmic_settings_config::shortcuts; use smithay::{ input::{ @@ -67,6 +69,22 @@ pub enum ReleaseMode { NoMouseButtons, } +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct UngrabOnPointerUp(Cell); +impl UngrabOnPointerUp { + pub fn new() -> Self { + Self(Cell::new(false)) + } + + pub fn get(&self) -> bool { + self.0.get() + } + + pub fn set(&self, ungrab: bool) { + self.0.set(ungrab); + } +} + mod menu; pub use self::menu::*; mod moving; From ce222e29d5374c22a0f3f0acfd63c4971bcbc816 Mon Sep 17 00:00:00 2001 From: Daniel <101683475+Koranir@users.noreply.github.com> Date: Wed, 8 Jan 2025 19:03:58 +1100 Subject: [PATCH 3/4] remove unused import --- src/input/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/input/mod.rs b/src/input/mod.rs index f27fca36..4e700b0a 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -75,7 +75,7 @@ use xkbcommon::xkb::{Keycode, Keysym}; use std::{ any::Any, borrow::Cow, - cell::{Cell, RefCell}, + cell::RefCell, collections::HashSet, ops::ControlFlow, time::{Duration, Instant}, From 532f477edc85d439cdbcbe9184282b010af046b6 Mon Sep 17 00:00:00 2001 From: Daniel <101683475+Koranir@users.noreply.github.com> Date: Thu, 16 Jan 2025 16:49:15 +1100 Subject: [PATCH 4/4] Just use Meta + Right-Click --- cosmic-comp-config/src/lib.rs | 3 + src/input/mod.rs | 299 +++++++++++++++++++--------------- src/shell/grabs/mod.rs | 154 +++++++++++++++++ src/shell/mod.rs | 27 ++- 4 files changed, 349 insertions(+), 134 deletions(-) diff --git a/cosmic-comp-config/src/lib.rs b/cosmic-comp-config/src/lib.rs index 5a656e52..8a051d77 100644 --- a/cosmic-comp-config/src/lib.rs +++ b/cosmic-comp-config/src/lib.rs @@ -31,6 +31,8 @@ pub struct CosmicCompConfig { pub focus_follows_cursor_delay: u64, /// Let X11 applications scale themselves pub descale_xwayland: bool, + /// How far the pointer can travel before it's considered as moved + pub pointer_moved_epsilon: u32, } impl Default for CosmicCompConfig { @@ -60,6 +62,7 @@ impl Default for CosmicCompConfig { cursor_follows_focus: false, focus_follows_cursor_delay: 250, descale_xwayland: false, + pointer_moved_epsilon: 10, } } } diff --git a/src/input/mod.rs b/src/input/mod.rs index 4e700b0a..0f6994fa 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -16,7 +16,7 @@ use crate::{ target::{KeyboardFocusTarget, PointerFocusTarget}, Stage, }, - grabs::{ReleaseMode, ResizeEdge, UngrabOnPointerUp}, + grabs::{MenuGrab, ReleaseMode, ResizeEdge, UngrabOnPointerUp}, layout::{ floating::ResizeGrabMarker, tiling::{NodeDesc, TilingLayout}, @@ -31,7 +31,7 @@ use crate::{ }; use calloop::{ timer::{TimeoutAction, Timer}, - LoopHandle, RegistrationToken, + RegistrationToken, }; use cosmic_comp_config::workspace::WorkspaceLayout; use cosmic_settings_config::shortcuts; @@ -678,64 +678,56 @@ impl State { } } - fn window_menu( - seat: Seat, - evlh: &LoopHandle, + fn window_menu_grab( + state: &mut State, + seat: &Seat, surface: WlSurface, serial: Serial, - ) { - evlh.insert_idle(move |state| { - let shell = state.common.shell.write().unwrap(); - - let grab = if let Some(mapped) = - shell.element_for_surface(&surface).cloned() + ) -> Option<(MenuGrab, smithay::input::pointer::Focus)> + { + let shell = state.common.shell.write().unwrap(); + if let Some(mapped) = + shell.element_for_surface(&surface).cloned() + { + let position = if let Some((output, set)) = + shell.workspaces.sets.iter().find(|(_, set)| { + set.sticky_layer.mapped().any(|m| m == &mapped) + }) { + set.sticky_layer + .element_geometry(&mapped) + .unwrap() + .loc + .to_global(output) + } else if let Some(workspace) = shell.space_for(&mapped) { - let position = if let Some((output, set)) = - shell.workspaces.sets.iter().find(|(_, set)| { - set.sticky_layer - .mapped() - .any(|m| m == &mapped) - }) { - set.sticky_layer - .element_geometry(&mapped) - .unwrap() - .loc - .to_global(output) - } else if let Some(workspace) = - shell.space_for(&mapped) - { - let Some(elem_geo) = - workspace.element_geometry(&mapped) - else { - return; - }; - elem_geo.loc.to_global(&workspace.output) - } else { - return; + let Some(elem_geo) = + workspace.element_geometry(&mapped) + else { + return None; }; - let cursor = seat - .get_pointer() - .unwrap() - .current_location() - .to_i32_round(); - - shell.menu_request( - &surface, - &seat, - serial, - cursor - position.as_logical(), - false, - &state.common.config, - &state.common.event_loop_handle, - false, - ) + elem_geo.loc.to_global(&workspace.output) } else { - None + return None; }; - drop(shell); - - dispatch_grab(grab, seat, serial, state); - }); + let cursor = seat + .get_pointer() + .unwrap() + .current_location() + .to_i32_round(); + + shell.menu_request( + &surface, + &seat, + serial, + cursor - position.as_logical(), + false, + &state.common.config, + &state.common.event_loop_handle, + false, + ) + } else { + None + } } if let Some(mouse_button) = mouse_button { @@ -770,90 +762,131 @@ impl State { }, ); } - smithay::backend::input::MouseButton::Middle => { - supress_button(); - window_menu( - seat_clone, - &self.common.event_loop_handle, - surface, - serial, - ); - } smithay::backend::input::MouseButton::Right => { supress_button(); - if seat - .get_keyboard() - .unwrap() - .modifier_state() - .shift - { - window_menu( + + let time = event.time_msec(); + self.common.event_loop_handle.insert_idle(move |state| { + let surface_clone = surface.clone(); + let surface_clone2 = surface.clone(); + let seat_clone2 = seat_clone.clone(); + let seat_clone3 = seat_clone.clone(); + + let mut shell = state.common.shell.write().unwrap(); + let res = shell + .distance_switch_request( + &surface_clone, + &seat_clone, + serial, + &state.common.config, + move |state| { + state.common.event_loop_handle.insert_idle(move |state| { + let mut shell = state + .common + .shell + .write() + .unwrap(); + + let Some(target_elem) = + shell.element_for_surface(&surface) + else { + return; + }; + let Some(geom) = shell + .space_for(target_elem) + .and_then(|f| { + f.element_geometry( + target_elem, + ) + }) + else { + return; + }; + let geom = geom.to_f64(); + let center = geom.loc + + geom + .size + .downscale(2.0); + let offset = center + .to_global(&output) + - global_position; + let edge = match ( + offset.x > 0.0, + offset.y > 0.0, + ) { + (true, true) => { + ResizeEdge::TOP_LEFT + } + (false, true) => { + ResizeEdge::TOP_RIGHT + } + (true, false) => { + ResizeEdge::BOTTOM_LEFT + } + (false, false) => { + ResizeEdge::BOTTOM_RIGHT + } + }; + let res = shell + .resize_request( + &surface, + &seat_clone2, + serial, + edge, + false, + ); + drop(shell); + + seat_clone2 + .user_data() + .get_or_insert( + UngrabOnPointerUp::new, + ) + .set(true); + + dispatch_grab(res, seat_clone2, serial, state); + }); + }, + move |state| { + state.common.event_loop_handle.insert_idle(move |state| { + let grab = window_menu_grab( + state, + &seat_clone3, + surface_clone2, + serial, + ); + dispatch_grab(grab, seat_clone3.clone(), serial, state); + + let ptr = seat_clone3.get_pointer().unwrap(); + ptr.motion( + state, + ptr.current_focus().map(|f| + (f, ptr.current_location()) + ), + &MotionEvent { + location: ptr.current_location(), + serial, + time + } + ); + }); + }, + false, + ); + + drop(shell); + + seat_clone + .user_data() + .get_or_insert(UngrabOnPointerUp::new) + .set(true); + dispatch_grab( + res, seat_clone, - &self.common.event_loop_handle, - surface, serial, + state, ); - } else { - self.common.event_loop_handle.insert_idle( - move |state| { - let mut shell = - state.common.shell.write().unwrap(); - let Some(target_elem) = - shell.element_for_surface(&surface) - else { - return; - }; - let Some(geom) = shell - .space_for(target_elem) - .and_then(|f| { - f.element_geometry(target_elem) - }) - else { - return; - }; - let geom = geom.to_f64(); - let center = - geom.loc + geom.size.downscale(2.0); - let offset = center.to_global(&output) - - global_position; - let edge = match ( - offset.x > 0.0, - offset.y > 0.0, - ) { - (true, true) => { - ResizeEdge::TOP_LEFT - } - (false, true) => { - ResizeEdge::TOP_RIGHT - } - (true, false) => { - ResizeEdge::BOTTOM_LEFT - } - (false, false) => { - ResizeEdge::BOTTOM_RIGHT - } - }; - let res = shell.resize_request( - &surface, - &seat_clone, - serial, - edge, - false, - ); - drop(shell); - - seat_clone - .user_data() - .get_or_insert( - UngrabOnPointerUp::new, - ) - .set(true); - dispatch_grab( - res, seat_clone, serial, state, - ); - }, - ); - } + }); } _ => {} } diff --git a/src/shell/grabs/mod.rs b/src/shell/grabs/mod.rs index cafaeff2..fb409ab0 100644 --- a/src/shell/grabs/mod.rs +++ b/src/shell/grabs/mod.rs @@ -69,6 +69,160 @@ pub enum ReleaseMode { NoMouseButtons, } +#[derive(Debug, Clone)] +pub struct DistanceSwitchGrab { + pub moved: Option, + pub unmoved: Option, + pub start: GrabStartData, + pub pointer_moved_epsilon: u32, +} +impl + PointerGrab for DistanceSwitchGrab +{ + fn motion( + &mut self, + data: &mut State, + handle: &mut PointerInnerHandle<'_, State>, + focus: Option<(PointerFocusTarget, Point)>, + event: &MotionEvent, + ) { + let start = self.start.location(); + let current = event.location; + + let x = start.x - current.x; + let y = start.y - current.y; + + let distance = ((x * x) + (y * y)).sqrt(); + if distance > self.pointer_moved_epsilon as f64 { + drop(data.common.shell.try_write().unwrap()); + self.moved.take().unwrap()(data); + } else { + handle.motion(data, focus, event) + } + } + + fn relative_motion( + &mut self, + data: &mut State, + handle: &mut PointerInnerHandle<'_, State>, + focus: Option<( + ::PointerFocus, + Point, + )>, + event: &RelativeMotionEvent, + ) { + handle.relative_motion(data, focus, event) + } + + fn button( + &mut self, + data: &mut State, + handle: &mut PointerInnerHandle<'_, State>, + event: &ButtonEvent, + ) { + handle.button(data, event) + } + + fn axis( + &mut self, + data: &mut State, + handle: &mut PointerInnerHandle<'_, State>, + details: AxisFrame, + ) { + handle.axis(data, details) + } + + fn frame(&mut self, data: &mut State, handle: &mut PointerInnerHandle<'_, State>) { + handle.frame(data) + } + + fn gesture_swipe_begin( + &mut self, + data: &mut State, + handle: &mut PointerInnerHandle<'_, State>, + event: &GestureSwipeBeginEvent, + ) { + handle.gesture_swipe_begin(data, event) + } + + fn gesture_swipe_update( + &mut self, + data: &mut State, + handle: &mut PointerInnerHandle<'_, State>, + event: &GestureSwipeUpdateEvent, + ) { + handle.gesture_swipe_update(data, event) + } + + fn gesture_swipe_end( + &mut self, + data: &mut State, + handle: &mut PointerInnerHandle<'_, State>, + event: &GestureSwipeEndEvent, + ) { + handle.gesture_swipe_end(data, event) + } + + fn gesture_pinch_begin( + &mut self, + data: &mut State, + handle: &mut PointerInnerHandle<'_, State>, + event: &GesturePinchBeginEvent, + ) { + handle.gesture_pinch_begin(data, event) + } + + fn gesture_pinch_update( + &mut self, + data: &mut State, + handle: &mut PointerInnerHandle<'_, State>, + event: &GesturePinchUpdateEvent, + ) { + handle.gesture_pinch_update(data, event) + } + + fn gesture_pinch_end( + &mut self, + data: &mut State, + handle: &mut PointerInnerHandle<'_, State>, + event: &GesturePinchEndEvent, + ) { + handle.gesture_pinch_end(data, event) + } + + fn gesture_hold_begin( + &mut self, + data: &mut State, + handle: &mut PointerInnerHandle<'_, State>, + event: &GestureHoldBeginEvent, + ) { + handle.gesture_hold_begin(data, event) + } + + fn gesture_hold_end( + &mut self, + data: &mut State, + handle: &mut PointerInnerHandle<'_, State>, + event: &GestureHoldEndEvent, + ) { + handle.gesture_hold_end(data, event) + } + + fn start_data(&self) -> &PointerGrabStartData { + match &self.start { + GrabStartData::Touch(_) => unreachable!(), + GrabStartData::Pointer(p) => p, + } + } + + fn unset(&mut self, data: &mut State) { + if self.moved.is_some() { + self.unmoved.take().unwrap()(data); + } + _ = data; + } +} + #[derive(Debug, Clone, PartialEq, Eq)] pub struct UngrabOnPointerUp(Cell); impl UngrabOnPointerUp { diff --git a/src/shell/mod.rs b/src/shell/mod.rs index f19e12d7..dd9c1193 100644 --- a/src/shell/mod.rs +++ b/src/shell/mod.rs @@ -1,6 +1,6 @@ use calloop::LoopHandle; use focus::target::WindowGroup; -use grabs::SeatMoveGrabState; +use grabs::{DistanceSwitchGrab, SeatMoveGrabState}; use indexmap::IndexMap; use layout::TilingExceptions; use std::{ @@ -2662,6 +2662,31 @@ impl Shell { Some((grab, Focus::Keep)) } + pub fn distance_switch_request( + &mut self, + surface: &WlSurface, + seat: &Seat, + serial: impl Into>, + config: &Config, + on_moved: Moved, + on_unmoved: Unmoved, + client_initiated: bool, + ) -> Option<(DistanceSwitchGrab, Focus)> { + let serial = serial.into(); + + let start_data = check_grab_preconditions(&seat, surface, serial, client_initiated)?; + + Some(( + DistanceSwitchGrab { + moved: Some(on_moved), + unmoved: Some(on_unmoved), + start: start_data, + pointer_moved_epsilon: config.cosmic_conf.pointer_moved_epsilon, + }, + Focus::Keep, + )) + } + pub fn move_request( &mut self, surface: &WlSurface,