Skip to content

Commit

Permalink
Change cursor on move and resize grab
Browse files Browse the repository at this point in the history
  • Loading branch information
Ottatop committed Jun 21, 2024
1 parent 85fb1be commit 58c3346
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 15 deletions.
9 changes: 8 additions & 1 deletion src/api/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
26 changes: 19 additions & 7 deletions src/grab/move_grab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -46,6 +47,10 @@ impl PointerGrab<State> 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;
}
Expand Down Expand Up @@ -168,6 +173,9 @@ impl PointerGrab<State> 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);
}
}
Expand Down Expand Up @@ -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(),
};
Expand All @@ -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));
}
}
39 changes: 32 additions & 7 deletions src/grab/resize_grab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -49,6 +49,23 @@ impl From<xdg_toplevel::ResizeEdge> 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<State>,
window: WindowElement,
Expand Down Expand Up @@ -146,6 +163,9 @@ impl PointerGrab<State> 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;
}
Expand Down Expand Up @@ -242,6 +262,9 @@ impl PointerGrab<State> 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);
}
}
Expand Down Expand Up @@ -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(),
};
Expand All @@ -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()));
}
}
}

0 comments on commit 58c3346

Please sign in to comment.