aboutsummaryrefslogtreecommitdiff
path: root/src/input
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2024-06-09 11:57:05 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2024-06-10 18:08:01 +0300
commit4b830ee7ff2a96fc7bf05176c9da0095f890e1ad (patch)
treea16c2d3c32f3e70d908ce9ff38cffc684223f8b7 /src/input
parent8e41568ffd31bb1bdade7f8dd31f893e6539003b (diff)
downloadniri-4b830ee7ff2a96fc7bf05176c9da0095f890e1ad.tar.gz
niri-4b830ee7ff2a96fc7bf05176c9da0095f890e1ad.tar.bz2
niri-4b830ee7ff2a96fc7bf05176c9da0095f890e1ad.zip
ui/screenshot_ui: Correct fractional scaled behavior
Diffstat (limited to 'src/input')
-rw-r--r--src/input/mod.rs51
1 files changed, 25 insertions, 26 deletions
diff --git a/src/input/mod.rs b/src/input/mod.rs
index 40607ad5..acb08e1c 100644
--- a/src/input/mod.rs
+++ b/src/input/mod.rs
@@ -1,4 +1,5 @@
use std::any::Any;
+use std::cmp::min;
use std::collections::hash_map::Entry;
use std::collections::HashSet;
use std::time::Duration;
@@ -1009,16 +1010,16 @@ impl State {
if let Some(output) = self.niri.screenshot_ui.selection_output() {
let geom = self.niri.global_space.output_geometry(output).unwrap();
- let mut point = new_pos;
- point.x = point
- .x
- .clamp(geom.loc.x as f64, (geom.loc.x + geom.size.w - 1) as f64);
- point.y = point
- .y
- .clamp(geom.loc.y as f64, (geom.loc.y + geom.size.h - 1) as f64);
- let point = (point - geom.loc.to_f64())
+ let mut point = (new_pos - geom.loc.to_f64())
.to_physical(output.current_scale().fractional_scale())
.to_i32_round();
+
+ let size = output.current_mode().unwrap().size;
+ let transform = output.current_transform();
+ let size = transform.transform_size(size);
+ point.x = min(size.w - 1, point.x);
+ point.y = min(size.h - 1, point.y);
+
self.niri.screenshot_ui.pointer_motion(point);
}
@@ -1106,16 +1107,16 @@ impl State {
if let Some(output) = self.niri.screenshot_ui.selection_output() {
let geom = self.niri.global_space.output_geometry(output).unwrap();
- let mut point = pos;
- point.x = point
- .x
- .clamp(geom.loc.x as f64, (geom.loc.x + geom.size.w - 1) as f64);
- point.y = point
- .y
- .clamp(geom.loc.y as f64, (geom.loc.y + geom.size.h - 1) as f64);
- let point = (point - geom.loc.to_f64())
+ let mut point = (pos - geom.loc.to_f64())
.to_physical(output.current_scale().fractional_scale())
.to_i32_round();
+
+ let size = output.current_mode().unwrap().size;
+ let transform = output.current_transform();
+ let size = transform.transform_size(size);
+ point.x = min(size.w - 1, point.x);
+ point.y = min(size.h - 1, point.y);
+
self.niri.screenshot_ui.pointer_motion(point);
}
@@ -1277,18 +1278,16 @@ impl State {
if let Some((output, _)) = self.niri.output_under(pos) {
let output = output.clone();
let geom = self.niri.global_space.output_geometry(&output).unwrap();
- let mut point = pos;
- // Re-clamp as pointer can be within 0.5 from the limit which will round up
- // to a wrong value.
- point.x = point
- .x
- .clamp(geom.loc.x as f64, (geom.loc.x + geom.size.w - 1) as f64);
- point.y = point
- .y
- .clamp(geom.loc.y as f64, (geom.loc.y + geom.size.h - 1) as f64);
- let point = (point - geom.loc.to_f64())
+ let mut point = (pos - geom.loc.to_f64())
.to_physical(output.current_scale().fractional_scale())
.to_i32_round();
+
+ let size = output.current_mode().unwrap().size;
+ let transform = output.current_transform();
+ let size = transform.transform_size(size);
+ point.x = min(size.w - 1, point.x);
+ point.y = min(size.h - 1, point.y);
+
if self
.niri
.screenshot_ui