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:
+41
-41
@@ -2564,25 +2564,27 @@ impl State {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if button == Some(MouseButton::Left) && self.niri.screenshot_ui.is_open() {
|
if button == Some(MouseButton::Left) && self.niri.screenshot_ui.is_open() {
|
||||||
let pos = pointer.current_location();
|
if button_state == ButtonState::Pressed {
|
||||||
if let Some((output, _)) = self.niri.output_under(pos) {
|
let pos = pointer.current_location();
|
||||||
let output = output.clone();
|
if let Some((output, _)) = self.niri.output_under(pos) {
|
||||||
let geom = self.niri.global_space.output_geometry(&output).unwrap();
|
let output = output.clone();
|
||||||
let mut point = (pos - geom.loc.to_f64())
|
let geom = self.niri.global_space.output_geometry(&output).unwrap();
|
||||||
.to_physical(output.current_scale().fractional_scale())
|
let mut point = (pos - geom.loc.to_f64())
|
||||||
.to_i32_round();
|
.to_physical(output.current_scale().fractional_scale())
|
||||||
|
.to_i32_round();
|
||||||
|
|
||||||
let size = output.current_mode().unwrap().size;
|
let size = output.current_mode().unwrap().size;
|
||||||
let transform = output.current_transform();
|
let transform = output.current_transform();
|
||||||
let size = transform.transform_size(size);
|
let size = transform.transform_size(size);
|
||||||
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) {
|
||||||
|
self.niri.queue_redraw_all();
|
||||||
if self.niri.screenshot_ui.pointer_button(output, point, down) {
|
}
|
||||||
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();
|
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();
|
let is_overview_open = self.niri.layout.is_overview_open();
|
||||||
|
|
||||||
match tip_state {
|
match tip_state {
|
||||||
@@ -3118,7 +3096,25 @@ impl State {
|
|||||||
|
|
||||||
if let Some(pos) = self.niri.tablet_cursor_location {
|
if let Some(pos) = self.niri.tablet_cursor_location {
|
||||||
let under = self.niri.contents_under(pos);
|
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() {
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+41
-27
@@ -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,34 +684,53 @@ 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;
|
||||||
|
*selection = (output, point, point);
|
||||||
|
|
||||||
if down {
|
self.update_buffers();
|
||||||
*selection = (output, point, point);
|
|
||||||
} else {
|
true
|
||||||
// Check if the resulting selection is zero-sized, and try to come up with a small
|
}
|
||||||
// default rectangle.
|
|
||||||
let (output, a, b) = selection;
|
pub fn pointer_up(&mut self) -> bool {
|
||||||
let mut rect = rect_from_corner_points(*a, *b);
|
let Self::Open {
|
||||||
if rect.size.is_empty() || rect.size == Size::from((1, 1)) {
|
selection,
|
||||||
let data = &output_data[output];
|
output_data,
|
||||||
rect = Rectangle::new(
|
mouse_down,
|
||||||
Point::from((rect.loc.x - 16, rect.loc.y - 16)),
|
..
|
||||||
Size::from((32, 32)),
|
} = self
|
||||||
)
|
else {
|
||||||
.intersection(Rectangle::from_size(data.size))
|
return false;
|
||||||
.unwrap_or_default();
|
};
|
||||||
*a = rect.loc;
|
|
||||||
*b = rect.loc + rect.size - Size::from((1, 1));
|
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();
|
self.update_buffers();
|
||||||
|
|||||||
Reference in New Issue
Block a user