Clamp pointer to output inside screenshot_ui
Browse files at this commitf115f2e5e76545e0a1370006598ec3b0ef2a0732Parent: 2e072822 changed files +16 -51
- src/input/mod.rs +7 -50
- src/ui/screenshot_ui.rs +9 -1
src/input/mod.rsmodified+7 -50
| @@ -1,5 +1,4 @@ | ||
| 1 | 1 | use std::any::Any; |
| 2 | -use std::cmp::min; | |
| 3 | 2 | use std::collections::hash_map::Entry; |
| 4 | 3 | use std::collections::HashSet; |
| 5 | 4 | use std::time::Duration; |
| @@ -2547,16 +2546,10 @@ impl State { | ||
| 2547 | 2546 | |
| 2548 | 2547 | if let Some(output) = self.niri.screenshot_ui.selection_output() { |
| 2549 | 2548 | let geom = self.niri.global_space.output_geometry(output).unwrap(); |
| 2550 | - let mut point = (new_pos - geom.loc.to_f64()) | |
| 2549 | + let point = (new_pos - geom.loc.to_f64()) | |
| 2551 | 2550 | .to_physical(output.current_scale().fractional_scale()) |
| 2552 | 2551 | .to_i32_round::<i32>(); |
| 2553 | 2552 | |
| 2554 | - let size = output.current_mode().unwrap().size; | |
| 2555 | - let transform = output.current_transform(); | |
| 2556 | - let size = transform.transform_size(size); | |
| 2557 | - point.x = point.x.clamp(0, size.w - 1); | |
| 2558 | - point.y = point.y.clamp(0, size.h - 1); | |
| 2559 | - | |
| 2560 | 2553 | self.niri.screenshot_ui.pointer_motion(point, None); |
| 2561 | 2554 | } |
| 2562 | 2555 | |
| @@ -2684,16 +2677,10 @@ impl State { | ||
| 2684 | 2677 | |
| 2685 | 2678 | if let Some(output) = self.niri.screenshot_ui.selection_output() { |
| 2686 | 2679 | let geom = self.niri.global_space.output_geometry(output).unwrap(); |
| 2687 | - let mut point = (pos - geom.loc.to_f64()) | |
| 2680 | + let point = (pos - geom.loc.to_f64()) | |
| 2688 | 2681 | .to_physical(output.current_scale().fractional_scale()) |
| 2689 | 2682 | .to_i32_round::<i32>(); |
| 2690 | 2683 | |
| 2691 | - let size = output.current_mode().unwrap().size; | |
| 2692 | - let transform = output.current_transform(); | |
| 2693 | - let size = transform.transform_size(size); | |
| 2694 | - point.x = point.x.clamp(0, size.w - 1); | |
| 2695 | - point.y = point.y.clamp(0, size.h - 1); | |
| 2696 | - | |
| 2697 | 2684 | self.niri.screenshot_ui.pointer_motion(point, None); |
| 2698 | 2685 | } |
| 2699 | 2686 | |
| @@ -3044,16 +3031,10 @@ impl State { | ||
| 3044 | 3031 | if let Some((output, _)) = self.niri.output_under(pos) { |
| 3045 | 3032 | let output = output.clone(); |
| 3046 | 3033 | let geom = self.niri.global_space.output_geometry(&output).unwrap(); |
| 3047 | - let mut point = (pos - geom.loc.to_f64()) | |
| 3034 | + let point = (pos - geom.loc.to_f64()) | |
| 3048 | 3035 | .to_physical(output.current_scale().fractional_scale()) |
| 3049 | 3036 | .to_i32_round(); |
| 3050 | 3037 | |
| 3051 | - let size = output.current_mode().unwrap().size; | |
| 3052 | - let transform = output.current_transform(); | |
| 3053 | - let size = transform.transform_size(size); | |
| 3054 | - point.x = min(size.w - 1, point.x); | |
| 3055 | - point.y = min(size.h - 1, point.y); | |
| 3056 | - | |
| 3057 | 3038 | if self.niri.screenshot_ui.pointer_down(output, point, None) { |
| 3058 | 3039 | self.niri.queue_redraw_all(); |
| 3059 | 3040 | } |
| @@ -3570,16 +3551,10 @@ impl State { | ||
| 3570 | 3551 | |
| 3571 | 3552 | if let Some(output) = self.niri.screenshot_ui.selection_output() { |
| 3572 | 3553 | let geom = self.niri.global_space.output_geometry(output).unwrap(); |
| 3573 | - let mut point = (pos - geom.loc.to_f64()) | |
| 3554 | + let point = (pos - geom.loc.to_f64()) | |
| 3574 | 3555 | .to_physical(output.current_scale().fractional_scale()) |
| 3575 | 3556 | .to_i32_round::<i32>(); |
| 3576 | 3557 | |
| 3577 | - let size = output.current_mode().unwrap().size; | |
| 3578 | - let transform = output.current_transform(); | |
| 3579 | - let size = transform.transform_size(size); | |
| 3580 | - point.x = point.x.clamp(0, size.w - 1); | |
| 3581 | - point.y = point.y.clamp(0, size.h - 1); | |
| 3582 | - | |
| 3583 | 3558 | self.niri.screenshot_ui.pointer_motion(point, None); |
| 3584 | 3559 | } |
| 3585 | 3560 | |
| @@ -3654,16 +3629,10 @@ impl State { | ||
| 3654 | 3629 | if self.niri.screenshot_ui.is_open() { |
| 3655 | 3630 | if let Some(output) = under.output.clone() { |
| 3656 | 3631 | let geom = self.niri.global_space.output_geometry(&output).unwrap(); |
| 3657 | - let mut point = (pos - geom.loc.to_f64()) | |
| 3632 | + let point = (pos - geom.loc.to_f64()) | |
| 3658 | 3633 | .to_physical(output.current_scale().fractional_scale()) |
| 3659 | 3634 | .to_i32_round(); |
| 3660 | 3635 | |
| 3661 | - let size = output.current_mode().unwrap().size; | |
| 3662 | - let transform = output.current_transform(); | |
| 3663 | - let size = transform.transform_size(size); | |
| 3664 | - point.x = min(size.w - 1, point.x); | |
| 3665 | - point.y = min(size.h - 1, point.y); | |
| 3666 | - | |
| 3667 | 3636 | if self.niri.screenshot_ui.pointer_down(output, point, None) { |
| 3668 | 3637 | self.niri.queue_redraw_all(); |
| 3669 | 3638 | } |
| @@ -4130,16 +4099,10 @@ impl State { | ||
| 4130 | 4099 | if self.niri.screenshot_ui.is_open() { |
| 4131 | 4100 | if let Some(output) = under.output.clone() { |
| 4132 | 4101 | let geom = self.niri.global_space.output_geometry(&output).unwrap(); |
| 4133 | - let mut point = (pos - geom.loc.to_f64()) | |
| 4102 | + let point = (pos - geom.loc.to_f64()) | |
| 4134 | 4103 | .to_physical(output.current_scale().fractional_scale()) |
| 4135 | 4104 | .to_i32_round(); |
| 4136 | 4105 | |
| 4137 | - let size = output.current_mode().unwrap().size; | |
| 4138 | - let transform = output.current_transform(); | |
| 4139 | - let size = transform.transform_size(size); | |
| 4140 | - point.x = min(size.w - 1, point.x); | |
| 4141 | - point.y = min(size.h - 1, point.y); | |
| 4142 | - | |
| 4143 | 4106 | if self |
| 4144 | 4107 | .niri |
| 4145 | 4108 | .screenshot_ui |
| @@ -4278,16 +4241,10 @@ impl State { | ||
| 4278 | 4241 | |
| 4279 | 4242 | if let Some(output) = self.niri.screenshot_ui.selection_output().cloned() { |
| 4280 | 4243 | let geom = self.niri.global_space.output_geometry(&output).unwrap(); |
| 4281 | - let mut point = (pos - geom.loc.to_f64()) | |
| 4244 | + let point = (pos - geom.loc.to_f64()) | |
| 4282 | 4245 | .to_physical(output.current_scale().fractional_scale()) |
| 4283 | 4246 | .to_i32_round::<i32>(); |
| 4284 | 4247 | |
| 4285 | - let size = output.current_mode().unwrap().size; | |
| 4286 | - let transform = output.current_transform(); | |
| 4287 | - let size = transform.transform_size(size); | |
| 4288 | - point.x = point.x.clamp(0, size.w - 1); | |
| 4289 | - point.y = point.y.clamp(0, size.h - 1); | |
| 4290 | - | |
| 4291 | 4248 | self.niri.screenshot_ui.pointer_motion(point, Some(slot)); |
| 4292 | 4249 | self.niri.queue_redraw(&output); |
| 4293 | 4250 | } |
src/ui/screenshot_ui.rsmodified+9 -1
| @@ -799,6 +799,8 @@ impl ScreenshotUi { | ||
| 799 | 799 | } |
| 800 | 800 | |
| 801 | 801 | /// The pointer has moved to `point` relative to the current selection output. |
| 802 | + /// | |
| 803 | + /// The point may be outside output bounds. | |
| 802 | 804 | pub fn pointer_motion(&mut self, point: Point<i32, Physical>, slot: Option<TouchSlot>) { |
| 803 | 805 | let Self::Open { |
| 804 | 806 | selection, |
| @@ -838,7 +840,8 @@ impl ScreenshotUi { | ||
| 838 | 840 | selection.1 += delta; |
| 839 | 841 | selection.2 += delta; |
| 840 | 842 | } else { |
| 841 | - selection.2 = point; | |
| 843 | + let size = output_data[&selection.0].size; | |
| 844 | + selection.2 = Point::new(point.x.clamp(0, size.w - 1), point.y.clamp(0, size.h - 1)); | |
| 842 | 845 | } |
| 843 | 846 | |
| 844 | 847 | self.update_buffers(); |
| @@ -909,6 +912,11 @@ impl ScreenshotUi { | ||
| 909 | 912 | last_pos: (output.clone(), point), |
| 910 | 913 | move_state: None, |
| 911 | 914 | }; |
| 915 | + | |
| 916 | + let point = Point::new( | |
| 917 | + point.x.clamp(0, output_data.size.w - 1), | |
| 918 | + point.y.clamp(0, output_data.size.h - 1), | |
| 919 | + ); | |
| 912 | 920 | *selection = (output, point, point); |
| 913 | 921 | |
| 914 | 922 | self.update_buffers(); |