Add touch selection support to the screenshot UI
Browse files at this commit09be90f4e63c312fbb70ba8c743ab0909cb591e2Parent: dfc42b93 changed files +82 -13
- src/input/mod.rs +55 -10
- src/niri.rs +3 -0
- src/ui/screenshot_ui.rs +24 -3
src/input/mod.rsmodified+55 -10
| @@ -2112,7 +2112,7 @@ impl State { | |||
| 2112 | point.x = point.x.clamp(0, size.w - 1); | 2112 | point.x = point.x.clamp(0, size.w - 1); |
| 2113 | point.y = point.y.clamp(0, size.h - 1); | 2113 | point.y = point.y.clamp(0, size.h - 1); |
| 2114 | 2114 | ||
| 2115 | - self.niri.screenshot_ui.pointer_motion(point); | 2115 | + self.niri.screenshot_ui.pointer_motion(point, None); |
| 2116 | } | 2116 | } |
| 2117 | 2117 | ||
| 2118 | let under = self.niri.contents_under(new_pos); | 2118 | let under = self.niri.contents_under(new_pos); |
| @@ -2245,7 +2245,7 @@ impl State { | |||
| 2245 | point.x = point.x.clamp(0, size.w - 1); | 2245 | point.x = point.x.clamp(0, size.w - 1); |
| 2246 | point.y = point.y.clamp(0, size.h - 1); | 2246 | point.y = point.y.clamp(0, size.h - 1); |
| 2247 | 2247 | ||
| 2248 | - self.niri.screenshot_ui.pointer_motion(point); | 2248 | + self.niri.screenshot_ui.pointer_motion(point, None); |
| 2249 | } | 2249 | } |
| 2250 | 2250 | ||
| 2251 | let under = self.niri.contents_under(pos); | 2251 | let under = self.niri.contents_under(pos); |
| @@ -2579,11 +2579,11 @@ impl State { | |||
| 2579 | point.x = min(size.w - 1, point.x); | 2579 | point.x = min(size.w - 1, point.x); |
| 2580 | point.y = min(size.h - 1, point.y); | 2580 | point.y = min(size.h - 1, point.y); |
| 2581 | 2581 | ||
| 2582 | - if self.niri.screenshot_ui.pointer_down(output, point) { | 2582 | + if self.niri.screenshot_ui.pointer_down(output, point, None) { |
| 2583 | self.niri.queue_redraw_all(); | 2583 | self.niri.queue_redraw_all(); |
| 2584 | } | 2584 | } |
| 2585 | } | 2585 | } |
| 2586 | - } else if self.niri.screenshot_ui.pointer_up() { | 2586 | + } else if self.niri.screenshot_ui.pointer_up(None) { |
| 2587 | self.niri.queue_redraw_all(); | 2587 | self.niri.queue_redraw_all(); |
| 2588 | } | 2588 | } |
| 2589 | } | 2589 | } |
| @@ -3034,7 +3034,7 @@ impl State { | |||
| 3034 | point.x = point.x.clamp(0, size.w - 1); | 3034 | point.x = point.x.clamp(0, size.w - 1); |
| 3035 | point.y = point.y.clamp(0, size.h - 1); | 3035 | point.y = point.y.clamp(0, size.h - 1); |
| 3036 | 3036 | ||
| 3037 | - self.niri.screenshot_ui.pointer_motion(point); | 3037 | + self.niri.screenshot_ui.pointer_motion(point, None); |
| 3038 | } | 3038 | } |
| 3039 | 3039 | ||
| 3040 | let under = self.niri.contents_under(pos); | 3040 | let under = self.niri.contents_under(pos); |
| @@ -3110,7 +3110,7 @@ impl State { | |||
| 3110 | point.x = min(size.w - 1, point.x); | 3110 | point.x = min(size.w - 1, point.x); |
| 3111 | point.y = min(size.h - 1, point.y); | 3111 | point.y = min(size.h - 1, point.y); |
| 3112 | 3112 | ||
| 3113 | - if self.niri.screenshot_ui.pointer_down(output, point) { | 3113 | + if self.niri.screenshot_ui.pointer_down(output, point, None) { |
| 3114 | self.niri.queue_redraw_all(); | 3114 | self.niri.queue_redraw_all(); |
| 3115 | } | 3115 | } |
| 3116 | } | 3116 | } |
| @@ -3151,7 +3151,7 @@ impl State { | |||
| 3151 | } | 3151 | } |
| 3152 | } | 3152 | } |
| 3153 | TabletToolTipState::Up => { | 3153 | TabletToolTipState::Up => { |
| 3154 | - if self.niri.screenshot_ui.pointer_up() { | 3154 | + if self.niri.screenshot_ui.pointer_up(None) { |
| 3155 | self.niri.queue_redraw_all(); | 3155 | self.niri.queue_redraw_all(); |
| 3156 | } | 3156 | } |
| 3157 | 3157 | ||
| @@ -3550,7 +3550,28 @@ impl State { | |||
| 3550 | 3550 | ||
| 3551 | let mod_key = self.backend.mod_key(&self.niri.config.borrow()); | 3551 | let mod_key = self.backend.mod_key(&self.niri.config.borrow()); |
| 3552 | 3552 | ||
| 3553 | - if !handle.is_grabbed() { | 3553 | + if self.niri.screenshot_ui.is_open() { |
| 3554 | + if let Some(output) = under.output.clone() { | ||
| 3555 | + let geom = self.niri.global_space.output_geometry(&output).unwrap(); | ||
| 3556 | + let mut point = (pos - geom.loc.to_f64()) | ||
| 3557 | + .to_physical(output.current_scale().fractional_scale()) | ||
| 3558 | + .to_i32_round(); | ||
| 3559 | + | ||
| 3560 | + let size = output.current_mode().unwrap().size; | ||
| 3561 | + let transform = output.current_transform(); | ||
| 3562 | + let size = transform.transform_size(size); | ||
| 3563 | + point.x = min(size.w - 1, point.x); | ||
| 3564 | + point.y = min(size.h - 1, point.y); | ||
| 3565 | + | ||
| 3566 | + if self | ||
| 3567 | + .niri | ||
| 3568 | + .screenshot_ui | ||
| 3569 | + .pointer_down(output, point, Some(slot)) | ||
| 3570 | + { | ||
| 3571 | + self.niri.queue_redraw_all(); | ||
| 3572 | + } | ||
| 3573 | + } | ||
| 3574 | + } else if !handle.is_grabbed() { | ||
| 3554 | let mods = self.niri.seat.get_keyboard().unwrap().modifier_state(); | 3575 | let mods = self.niri.seat.get_keyboard().unwrap().modifier_state(); |
| 3555 | let mods = modifiers_from_state(mods); | 3576 | let mods = modifiers_from_state(mods); |
| 3556 | let mod_down = mods.contains(mod_key.to_modifiers()); | 3577 | let mod_down = mods.contains(mod_key.to_modifiers()); |
| @@ -3638,11 +3659,17 @@ impl State { | |||
| 3638 | let Some(handle) = self.niri.seat.get_touch() else { | 3659 | let Some(handle) = self.niri.seat.get_touch() else { |
| 3639 | return; | 3660 | return; |
| 3640 | }; | 3661 | }; |
| 3662 | + let slot = evt.slot(); | ||
| 3663 | + | ||
| 3664 | + if self.niri.screenshot_ui.pointer_up(Some(slot)) { | ||
| 3665 | + self.niri.queue_redraw_all(); | ||
| 3666 | + } | ||
| 3667 | + | ||
| 3641 | let serial = SERIAL_COUNTER.next_serial(); | 3668 | let serial = SERIAL_COUNTER.next_serial(); |
| 3642 | handle.up( | 3669 | handle.up( |
| 3643 | self, | 3670 | self, |
| 3644 | &UpEvent { | 3671 | &UpEvent { |
| 3645 | - slot: evt.slot(), | 3672 | + slot, |
| 3646 | serial, | 3673 | serial, |
| 3647 | time: evt.time_msec(), | 3674 | time: evt.time_msec(), |
| 3648 | }, | 3675 | }, |
| @@ -3655,12 +3682,30 @@ impl State { | |||
| 3655 | let Some(pos) = self.compute_touch_location(&evt) else { | 3682 | let Some(pos) = self.compute_touch_location(&evt) else { |
| 3656 | return; | 3683 | return; |
| 3657 | }; | 3684 | }; |
| 3685 | + let slot = evt.slot(); | ||
| 3686 | + | ||
| 3687 | + if let Some(output) = self.niri.screenshot_ui.selection_output().cloned() { | ||
| 3688 | + let geom = self.niri.global_space.output_geometry(&output).unwrap(); | ||
| 3689 | + let mut point = (pos - geom.loc.to_f64()) | ||
| 3690 | + .to_physical(output.current_scale().fractional_scale()) | ||
| 3691 | + .to_i32_round::<i32>(); | ||
| 3692 | + | ||
| 3693 | + let size = output.current_mode().unwrap().size; | ||
| 3694 | + let transform = output.current_transform(); | ||
| 3695 | + let size = transform.transform_size(size); | ||
| 3696 | + point.x = point.x.clamp(0, size.w - 1); | ||
| 3697 | + point.y = point.y.clamp(0, size.h - 1); | ||
| 3698 | + | ||
| 3699 | + self.niri.screenshot_ui.pointer_motion(point, Some(slot)); | ||
| 3700 | + self.niri.queue_redraw(&output); | ||
| 3701 | + } | ||
| 3702 | + | ||
| 3658 | let under = self.niri.contents_under(pos); | 3703 | let under = self.niri.contents_under(pos); |
| 3659 | handle.motion( | 3704 | handle.motion( |
| 3660 | self, | 3705 | self, |
| 3661 | under.surface, | 3706 | under.surface, |
| 3662 | &TouchMotionEvent { | 3707 | &TouchMotionEvent { |
| 3663 | - slot: evt.slot(), | 3708 | + slot, |
| 3664 | location: pos, | 3709 | location: pos, |
| 3665 | time: evt.time_msec(), | 3710 | time: evt.time_msec(), |
| 3666 | }, | 3711 | }, |
src/niri.rsmodified+3 -0
| @@ -1712,6 +1712,9 @@ impl State { | |||
| 1712 | SERIAL_COUNTER.next_serial(), | 1712 | SERIAL_COUNTER.next_serial(), |
| 1713 | get_monotonic_time().as_millis() as u32, | 1713 | get_monotonic_time().as_millis() as u32, |
| 1714 | ); | 1714 | ); |
| 1715 | + if let Some(touch) = self.niri.seat.get_touch() { | ||
| 1716 | + touch.unset_grab(self); | ||
| 1717 | + } | ||
| 1715 | 1718 | ||
| 1716 | self.backend.with_primary_renderer(|renderer| { | 1719 | self.backend.with_primary_renderer(|renderer| { |
| 1717 | self.niri | 1720 | self.niri |
src/ui/screenshot_ui.rsmodified+24 -3
| @@ -11,6 +11,7 @@ use niri_ipc::SizeChange; | |||
| 11 | use pango::{Alignment, FontDescription}; | 11 | use pango::{Alignment, FontDescription}; |
| 12 | use pangocairo::cairo::{self, ImageSurface}; | 12 | use pangocairo::cairo::{self, ImageSurface}; |
| 13 | use smithay::backend::allocator::Fourcc; | 13 | use smithay::backend::allocator::Fourcc; |
| 14 | +use smithay::backend::input::TouchSlot; | ||
| 14 | use smithay::backend::renderer::element::utils::{Relocate, RelocateRenderElement}; | 15 | use smithay::backend::renderer::element::utils::{Relocate, RelocateRenderElement}; |
| 15 | use smithay::backend::renderer::element::Kind; | 16 | use smithay::backend::renderer::element::Kind; |
| 16 | use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture}; | 17 | use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture}; |
| @@ -56,6 +57,7 @@ pub enum ScreenshotUi { | |||
| 56 | selection: (Output, Point<i32, Physical>, Point<i32, Physical>), | 57 | selection: (Output, Point<i32, Physical>, Point<i32, Physical>), |
| 57 | output_data: HashMap<Output, OutputData>, | 58 | output_data: HashMap<Output, OutputData>, |
| 58 | mouse_down: bool, | 59 | mouse_down: bool, |
| 60 | + touch_slot: Option<TouchSlot>, | ||
| 59 | show_pointer: bool, | 61 | show_pointer: bool, |
| 60 | open_anim: Animation, | 62 | open_anim: Animation, |
| 61 | clock: Clock, | 63 | clock: Clock, |
| @@ -193,6 +195,7 @@ impl ScreenshotUi { | |||
| 193 | selection, | 195 | selection, |
| 194 | output_data, | 196 | output_data, |
| 195 | mouse_down: false, | 197 | mouse_down: false, |
| 198 | + touch_slot: None, | ||
| 196 | show_pointer, | 199 | show_pointer, |
| 197 | open_anim, | 200 | open_anim, |
| 198 | clock: clock.clone(), | 201 | clock: clock.clone(), |
| @@ -659,25 +662,36 @@ impl ScreenshotUi { | |||
| 659 | } | 662 | } |
| 660 | 663 | ||
| 661 | /// The pointer has moved to `point` relative to the current selection output. | 664 | /// The pointer has moved to `point` relative to the current selection output. |
| 662 | - pub fn pointer_motion(&mut self, point: Point<i32, Physical>) { | 665 | + pub fn pointer_motion(&mut self, point: Point<i32, Physical>, slot: Option<TouchSlot>) { |
| 663 | let Self::Open { | 666 | let Self::Open { |
| 664 | selection, | 667 | selection, |
| 665 | mouse_down: true, | 668 | mouse_down: true, |
| 669 | + touch_slot, | ||
| 666 | .. | 670 | .. |
| 667 | } = self | 671 | } = self |
| 668 | else { | 672 | else { |
| 669 | return; | 673 | return; |
| 670 | }; | 674 | }; |
| 671 | 675 | ||
| 676 | + if *touch_slot != slot { | ||
| 677 | + return; | ||
| 678 | + } | ||
| 679 | + | ||
| 672 | selection.2 = point; | 680 | selection.2 = point; |
| 673 | self.update_buffers(); | 681 | self.update_buffers(); |
| 674 | } | 682 | } |
| 675 | 683 | ||
| 676 | - pub fn pointer_down(&mut self, output: Output, point: Point<i32, Physical>) -> bool { | 684 | + pub fn pointer_down( |
| 685 | + &mut self, | ||
| 686 | + output: Output, | ||
| 687 | + point: Point<i32, Physical>, | ||
| 688 | + slot: Option<TouchSlot>, | ||
| 689 | + ) -> bool { | ||
| 677 | let Self::Open { | 690 | let Self::Open { |
| 678 | selection, | 691 | selection, |
| 679 | output_data, | 692 | output_data, |
| 680 | mouse_down, | 693 | mouse_down, |
| 694 | + touch_slot, | ||
| 681 | .. | 695 | .. |
| 682 | } = self | 696 | } = self |
| 683 | else { | 697 | else { |
| @@ -694,17 +708,19 @@ impl ScreenshotUi { | |||
| 694 | 708 | ||
| 695 | *mouse_down = true; | 709 | *mouse_down = true; |
| 696 | *selection = (output, point, point); | 710 | *selection = (output, point, point); |
| 711 | + *touch_slot = slot; | ||
| 697 | 712 | ||
| 698 | self.update_buffers(); | 713 | self.update_buffers(); |
| 699 | 714 | ||
| 700 | true | 715 | true |
| 701 | } | 716 | } |
| 702 | 717 | ||
| 703 | - pub fn pointer_up(&mut self) -> bool { | 718 | + pub fn pointer_up(&mut self, slot: Option<TouchSlot>) -> bool { |
| 704 | let Self::Open { | 719 | let Self::Open { |
| 705 | selection, | 720 | selection, |
| 706 | output_data, | 721 | output_data, |
| 707 | mouse_down, | 722 | mouse_down, |
| 723 | + touch_slot, | ||
| 708 | .. | 724 | .. |
| 709 | } = self | 725 | } = self |
| 710 | else { | 726 | else { |
| @@ -715,7 +731,12 @@ impl ScreenshotUi { | |||
| 715 | return false; | 731 | return false; |
| 716 | } | 732 | } |
| 717 | 733 | ||
| 734 | + if *touch_slot != slot { | ||
| 735 | + return false; | ||
| 736 | + } | ||
| 737 | + | ||
| 718 | *mouse_down = false; | 738 | *mouse_down = false; |
| 739 | + *touch_slot = None; | ||
| 719 | 740 | ||
| 720 | // Check if the resulting selection is zero-sized, and try to come up with a small | 741 | // Check if the resulting selection is zero-sized, and try to come up with a small |
| 721 | // default rectangle. | 742 | // default rectangle. |