forge
Explore
Log in

Don't you dare go Hollow

screenshot_ui: Move selection with a second touch too

Browse files at this commit

97dfd2b1a00bcb9b765a8fa92ce39d2e0c79abc2Ivan MolodetskikhParent: 730eab0
src/ui/screenshot_ui.rsmodified+56 -10
@@ -66,14 +66,22 @@ pub enum ScreenshotUi {
6666 },
6767 }
6868
69+/// State for moving the selection (as opposed to just drawing).
70+pub struct MoveState {
71+ // Cursor offset from selection.1 when starting the move.
72+ pointer_offset: Point<i32, Physical>,
73+ // If the move is initiated by a touch, this is the slot. If `None`, the move was initiated by
74+ // holding Space.
75+ touch_slot: Option<TouchSlot>,
76+}
77+
6978 pub enum Button {
7079 Up,
7180 Down {
7281 touch_slot: Option<TouchSlot>,
7382 on_capture_button: bool,
7483 last_pos: (Output, Point<i32, Physical>),
75- /// Offset from the selection.1 corner to cursor grab point when moving the selection.
76- move_cursor_offset: Option<Point<i32, Physical>>,
84+ move_state: Option<MoveState>,
7785 },
7886 }
7987
@@ -274,7 +282,7 @@ impl ScreenshotUi {
274282 selection,
275283 button:
276284 Button::Down {
277- move_cursor_offset,
285+ move_state,
278286 last_pos,
279287 ..
280288 },
@@ -282,9 +290,20 @@ impl ScreenshotUi {
282290 } = self
283291 {
284292 if down {
285- *move_cursor_offset = Some(last_pos.1 - selection.1);
293+ if move_state.is_none() {
294+ *move_state = Some(MoveState {
295+ pointer_offset: last_pos.1 - selection.1,
296+ touch_slot: None,
297+ });
298+ }
286299 } else {
287- *move_cursor_offset = None;
300+ // Only clear if moving with Space.
301+ if let Some(MoveState {
302+ touch_slot: None, ..
303+ }) = move_state
304+ {
305+ *move_state = None;
306+ }
288307 }
289308 }
290309 }
@@ -790,7 +809,7 @@ impl ScreenshotUi {
790809 touch_slot,
791810 on_capture_button,
792811 last_pos,
793- move_cursor_offset,
812+ move_state,
794813 },
795814 ..
796815 } = self
@@ -808,9 +827,9 @@ impl ScreenshotUi {
808827 return;
809828 }
810829
811- if let Some(cursor_offset) = move_cursor_offset {
830+ if let Some(move_state) = move_state {
812831 // The cursor offset is relative to selection.1.
813- let delta = point - (selection.1 + *cursor_offset);
832+ let delta = point - (selection.1 + move_state.pointer_offset);
814833
815834 let desired = rect_from_corner_points(selection.1 + delta, selection.2 + delta);
816835 let bounds = Rectangle::from_size(output_data[&selection.0].size - desired.size);
@@ -843,6 +862,24 @@ impl ScreenshotUi {
843862 return false;
844863 };
845864
865+ // Check if this is a second touch (different slot) while already dragging.
866+ if let Some(new_slot) = slot {
867+ if let Button::Down {
868+ on_capture_button: false,
869+ move_state,
870+ last_pos,
871+ ..
872+ } = button
873+ {
874+ if move_state.is_none() {
875+ *move_state = Some(MoveState {
876+ pointer_offset: last_pos.1 - selection.1,
877+ touch_slot: Some(new_slot),
878+ });
879+ }
880+ }
881+ }
882+
846883 if button.is_down() {
847884 return false;
848885 }
@@ -861,7 +898,7 @@ impl ScreenshotUi {
861898 touch_slot: slot,
862899 on_capture_button: true,
863900 last_pos: (output, point),
864- move_cursor_offset: None,
901+ move_state: None,
865902 };
866903 return false;
867904 }
@@ -871,7 +908,7 @@ impl ScreenshotUi {
871908 touch_slot: slot,
872909 on_capture_button: false,
873910 last_pos: (output.clone(), point),
874- move_cursor_offset: None,
911+ move_state: None,
875912 };
876913 *selection = (output, point, point);
877914
@@ -896,12 +933,21 @@ impl ScreenshotUi {
896933 touch_slot,
897934 on_capture_button,
898935 ref last_pos,
936+ ref mut move_state,
899937 ..
900938 } = *button
901939 else {
902940 return None;
903941 };
904942
943+ // Check if this is a move touch and if so, stop the move.
944+ if let Some(state) = move_state {
945+ if state.touch_slot.is_some_and(|m_slot| Some(m_slot) == slot) {
946+ *move_state = None;
947+ return None;
948+ }
949+ };
950+
905951 if touch_slot != slot {
906952 return None;
907953 }