From 09be90f4e63c312fbb70ba8c743ab0909cb591e2 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Fri, 9 May 2025 09:18:22 +0300 Subject: Add touch selection support to the screenshot UI --- src/ui/screenshot_ui.rs | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'src/ui') diff --git a/src/ui/screenshot_ui.rs b/src/ui/screenshot_ui.rs index 2de3ddbc..14e1e84a 100644 --- a/src/ui/screenshot_ui.rs +++ b/src/ui/screenshot_ui.rs @@ -11,6 +11,7 @@ use niri_ipc::SizeChange; use pango::{Alignment, FontDescription}; use pangocairo::cairo::{self, ImageSurface}; use smithay::backend::allocator::Fourcc; +use smithay::backend::input::TouchSlot; use smithay::backend::renderer::element::utils::{Relocate, RelocateRenderElement}; use smithay::backend::renderer::element::Kind; use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture}; @@ -56,6 +57,7 @@ pub enum ScreenshotUi { selection: (Output, Point, Point), output_data: HashMap, mouse_down: bool, + touch_slot: Option, show_pointer: bool, open_anim: Animation, clock: Clock, @@ -193,6 +195,7 @@ impl ScreenshotUi { selection, output_data, mouse_down: false, + touch_slot: None, show_pointer, open_anim, clock: clock.clone(), @@ -659,25 +662,36 @@ impl ScreenshotUi { } /// The pointer has moved to `point` relative to the current selection output. - pub fn pointer_motion(&mut self, point: Point) { + pub fn pointer_motion(&mut self, point: Point, slot: Option) { let Self::Open { selection, mouse_down: true, + touch_slot, .. } = self else { return; }; + if *touch_slot != slot { + return; + } + selection.2 = point; self.update_buffers(); } - pub fn pointer_down(&mut self, output: Output, point: Point) -> bool { + pub fn pointer_down( + &mut self, + output: Output, + point: Point, + slot: Option, + ) -> bool { let Self::Open { selection, output_data, mouse_down, + touch_slot, .. } = self else { @@ -694,17 +708,19 @@ impl ScreenshotUi { *mouse_down = true; *selection = (output, point, point); + *touch_slot = slot; self.update_buffers(); true } - pub fn pointer_up(&mut self) -> bool { + pub fn pointer_up(&mut self, slot: Option) -> bool { let Self::Open { selection, output_data, mouse_down, + touch_slot, .. } = self else { @@ -715,7 +731,12 @@ impl ScreenshotUi { return false; } + if *touch_slot != slot { + return false; + } + *mouse_down = false; + *touch_slot = None; // Check if the resulting selection is zero-sized, and try to come up with a small // default rectangle. -- cgit