mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-21 02:01:55 +07:00
Clamp pointer to output inside screenshot_ui
- Removes some duplication - Allows for better handling by screenshot UI itself depending on the case
This commit is contained in:
+7
-50
@@ -1,5 +1,4 @@
|
||||
use std::any::Any;
|
||||
use std::cmp::min;
|
||||
use std::collections::hash_map::Entry;
|
||||
use std::collections::HashSet;
|
||||
use std::time::Duration;
|
||||
@@ -2547,16 +2546,10 @@ 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 - geom.loc.to_f64())
|
||||
let point = (new_pos - geom.loc.to_f64())
|
||||
.to_physical(output.current_scale().fractional_scale())
|
||||
.to_i32_round::<i32>();
|
||||
|
||||
let size = output.current_mode().unwrap().size;
|
||||
let transform = output.current_transform();
|
||||
let size = transform.transform_size(size);
|
||||
point.x = point.x.clamp(0, size.w - 1);
|
||||
point.y = point.y.clamp(0, size.h - 1);
|
||||
|
||||
self.niri.screenshot_ui.pointer_motion(point, None);
|
||||
}
|
||||
|
||||
@@ -2684,16 +2677,10 @@ 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 - geom.loc.to_f64())
|
||||
let point = (pos - geom.loc.to_f64())
|
||||
.to_physical(output.current_scale().fractional_scale())
|
||||
.to_i32_round::<i32>();
|
||||
|
||||
let size = output.current_mode().unwrap().size;
|
||||
let transform = output.current_transform();
|
||||
let size = transform.transform_size(size);
|
||||
point.x = point.x.clamp(0, size.w - 1);
|
||||
point.y = point.y.clamp(0, size.h - 1);
|
||||
|
||||
self.niri.screenshot_ui.pointer_motion(point, None);
|
||||
}
|
||||
|
||||
@@ -3044,16 +3031,10 @@ 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 - geom.loc.to_f64())
|
||||
let 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.pointer_down(output, point, None) {
|
||||
self.niri.queue_redraw_all();
|
||||
}
|
||||
@@ -3570,16 +3551,10 @@ 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 - geom.loc.to_f64())
|
||||
let point = (pos - geom.loc.to_f64())
|
||||
.to_physical(output.current_scale().fractional_scale())
|
||||
.to_i32_round::<i32>();
|
||||
|
||||
let size = output.current_mode().unwrap().size;
|
||||
let transform = output.current_transform();
|
||||
let size = transform.transform_size(size);
|
||||
point.x = point.x.clamp(0, size.w - 1);
|
||||
point.y = point.y.clamp(0, size.h - 1);
|
||||
|
||||
self.niri.screenshot_ui.pointer_motion(point, None);
|
||||
}
|
||||
|
||||
@@ -3654,16 +3629,10 @@ impl State {
|
||||
if self.niri.screenshot_ui.is_open() {
|
||||
if let Some(output) = under.output.clone() {
|
||||
let geom = self.niri.global_space.output_geometry(&output).unwrap();
|
||||
let mut point = (pos - geom.loc.to_f64())
|
||||
let 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.pointer_down(output, point, None) {
|
||||
self.niri.queue_redraw_all();
|
||||
}
|
||||
@@ -4130,16 +4099,10 @@ impl State {
|
||||
if self.niri.screenshot_ui.is_open() {
|
||||
if let Some(output) = under.output.clone() {
|
||||
let geom = self.niri.global_space.output_geometry(&output).unwrap();
|
||||
let mut point = (pos - geom.loc.to_f64())
|
||||
let 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
|
||||
@@ -4278,16 +4241,10 @@ impl State {
|
||||
|
||||
if let Some(output) = self.niri.screenshot_ui.selection_output().cloned() {
|
||||
let geom = self.niri.global_space.output_geometry(&output).unwrap();
|
||||
let mut point = (pos - geom.loc.to_f64())
|
||||
let point = (pos - geom.loc.to_f64())
|
||||
.to_physical(output.current_scale().fractional_scale())
|
||||
.to_i32_round::<i32>();
|
||||
|
||||
let size = output.current_mode().unwrap().size;
|
||||
let transform = output.current_transform();
|
||||
let size = transform.transform_size(size);
|
||||
point.x = point.x.clamp(0, size.w - 1);
|
||||
point.y = point.y.clamp(0, size.h - 1);
|
||||
|
||||
self.niri.screenshot_ui.pointer_motion(point, Some(slot));
|
||||
self.niri.queue_redraw(&output);
|
||||
}
|
||||
|
||||
@@ -799,6 +799,8 @@ impl ScreenshotUi {
|
||||
}
|
||||
|
||||
/// The pointer has moved to `point` relative to the current selection output.
|
||||
///
|
||||
/// The point may be outside output bounds.
|
||||
pub fn pointer_motion(&mut self, point: Point<i32, Physical>, slot: Option<TouchSlot>) {
|
||||
let Self::Open {
|
||||
selection,
|
||||
@@ -838,7 +840,8 @@ impl ScreenshotUi {
|
||||
selection.1 += delta;
|
||||
selection.2 += delta;
|
||||
} else {
|
||||
selection.2 = point;
|
||||
let size = output_data[&selection.0].size;
|
||||
selection.2 = Point::new(point.x.clamp(0, size.w - 1), point.y.clamp(0, size.h - 1));
|
||||
}
|
||||
|
||||
self.update_buffers();
|
||||
@@ -909,6 +912,11 @@ impl ScreenshotUi {
|
||||
last_pos: (output.clone(), point),
|
||||
move_state: None,
|
||||
};
|
||||
|
||||
let point = Point::new(
|
||||
point.x.clamp(0, output_data.size.w - 1),
|
||||
point.y.clamp(0, output_data.size.h - 1),
|
||||
);
|
||||
*selection = (output, point, point);
|
||||
|
||||
self.update_buffers();
|
||||
|
||||
Reference in New Issue
Block a user