aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/input/mod.rs82
-rw-r--r--src/ui/screenshot_ui.rs68
2 files changed, 82 insertions, 68 deletions
diff --git a/src/input/mod.rs b/src/input/mod.rs
index c9d2c4f2..9cc39f74 100644
--- a/src/input/mod.rs
+++ b/src/input/mod.rs
@@ -2564,25 +2564,27 @@ impl State {
}
if button == Some(MouseButton::Left) && self.niri.screenshot_ui.is_open() {
- let pos = pointer.current_location();
- 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())
- .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 button_state == ButtonState::Pressed {
+ let pos = pointer.current_location();
+ 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())
+ .to_physical(output.current_scale().fractional_scale())
+ .to_i32_round();
- let down = button_state == ButtonState::Pressed;
+ 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_button(output, point, down) {
- self.niri.queue_redraw_all();
+ if self.niri.screenshot_ui.pointer_down(output, point) {
+ self.niri.queue_redraw_all();
+ }
}
+ } else if self.niri.screenshot_ui.pointer_up() {
+ self.niri.queue_redraw_all();
}
}
@@ -3085,30 +3087,6 @@ impl State {
};
let tip_state = event.tip_state();
- if self.niri.screenshot_ui.is_open() {
- if let Some(pos) = self.niri.tablet_cursor_location {
- 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())
- .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);
-
- let down = tip_state == TabletToolTipState::Down;
-
- if self.niri.screenshot_ui.pointer_button(output, point, down) {
- self.niri.queue_redraw_all();
- }
- }
- }
- }
-
let is_overview_open = self.niri.layout.is_overview_open();
match tip_state {
@@ -3118,7 +3096,25 @@ impl State {
if let Some(pos) = self.niri.tablet_cursor_location {
let under = self.niri.contents_under(pos);
- if let Some((window, _)) = under.window {
+
+ 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())
+ .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) {
+ self.niri.queue_redraw_all();
+ }
+ }
+ } else if let Some((window, _)) = under.window {
if let Some(output) = is_overview_open.then_some(under.output).flatten() {
let mut workspaces = self.niri.layout.workspaces();
if let Some(ws_idx) = workspaces.find_map(|(_, ws_idx, ws)| {
@@ -3155,6 +3151,10 @@ impl State {
}
}
TabletToolTipState::Up => {
+ if self.niri.screenshot_ui.pointer_up() {
+ self.niri.queue_redraw_all();
+ }
+
tool.tip_up(event.time_msec());
}
}
diff --git a/src/ui/screenshot_ui.rs b/src/ui/screenshot_ui.rs
index 0718a3a1..2de3ddbc 100644
--- a/src/ui/screenshot_ui.rs
+++ b/src/ui/screenshot_ui.rs
@@ -673,12 +673,7 @@ impl ScreenshotUi {
self.update_buffers();
}
- pub fn pointer_button(
- &mut self,
- output: Output,
- point: Point<i32, Physical>,
- down: bool,
- ) -> bool {
+ pub fn pointer_down(&mut self, output: Output, point: Point<i32, Physical>) -> bool {
let Self::Open {
selection,
output_data,
@@ -689,34 +684,53 @@ impl ScreenshotUi {
return false;
};
- if *mouse_down == down {
+ if *mouse_down {
return false;
}
- if down && !output_data.contains_key(&output) {
+ if !output_data.contains_key(&output) {
return false;
}
- *mouse_down = down;
+ *mouse_down = true;
+ *selection = (output, point, point);
- if down {
- *selection = (output, point, point);
- } else {
- // Check if the resulting selection is zero-sized, and try to come up with a small
- // default rectangle.
- let (output, a, b) = selection;
- let mut rect = rect_from_corner_points(*a, *b);
- if rect.size.is_empty() || rect.size == Size::from((1, 1)) {
- let data = &output_data[output];
- rect = Rectangle::new(
- Point::from((rect.loc.x - 16, rect.loc.y - 16)),
- Size::from((32, 32)),
- )
- .intersection(Rectangle::from_size(data.size))
- .unwrap_or_default();
- *a = rect.loc;
- *b = rect.loc + rect.size - Size::from((1, 1));
- }
+ self.update_buffers();
+
+ true
+ }
+
+ pub fn pointer_up(&mut self) -> bool {
+ let Self::Open {
+ selection,
+ output_data,
+ mouse_down,
+ ..
+ } = self
+ else {
+ return false;
+ };
+
+ if !*mouse_down {
+ return false;
+ }
+
+ *mouse_down = false;
+
+ // Check if the resulting selection is zero-sized, and try to come up with a small
+ // default rectangle.
+ let (output, a, b) = selection;
+ let mut rect = rect_from_corner_points(*a, *b);
+ if rect.size.is_empty() || rect.size == Size::from((1, 1)) {
+ let data = &output_data[output];
+ rect = Rectangle::new(
+ Point::from((rect.loc.x - 16, rect.loc.y - 16)),
+ Size::from((32, 32)),
+ )
+ .intersection(Rectangle::from_size(data.size))
+ .unwrap_or_default();
+ *a = rect.loc;
+ *b = rect.loc + rect.size - Size::from((1, 1));
}
self.update_buffers();