From 58c33467dd97eea07ea65fbee1c438412cca6237 Mon Sep 17 00:00:00 2001 From: Ottatop Date: Fri, 21 Jun 2024 15:03:32 -0500 Subject: [PATCH] Change cursor on move and resize grab --- src/api/window.rs | 9 ++++++++- src/grab/move_grab.rs | 26 +++++++++++++++++++------- src/grab/resize_grab.rs | 39 ++++++++++++++++++++++++++++++++------- 3 files changed, 59 insertions(+), 15 deletions(-) diff --git a/src/api/window.rs b/src/api/window.rs index 352a4af2d..c0f1acd2a 100644 --- a/src/api/window.rs +++ b/src/api/window.rs @@ -489,7 +489,6 @@ impl window_service_server::WindowService for WindowService { return; }; let Some(window) = pointer_focus.window_for(state) else { - tracing::info!("Move grabs are currently not implemented for non-windows"); return; }; let Some(wl_surf) = window.wl_surface() else { @@ -498,6 +497,10 @@ impl window_service_server::WindowService for WindowService { let seat = state.pinnacle.seat.clone(); state.move_request_server(&wl_surf, &seat, SERIAL_COUNTER.next_serial(), button); + + if let Some(output) = state.pinnacle.focused_output().cloned() { + state.schedule_render(&output); + } }) .await } @@ -579,6 +582,10 @@ impl window_service_server::WindowService for WindowService { edges.into(), button, ); + + if let Some(output) = state.pinnacle.focused_output().cloned() { + state.schedule_render(&output); + } }) .await } diff --git a/src/grab/move_grab.rs b/src/grab/move_grab.rs index 95f3c1e8f..edb7bcc00 100644 --- a/src/grab/move_grab.rs +++ b/src/grab/move_grab.rs @@ -6,10 +6,11 @@ use smithay::{ // | input::keyboard input::{ pointer::{ - AxisFrame, ButtonEvent, Focus, GestureHoldBeginEvent, GestureHoldEndEvent, - GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent, - GestureSwipeBeginEvent, GestureSwipeEndEvent, GestureSwipeUpdateEvent, GrabStartData, - MotionEvent, PointerGrab, PointerInnerHandle, RelativeMotionEvent, + AxisFrame, ButtonEvent, CursorIcon, CursorImageStatus, Focus, GestureHoldBeginEvent, + GestureHoldEndEvent, GesturePinchBeginEvent, GesturePinchEndEvent, + GesturePinchUpdateEvent, GestureSwipeBeginEvent, GestureSwipeEndEvent, + GestureSwipeUpdateEvent, GrabStartData, MotionEvent, PointerGrab, PointerInnerHandle, + RelativeMotionEvent, }, Seat, SeatHandler, }, @@ -46,6 +47,10 @@ impl PointerGrab for MoveSurfaceGrab { handle.motion(state, None, event); if !self.window.alive() { + state + .pinnacle + .cursor_state + .set_cursor_image(CursorImageStatus::default_named()); handle.unset_grab(self, state, event.serial, event.time, true); return; } @@ -168,6 +173,9 @@ impl PointerGrab for MoveSurfaceGrab { handle.button(data, event); if !handle.current_pressed().contains(&self.start_data.button) { + data.pinnacle + .cursor_state + .set_cursor_image(CursorImageStatus::default_named()); handle.unset_grab(self, data, event.serial, event.time, true); } } @@ -311,9 +319,9 @@ impl State { .to_f64(); // TODO: add space f64 support or move away from space let start_data = smithay::input::pointer::GrabStartData { - focus: pointer - .current_focus() - .map(|focus| (focus, initial_window_loc)), + // If Some and same as the dragged window then the window is allowed to + // change the cursor, which we don't want, therefore this is None + focus: None, button: button_used, location: pointer.current_location(), }; @@ -325,5 +333,9 @@ impl State { }; pointer.set_grab(self, grab, serial, Focus::Clear); + + self.pinnacle + .cursor_state + .set_cursor_image(CursorImageStatus::Named(CursorIcon::Grabbing)); } } diff --git a/src/grab/resize_grab.rs b/src/grab/resize_grab.rs index 80adb829a..086702fab 100644 --- a/src/grab/resize_grab.rs +++ b/src/grab/resize_grab.rs @@ -4,10 +4,10 @@ use smithay::{ desktop::{space::SpaceElement, WindowSurface}, input::{ pointer::{ - AxisFrame, ButtonEvent, Focus, GestureHoldBeginEvent, GestureHoldEndEvent, - GesturePinchBeginEvent, GesturePinchEndEvent, GesturePinchUpdateEvent, - GestureSwipeBeginEvent, GestureSwipeEndEvent, GestureSwipeUpdateEvent, GrabStartData, - PointerGrab, PointerInnerHandle, + AxisFrame, ButtonEvent, CursorIcon, CursorImageStatus, Focus, GestureHoldBeginEvent, + GestureHoldEndEvent, GesturePinchBeginEvent, GesturePinchEndEvent, + GesturePinchUpdateEvent, GestureSwipeBeginEvent, GestureSwipeEndEvent, + GestureSwipeUpdateEvent, GrabStartData, PointerGrab, PointerInnerHandle, }, Seat, SeatHandler, }, @@ -49,6 +49,23 @@ impl From for ResizeEdge { } } +impl ResizeEdge { + fn cursor_icon(&self) -> CursorIcon { + match self.0 { + xdg_toplevel::ResizeEdge::None => CursorIcon::Default, // TODO: possibly different icon here? + xdg_toplevel::ResizeEdge::Top => CursorIcon::NResize, + xdg_toplevel::ResizeEdge::Bottom => CursorIcon::SResize, + xdg_toplevel::ResizeEdge::Left => CursorIcon::WResize, + xdg_toplevel::ResizeEdge::TopLeft => CursorIcon::NwResize, + xdg_toplevel::ResizeEdge::BottomLeft => CursorIcon::SwResize, + xdg_toplevel::ResizeEdge::Right => CursorIcon::EResize, + xdg_toplevel::ResizeEdge::TopRight => CursorIcon::NeResize, + xdg_toplevel::ResizeEdge::BottomRight => CursorIcon::SeResize, + _ => CursorIcon::Default, + } + } +} + pub struct ResizeSurfaceGrab { start_data: GrabStartData, window: WindowElement, @@ -146,6 +163,9 @@ impl PointerGrab for ResizeSurfaceGrab { handle.motion(data, None, event); if !self.window.alive() { + data.pinnacle + .cursor_state + .set_cursor_image(CursorImageStatus::default_named()); handle.unset_grab(self, data, event.serial, event.time, true); return; } @@ -242,6 +262,9 @@ impl PointerGrab for ResizeSurfaceGrab { handle.button(data, event); if !handle.current_pressed().contains(&self.button_used) { + data.pinnacle + .cursor_state + .set_cursor_image(CursorImageStatus::default_named()); handle.unset_grab(self, data, event.serial, event.time, true); } } @@ -558,9 +581,7 @@ impl State { } let start_data = smithay::input::pointer::GrabStartData { - focus: pointer - .current_focus() - .map(|focus| (focus, initial_window_loc)), + focus: None, button: button_used, location: pointer.current_location(), }; @@ -576,6 +597,10 @@ impl State { if let Some(grab) = grab { pointer.set_grab(self, grab, serial, Focus::Clear); + + self.pinnacle + .cursor_state + .set_cursor_image(CursorImageStatus::Named(edges.cursor_icon())); } } }