diff --git a/src/input/mod.rs b/src/input/mod.rs index 07d63e66..fa9e03be 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -3028,14 +3028,25 @@ impl State { if button == Some(MouseButton::Left) && self.niri.screenshot_ui.is_open() { if button_state == ButtonState::Pressed { let pos = pointer.current_location(); - if let Some((output, _)) = self.niri.output_under(pos) { - let output = output.clone(); + + // If we'll be moving the existing selection, use the selection output. + let output = if mod_down { + self.niri.screenshot_ui.selection_output() + } else { + self.niri.output_under(pos).map(|(out, _)| out) + }; + + if let Some(output) = output.cloned() { let geom = self.niri.global_space.output_geometry(&output).unwrap(); let point = (pos - geom.loc.to_f64()) .to_physical(output.current_scale().fractional_scale()) .to_i32_round(); - if self.niri.screenshot_ui.pointer_down(output, point, None) { + if self + .niri + .screenshot_ui + .pointer_down(output, point, None, mod_down) + { self.niri.queue_redraw_all(); } } @@ -3627,13 +3638,29 @@ impl State { let under = self.niri.contents_under(pos); if self.niri.screenshot_ui.is_open() { - if let Some(output) = under.output.clone() { + let mod_key = self.backend.mod_key(&self.niri.config.borrow()); + let mods = self.niri.seat.get_keyboard().unwrap().modifier_state(); + let modifiers = modifiers_from_state(mods); + let mod_down = modifiers.contains(mod_key.to_modifiers()); + + // If we'll be moving the existing selection, use the selection output. + let output = if mod_down { + self.niri.screenshot_ui.selection_output() + } else { + under.output.as_ref() + }; + + if let Some(output) = output.cloned() { let geom = self.niri.global_space.output_geometry(&output).unwrap(); let point = (pos - geom.loc.to_f64()) .to_physical(output.current_scale().fractional_scale()) .to_i32_round(); - if self.niri.screenshot_ui.pointer_down(output, point, None) { + if self + .niri + .screenshot_ui + .pointer_down(output, point, None, mod_down) + { self.niri.queue_redraw_all(); } } @@ -4095,9 +4122,19 @@ impl State { let under = self.niri.contents_under(pos); let mod_key = self.backend.mod_key(&self.niri.config.borrow()); + let mods = self.niri.seat.get_keyboard().unwrap().modifier_state(); + let mods = modifiers_from_state(mods); + let mod_down = mods.contains(mod_key.to_modifiers()); if self.niri.screenshot_ui.is_open() { - if let Some(output) = under.output.clone() { + // If we'll be moving the existing selection, use the selection output. + let output = if mod_down { + self.niri.screenshot_ui.selection_output() + } else { + under.output.as_ref() + }; + + if let Some(output) = output.cloned() { let geom = self.niri.global_space.output_geometry(&output).unwrap(); let point = (pos - geom.loc.to_f64()) .to_physical(output.current_scale().fractional_scale()) @@ -4106,7 +4143,7 @@ impl State { if self .niri .screenshot_ui - .pointer_down(output, point, Some(slot)) + .pointer_down(output, point, Some(slot), mod_down) { self.niri.queue_redraw_all(); } @@ -4125,10 +4162,6 @@ impl State { } } } else if !handle.is_grabbed() { - let mods = self.niri.seat.get_keyboard().unwrap().modifier_state(); - let mods = modifiers_from_state(mods); - let mod_down = mods.contains(mod_key.to_modifiers()); - if self.niri.layout.is_overview_open() && !mod_down && under.layer.is_none() diff --git a/src/ui/screenshot_ui.rs b/src/ui/screenshot_ui.rs index 369ea14b..a1586361 100644 --- a/src/ui/screenshot_ui.rs +++ b/src/ui/screenshot_ui.rs @@ -852,6 +852,7 @@ impl ScreenshotUi { output: Output, point: Point, slot: Option, + move_existing: bool, ) -> bool { let Self::Open { selection, @@ -886,6 +887,23 @@ impl ScreenshotUi { return false; } + if move_existing { + if output != selection.0 { + return false; + } + + *button = Button::Down { + touch_slot: slot, + on_capture_button: false, + last_pos: (output, point), + move_state: Some(MoveState { + pointer_offset: point - selection.1, + touch_slot: slot, + }), + }; + return true; + } + let Some(output_data) = output_data.get(&output) else { return false; }; @@ -947,15 +965,14 @@ impl ScreenshotUi { return None; }; - // Check if this is a move touch and if so, stop the move. - if let Some(state) = move_state { - if state.touch_slot.is_some_and(|m_slot| Some(m_slot) == slot) { - *move_state = None; - return None; - } - }; - if touch_slot != slot { + // This is not our main touch, but it might be the move touch. If so, stop the move. + if let Some(state) = move_state { + if state.touch_slot.is_some_and(|m_slot| Some(m_slot) == slot) { + *move_state = None; + } + }; + return None; }