mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-22 02:01:55 +07:00
Split ScreenshotUi::pointer_down() and up()
This commit is contained in:
+22
-22
@@ -2564,6 +2564,7 @@ impl State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if button == Some(MouseButton::Left) && self.niri.screenshot_ui.is_open() {
|
if button == Some(MouseButton::Left) && self.niri.screenshot_ui.is_open() {
|
||||||
|
if button_state == ButtonState::Pressed {
|
||||||
let pos = pointer.current_location();
|
let pos = pointer.current_location();
|
||||||
if let Some((output, _)) = self.niri.output_under(pos) {
|
if let Some((output, _)) = self.niri.output_under(pos) {
|
||||||
let output = output.clone();
|
let output = output.clone();
|
||||||
@@ -2578,12 +2579,13 @@ impl State {
|
|||||||
point.x = min(size.w - 1, point.x);
|
point.x = min(size.w - 1, point.x);
|
||||||
point.y = min(size.h - 1, point.y);
|
point.y = min(size.h - 1, point.y);
|
||||||
|
|
||||||
let down = button_state == ButtonState::Pressed;
|
if self.niri.screenshot_ui.pointer_down(output, point) {
|
||||||
|
|
||||||
if self.niri.screenshot_ui.pointer_button(output, point, down) {
|
|
||||||
self.niri.queue_redraw_all();
|
self.niri.queue_redraw_all();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if self.niri.screenshot_ui.pointer_up() {
|
||||||
|
self.niri.queue_redraw_all();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pointer.button(
|
pointer.button(
|
||||||
@@ -3085,10 +3087,18 @@ impl State {
|
|||||||
};
|
};
|
||||||
let tip_state = event.tip_state();
|
let tip_state = event.tip_state();
|
||||||
|
|
||||||
if self.niri.screenshot_ui.is_open() {
|
let is_overview_open = self.niri.layout.is_overview_open();
|
||||||
|
|
||||||
|
match tip_state {
|
||||||
|
TabletToolTipState::Down => {
|
||||||
|
let serial = SERIAL_COUNTER.next_serial();
|
||||||
|
tool.tip_down(serial, event.time_msec());
|
||||||
|
|
||||||
if let Some(pos) = self.niri.tablet_cursor_location {
|
if let Some(pos) = self.niri.tablet_cursor_location {
|
||||||
if let Some((output, _)) = self.niri.output_under(pos) {
|
let under = self.niri.contents_under(pos);
|
||||||
let output = output.clone();
|
|
||||||
|
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 geom = self.niri.global_space.output_geometry(&output).unwrap();
|
||||||
let mut point = (pos - geom.loc.to_f64())
|
let mut point = (pos - geom.loc.to_f64())
|
||||||
.to_physical(output.current_scale().fractional_scale())
|
.to_physical(output.current_scale().fractional_scale())
|
||||||
@@ -3100,25 +3110,11 @@ impl State {
|
|||||||
point.x = min(size.w - 1, point.x);
|
point.x = min(size.w - 1, point.x);
|
||||||
point.y = min(size.h - 1, point.y);
|
point.y = min(size.h - 1, point.y);
|
||||||
|
|
||||||
let down = tip_state == TabletToolTipState::Down;
|
if self.niri.screenshot_ui.pointer_down(output, point) {
|
||||||
|
|
||||||
if self.niri.screenshot_ui.pointer_button(output, point, down) {
|
|
||||||
self.niri.queue_redraw_all();
|
self.niri.queue_redraw_all();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if let Some((window, _)) = under.window {
|
||||||
}
|
|
||||||
|
|
||||||
let is_overview_open = self.niri.layout.is_overview_open();
|
|
||||||
|
|
||||||
match tip_state {
|
|
||||||
TabletToolTipState::Down => {
|
|
||||||
let serial = SERIAL_COUNTER.next_serial();
|
|
||||||
tool.tip_down(serial, event.time_msec());
|
|
||||||
|
|
||||||
if let Some(pos) = self.niri.tablet_cursor_location {
|
|
||||||
let under = self.niri.contents_under(pos);
|
|
||||||
if let Some((window, _)) = under.window {
|
|
||||||
if let Some(output) = is_overview_open.then_some(under.output).flatten() {
|
if let Some(output) = is_overview_open.then_some(under.output).flatten() {
|
||||||
let mut workspaces = self.niri.layout.workspaces();
|
let mut workspaces = self.niri.layout.workspaces();
|
||||||
if let Some(ws_idx) = workspaces.find_map(|(_, ws_idx, ws)| {
|
if let Some(ws_idx) = workspaces.find_map(|(_, ws_idx, ws)| {
|
||||||
@@ -3155,6 +3151,10 @@ impl State {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
TabletToolTipState::Up => {
|
TabletToolTipState::Up => {
|
||||||
|
if self.niri.screenshot_ui.pointer_up() {
|
||||||
|
self.niri.queue_redraw_all();
|
||||||
|
}
|
||||||
|
|
||||||
tool.tip_up(event.time_msec());
|
tool.tip_up(event.time_msec());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-13
@@ -673,12 +673,7 @@ impl ScreenshotUi {
|
|||||||
self.update_buffers();
|
self.update_buffers();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pointer_button(
|
pub fn pointer_down(&mut self, output: Output, point: Point<i32, Physical>) -> bool {
|
||||||
&mut self,
|
|
||||||
output: Output,
|
|
||||||
point: Point<i32, Physical>,
|
|
||||||
down: bool,
|
|
||||||
) -> bool {
|
|
||||||
let Self::Open {
|
let Self::Open {
|
||||||
selection,
|
selection,
|
||||||
output_data,
|
output_data,
|
||||||
@@ -689,19 +684,39 @@ impl ScreenshotUi {
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
if *mouse_down == down {
|
if *mouse_down {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if down && !output_data.contains_key(&output) {
|
if !output_data.contains_key(&output) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
*mouse_down = down;
|
*mouse_down = true;
|
||||||
|
|
||||||
if down {
|
|
||||||
*selection = (output, point, point);
|
*selection = (output, point, point);
|
||||||
} else {
|
|
||||||
|
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
|
// Check if the resulting selection is zero-sized, and try to come up with a small
|
||||||
// default rectangle.
|
// default rectangle.
|
||||||
let (output, a, b) = selection;
|
let (output, a, b) = selection;
|
||||||
@@ -717,7 +732,6 @@ impl ScreenshotUi {
|
|||||||
*a = rect.loc;
|
*a = rect.loc;
|
||||||
*b = rect.loc + rect.size - Size::from((1, 1));
|
*b = rect.loc + rect.size - Size::from((1, 1));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
self.update_buffers();
|
self.update_buffers();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user