diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2025-05-09 15:10:00 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2025-05-09 15:10:00 +0300 |
| commit | d207cd385b12e9c6b52e3865c74af5ec5c042552 (patch) | |
| tree | ba21eb91c386ff9d73bf9ae0247a015de1191ef3 /src | |
| parent | 99bf2df2b42e99b6593646590468aa7b563de416 (diff) | |
| download | niri-d207cd385b12e9c6b52e3865c74af5ec5c042552.tar.gz niri-d207cd385b12e9c6b52e3865c74af5ec5c042552.tar.bz2 niri-d207cd385b12e9c6b52e3865c74af5ec5c042552.zip | |
screenshot_ui: Refactor mouse down + touch slot state
Diffstat (limited to 'src')
| -rw-r--r-- | src/ui/screenshot_ui.rs | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/src/ui/screenshot_ui.rs b/src/ui/screenshot_ui.rs index 14e1e84a..00ea69d9 100644 --- a/src/ui/screenshot_ui.rs +++ b/src/ui/screenshot_ui.rs @@ -56,8 +56,7 @@ pub enum ScreenshotUi { Open { selection: (Output, Point<i32, Physical>, Point<i32, Physical>), output_data: HashMap<Output, OutputData>, - mouse_down: bool, - touch_slot: Option<TouchSlot>, + button: Button, show_pointer: bool, open_anim: Animation, clock: Clock, @@ -65,6 +64,12 @@ pub enum ScreenshotUi { }, } +#[derive(Clone, Copy)] +enum Button { + Up, + Down { touch_slot: Option<TouchSlot> }, +} + pub struct OutputData { size: Size<i32, Physical>, scale: f64, @@ -89,6 +94,12 @@ niri_render_elements! { } } +impl Button { + fn is_down(&self) -> bool { + matches!(self, Self::Down { .. }) + } +} + impl ScreenshotUi { pub fn new(clock: Clock, config: Rc<RefCell<Config>>) -> Self { Self::Closed { @@ -194,8 +205,7 @@ impl ScreenshotUi { *self = Self::Open { selection, output_data, - mouse_down: false, - touch_slot: None, + button: Button::Up, show_pointer, open_anim, clock: clock.clone(), @@ -491,7 +501,7 @@ impl ScreenshotUi { let Self::Open { output_data, show_pointer, - mouse_down, + button, open_anim, .. } = self @@ -520,7 +530,7 @@ impl ScreenshotUi { .to_f64() .to_logical(scale); - let alpha = if *mouse_down { 0.3 } else { 0.9 }; + let alpha = if button.is_down() { 0.3 } else { 0.9 }; let elem = PrimaryGpuTextureRenderElement(TextureRenderElement::from_texture_buffer( buffer.clone(), @@ -665,8 +675,7 @@ impl ScreenshotUi { pub fn pointer_motion(&mut self, point: Point<i32, Physical>, slot: Option<TouchSlot>) { let Self::Open { selection, - mouse_down: true, - touch_slot, + button: Button::Down { touch_slot }, .. } = self else { @@ -690,15 +699,15 @@ impl ScreenshotUi { let Self::Open { selection, output_data, - mouse_down, - touch_slot, + show_pointer, + button, .. } = self else { return false; }; - if *mouse_down { + if button.is_down() { return false; } @@ -706,9 +715,8 @@ impl ScreenshotUi { return false; } - *mouse_down = true; + *button = Button::Down { touch_slot: slot }; *selection = (output, point, point); - *touch_slot = slot; self.update_buffers(); @@ -719,24 +727,22 @@ impl ScreenshotUi { let Self::Open { selection, output_data, - mouse_down, - touch_slot, + button, .. } = self else { return false; }; - if !*mouse_down { + let Button::Down { touch_slot } = *button else { return false; - } + }; - if *touch_slot != slot { + if touch_slot != slot { return false; } - *mouse_down = false; - *touch_slot = None; + *button = Button::Up; // Check if the resulting selection is zero-sized, and try to come up with a small // default rectangle. |
