Use Grabbing cursor for Mod+LMB interactive move (#3045)
Browse files at this commit3 changed files +24 -5
- src/handlers/xdg_shell.rs +2 -2
- src/input/mod.rs +17 -2
- src/input/move_grab.rs +5 -1
src/handlers/xdg_shell.rsmodified+2 -2
| @@ -134,13 +134,13 @@ impl XdgShellHandler for State { | |||
| 134 | 134 | ||
| 135 | match &start_data { | 135 | match &start_data { |
| 136 | PointerOrTouchStartData::Pointer(_) => { | 136 | PointerOrTouchStartData::Pointer(_) => { |
| 137 | - if let Some(grab) = MoveGrab::new(self, start_data, window.clone(), true) { | 137 | + if let Some(grab) = MoveGrab::new(self, start_data, window.clone(), true, None) { |
| 138 | pointer.set_grab(self, grab, serial, Focus::Clear); | 138 | pointer.set_grab(self, grab, serial, Focus::Clear); |
| 139 | } | 139 | } |
| 140 | } | 140 | } |
| 141 | PointerOrTouchStartData::Touch(_) => { | 141 | PointerOrTouchStartData::Touch(_) => { |
| 142 | let touch = self.niri.seat.get_touch().unwrap(); | 142 | let touch = self.niri.seat.get_touch().unwrap(); |
| 143 | - if let Some(grab) = MoveGrab::new(self, start_data, window.clone(), true) { | 143 | + if let Some(grab) = MoveGrab::new(self, start_data, window.clone(), true, None) { |
| 144 | touch.set_grab(self, grab, serial); | 144 | touch.set_grab(self, grab, serial); |
| 145 | } | 145 | } |
| 146 | } | 146 | } |
src/input/mod.rsmodified+17 -2
| @@ -2857,8 +2857,22 @@ impl State { | |||
| 2857 | location, | 2857 | location, |
| 2858 | }; | 2858 | }; |
| 2859 | let start_data = PointerOrTouchStartData::Pointer(start_data); | 2859 | let start_data = PointerOrTouchStartData::Pointer(start_data); |
| 2860 | - if let Some(grab) = MoveGrab::new(self, start_data, window.clone(), false) { | 2860 | + let icon = CursorIcon::Grabbing; |
| 2861 | + if let Some(grab) = | ||
| 2862 | + MoveGrab::new(self, start_data, window.clone(), false, Some(icon)) | ||
| 2863 | + { | ||
| 2861 | pointer.set_grab(self, grab, serial, Focus::Clear); | 2864 | pointer.set_grab(self, grab, serial, Focus::Clear); |
| 2865 | + | ||
| 2866 | + // Set the cursor to Grabbing right away for Mod+LMB since it doesn't | ||
| 2867 | + // do any other gesture. | ||
| 2868 | + // | ||
| 2869 | + // In the overview, we click to activate window and close the overview, | ||
| 2870 | + // in this case setting the cursor right away would be distracting. | ||
| 2871 | + if !is_overview_open { | ||
| 2872 | + self.niri | ||
| 2873 | + .cursor_manager | ||
| 2874 | + .set_cursor_image(CursorImageStatus::Named(icon)); | ||
| 2875 | + } | ||
| 2862 | } | 2876 | } |
| 2863 | } | 2877 | } |
| 2864 | } | 2878 | } |
| @@ -4106,7 +4120,8 @@ impl State { | |||
| 4106 | location: pos, | 4120 | location: pos, |
| 4107 | }; | 4121 | }; |
| 4108 | let start_data = PointerOrTouchStartData::Touch(start_data); | 4122 | let start_data = PointerOrTouchStartData::Touch(start_data); |
| 4109 | - if let Some(grab) = MoveGrab::new(self, start_data, window.clone(), true) { | 4123 | + if let Some(grab) = MoveGrab::new(self, start_data, window.clone(), true, None) |
| 4124 | + { | ||
| 4110 | handle.set_grab(self, grab, serial); | 4125 | handle.set_grab(self, grab, serial); |
| 4111 | } | 4126 | } |
| 4112 | } | 4127 | } |
src/input/move_grab.rsmodified+5 -1
| @@ -27,6 +27,7 @@ pub struct MoveGrab { | |||
| 27 | window: Window, | 27 | window: Window, |
| 28 | gesture: GestureState, | 28 | gesture: GestureState, |
| 29 | enable_view_offset: bool, | 29 | enable_view_offset: bool, |
| 30 | + move_icon: CursorIcon, | ||
| 30 | } | 31 | } |
| 31 | 32 | ||
| 32 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 33 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| @@ -42,6 +43,7 @@ impl MoveGrab { | |||
| 42 | start_data: PointerOrTouchStartData<State>, | 43 | start_data: PointerOrTouchStartData<State>, |
| 43 | window: Window, | 44 | window: Window, |
| 44 | enable_view_offset: bool, | 45 | enable_view_offset: bool, |
| 46 | + move_icon: Option<CursorIcon>, | ||
| 45 | ) -> Option<Self> { | 47 | ) -> Option<Self> { |
| 46 | let (output, pos_within_output) = state.niri.output_under(start_data.location())?; | 48 | let (output, pos_within_output) = state.niri.output_under(start_data.location())?; |
| 47 | 49 | ||
| @@ -53,6 +55,8 @@ impl MoveGrab { | |||
| 53 | window, | 55 | window, |
| 54 | gesture: GestureState::Recognizing, | 56 | gesture: GestureState::Recognizing, |
| 55 | enable_view_offset, | 57 | enable_view_offset, |
| 58 | + // Moving windows by their titlebars uses the default cursor by default. | ||
| 59 | + move_icon: move_icon.unwrap_or(CursorIcon::Default), | ||
| 56 | }) | 60 | }) |
| 57 | } | 61 | } |
| 58 | 62 | ||
| @@ -112,7 +116,7 @@ impl MoveGrab { | |||
| 112 | if self.start_data.is_pointer() { | 116 | if self.start_data.is_pointer() { |
| 113 | data.niri | 117 | data.niri |
| 114 | .cursor_manager | 118 | .cursor_manager |
| 115 | - .set_cursor_image(CursorImageStatus::Named(CursorIcon::Move)); | 119 | + .set_cursor_image(CursorImageStatus::Named(self.move_icon)); |
| 116 | } | 120 | } |
| 117 | 121 | ||
| 118 | true | 122 | true |