Move existing screenshot selection when holding Mod
Browse files at this commitcb3a06cd54ea3e1db122f612daaba594ed5a3d1cParent: f115f2e2 changed files +69 -19
- src/input/mod.rs +44 -11
- src/ui/screenshot_ui.rs +25 -8
src/input/mod.rsmodified+44 -11
| @@ -3028,14 +3028,25 @@ impl State { | |||
| 3028 | if button == Some(MouseButton::Left) && self.niri.screenshot_ui.is_open() { | 3028 | if button == Some(MouseButton::Left) && self.niri.screenshot_ui.is_open() { |
| 3029 | if button_state == ButtonState::Pressed { | 3029 | if button_state == ButtonState::Pressed { |
| 3030 | let pos = pointer.current_location(); | 3030 | let pos = pointer.current_location(); |
| 3031 | - if let Some((output, _)) = self.niri.output_under(pos) { | 3031 | + |
| 3032 | - let output = output.clone(); | 3032 | + // If we'll be moving the existing selection, use the selection output. |
| 3033 | + let output = if mod_down { | ||
| 3034 | + self.niri.screenshot_ui.selection_output() | ||
| 3035 | + } else { | ||
| 3036 | + self.niri.output_under(pos).map(|(out, _)| out) | ||
| 3037 | + }; | ||
| 3038 | + | ||
| 3039 | + if let Some(output) = output.cloned() { | ||
| 3033 | let geom = self.niri.global_space.output_geometry(&output).unwrap(); | 3040 | let geom = self.niri.global_space.output_geometry(&output).unwrap(); |
| 3034 | let point = (pos - geom.loc.to_f64()) | 3041 | let point = (pos - geom.loc.to_f64()) |
| 3035 | .to_physical(output.current_scale().fractional_scale()) | 3042 | .to_physical(output.current_scale().fractional_scale()) |
| 3036 | .to_i32_round(); | 3043 | .to_i32_round(); |
| 3037 | 3044 | ||
| 3038 | - if self.niri.screenshot_ui.pointer_down(output, point, None) { | 3045 | + if self |
| 3046 | + .niri | ||
| 3047 | + .screenshot_ui | ||
| 3048 | + .pointer_down(output, point, None, mod_down) | ||
| 3049 | + { | ||
| 3039 | self.niri.queue_redraw_all(); | 3050 | self.niri.queue_redraw_all(); |
| 3040 | } | 3051 | } |
| 3041 | } | 3052 | } |
| @@ -3627,13 +3638,29 @@ impl State { | |||
| 3627 | let under = self.niri.contents_under(pos); | 3638 | let under = self.niri.contents_under(pos); |
| 3628 | 3639 | ||
| 3629 | if self.niri.screenshot_ui.is_open() { | 3640 | if self.niri.screenshot_ui.is_open() { |
| 3630 | - if let Some(output) = under.output.clone() { | 3641 | + let mod_key = self.backend.mod_key(&self.niri.config.borrow()); |
| 3642 | + let mods = self.niri.seat.get_keyboard().unwrap().modifier_state(); | ||
| 3643 | + let modifiers = modifiers_from_state(mods); | ||
| 3644 | + let mod_down = modifiers.contains(mod_key.to_modifiers()); | ||
| 3645 | + | ||
| 3646 | + // If we'll be moving the existing selection, use the selection output. | ||
| 3647 | + let output = if mod_down { | ||
| 3648 | + self.niri.screenshot_ui.selection_output() | ||
| 3649 | + } else { | ||
| 3650 | + under.output.as_ref() | ||
| 3651 | + }; | ||
| 3652 | + | ||
| 3653 | + if let Some(output) = output.cloned() { | ||
| 3631 | let geom = self.niri.global_space.output_geometry(&output).unwrap(); | 3654 | let geom = self.niri.global_space.output_geometry(&output).unwrap(); |
| 3632 | let point = (pos - geom.loc.to_f64()) | 3655 | let point = (pos - geom.loc.to_f64()) |
| 3633 | .to_physical(output.current_scale().fractional_scale()) | 3656 | .to_physical(output.current_scale().fractional_scale()) |
| 3634 | .to_i32_round(); | 3657 | .to_i32_round(); |
| 3635 | 3658 | ||
| 3636 | - if self.niri.screenshot_ui.pointer_down(output, point, None) { | 3659 | + if self |
| 3660 | + .niri | ||
| 3661 | + .screenshot_ui | ||
| 3662 | + .pointer_down(output, point, None, mod_down) | ||
| 3663 | + { | ||
| 3637 | self.niri.queue_redraw_all(); | 3664 | self.niri.queue_redraw_all(); |
| 3638 | } | 3665 | } |
| 3639 | } | 3666 | } |
| @@ -4095,9 +4122,19 @@ impl State { | |||
| 4095 | let under = self.niri.contents_under(pos); | 4122 | let under = self.niri.contents_under(pos); |
| 4096 | 4123 | ||
| 4097 | let mod_key = self.backend.mod_key(&self.niri.config.borrow()); | 4124 | let mod_key = self.backend.mod_key(&self.niri.config.borrow()); |
| 4125 | + let mods = self.niri.seat.get_keyboard().unwrap().modifier_state(); | ||
| 4126 | + let mods = modifiers_from_state(mods); | ||
| 4127 | + let mod_down = mods.contains(mod_key.to_modifiers()); | ||
| 4098 | 4128 | ||
| 4099 | if self.niri.screenshot_ui.is_open() { | 4129 | if self.niri.screenshot_ui.is_open() { |
| 4100 | - if let Some(output) = under.output.clone() { | 4130 | + // If we'll be moving the existing selection, use the selection output. |
| 4131 | + let output = if mod_down { | ||
| 4132 | + self.niri.screenshot_ui.selection_output() | ||
| 4133 | + } else { | ||
| 4134 | + under.output.as_ref() | ||
| 4135 | + }; | ||
| 4136 | + | ||
| 4137 | + if let Some(output) = output.cloned() { | ||
| 4101 | let geom = self.niri.global_space.output_geometry(&output).unwrap(); | 4138 | let geom = self.niri.global_space.output_geometry(&output).unwrap(); |
| 4102 | let point = (pos - geom.loc.to_f64()) | 4139 | let point = (pos - geom.loc.to_f64()) |
| 4103 | .to_physical(output.current_scale().fractional_scale()) | 4140 | .to_physical(output.current_scale().fractional_scale()) |
| @@ -4106,7 +4143,7 @@ impl State { | |||
| 4106 | if self | 4143 | if self |
| 4107 | .niri | 4144 | .niri |
| 4108 | .screenshot_ui | 4145 | .screenshot_ui |
| 4109 | - .pointer_down(output, point, Some(slot)) | 4146 | + .pointer_down(output, point, Some(slot), mod_down) |
| 4110 | { | 4147 | { |
| 4111 | self.niri.queue_redraw_all(); | 4148 | self.niri.queue_redraw_all(); |
| 4112 | } | 4149 | } |
| @@ -4125,10 +4162,6 @@ impl State { | |||
| 4125 | } | 4162 | } |
| 4126 | } | 4163 | } |
| 4127 | } else if !handle.is_grabbed() { | 4164 | } else if !handle.is_grabbed() { |
| 4128 | - let mods = self.niri.seat.get_keyboard().unwrap().modifier_state(); | ||
| 4129 | - let mods = modifiers_from_state(mods); | ||
| 4130 | - let mod_down = mods.contains(mod_key.to_modifiers()); | ||
| 4131 | - | ||
| 4132 | if self.niri.layout.is_overview_open() | 4165 | if self.niri.layout.is_overview_open() |
| 4133 | && !mod_down | 4166 | && !mod_down |
| 4134 | && under.layer.is_none() | 4167 | && under.layer.is_none() |
src/ui/screenshot_ui.rsmodified+25 -8
| @@ -852,6 +852,7 @@ impl ScreenshotUi { | |||
| 852 | output: Output, | 852 | output: Output, |
| 853 | point: Point<i32, Physical>, | 853 | point: Point<i32, Physical>, |
| 854 | slot: Option<TouchSlot>, | 854 | slot: Option<TouchSlot>, |
| 855 | + move_existing: bool, | ||
| 855 | ) -> bool { | 856 | ) -> bool { |
| 856 | let Self::Open { | 857 | let Self::Open { |
| 857 | selection, | 858 | selection, |
| @@ -886,6 +887,23 @@ impl ScreenshotUi { | |||
| 886 | return false; | 887 | return false; |
| 887 | } | 888 | } |
| 888 | 889 | ||
| 890 | + if move_existing { | ||
| 891 | + if output != selection.0 { | ||
| 892 | + return false; | ||
| 893 | + } | ||
| 894 | + | ||
| 895 | + *button = Button::Down { | ||
| 896 | + touch_slot: slot, | ||
| 897 | + on_capture_button: false, | ||
| 898 | + last_pos: (output, point), | ||
| 899 | + move_state: Some(MoveState { | ||
| 900 | + pointer_offset: point - selection.1, | ||
| 901 | + touch_slot: slot, | ||
| 902 | + }), | ||
| 903 | + }; | ||
| 904 | + return true; | ||
| 905 | + } | ||
| 906 | + | ||
| 889 | let Some(output_data) = output_data.get(&output) else { | 907 | let Some(output_data) = output_data.get(&output) else { |
| 890 | return false; | 908 | return false; |
| 891 | }; | 909 | }; |
| @@ -947,15 +965,14 @@ impl ScreenshotUi { | |||
| 947 | return None; | 965 | return None; |
| 948 | }; | 966 | }; |
| 949 | 967 | ||
| 950 | - // Check if this is a move touch and if so, stop the move. | ||
| 951 | - if let Some(state) = move_state { | ||
| 952 | - if state.touch_slot.is_some_and(|m_slot| Some(m_slot) == slot) { | ||
| 953 | - *move_state = None; | ||
| 954 | - return None; | ||
| 955 | - } | ||
| 956 | - }; | ||
| 957 | - | ||
| 958 | if touch_slot != slot { | 968 | if touch_slot != slot { |
| 969 | + // This is not our main touch, but it might be the move touch. If so, stop the move. | ||
| 970 | + if let Some(state) = move_state { | ||
| 971 | + if state.touch_slot.is_some_and(|m_slot| Some(m_slot) == slot) { | ||
| 972 | + *move_state = None; | ||
| 973 | + } | ||
| 974 | + }; | ||
| 975 | + | ||
| 959 | return None; | 976 | return None; |
| 960 | } | 977 | } |
| 961 | 978 | ||