Activate windows when clicking on the border
Browse files at this commitb13892ca637cccfb496e3204b2793c069af17ccbParent: 777ad4e5 changed files +41 -9
- src/layout/mod.rs +8 -1
- src/layout/monitor.rs +2 -2
- src/layout/tile.rs +6 -1
- src/layout/workspace.rs +16 -5
- src/niri.rs +9 -0
src/layout/mod.rsmodified+8 -1
| @@ -920,11 +920,18 @@ impl<W: LayoutElement> Layout<W> { | |||
| 920 | monitors[*active_monitor_idx].focus() | 920 | monitors[*active_monitor_idx].focus() |
| 921 | } | 921 | } |
| 922 | 922 | ||
| 923 | + /// Returns the window under the cursor and the position of its toplevel surface within the | ||
| 924 | + /// output. | ||
| 925 | + /// | ||
| 926 | + /// `Some((w, Some(p)))` means that the cursor is within the window's input region and can be | ||
| 927 | + /// used for delivering events to the window. `Some((w, None))` means that the cursor is within | ||
| 928 | + /// the window's activation region, but not within the window's input region. For example, the | ||
| 929 | + /// cursor may be on the window's server-side border. | ||
| 923 | pub fn window_under( | 930 | pub fn window_under( |
| 924 | &self, | 931 | &self, |
| 925 | output: &Output, | 932 | output: &Output, |
| 926 | pos_within_output: Point<f64, Logical>, | 933 | pos_within_output: Point<f64, Logical>, |
| 927 | - ) -> Option<(&W, Point<i32, Logical>)> { | 934 | + ) -> Option<(&W, Option<Point<i32, Logical>>)> { |
| 928 | let MonitorSet::Normal { monitors, .. } = &self.monitor_set else { | 935 | let MonitorSet::Normal { monitors, .. } = &self.monitor_set else { |
| 929 | return None; | 936 | return None; |
| 930 | }; | 937 | }; |
src/layout/monitor.rsmodified+2 -2
| @@ -450,7 +450,7 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 450 | pub fn window_under( | 450 | pub fn window_under( |
| 451 | &self, | 451 | &self, |
| 452 | pos_within_output: Point<f64, Logical>, | 452 | pos_within_output: Point<f64, Logical>, |
| 453 | - ) -> Option<(&W, Point<i32, Logical>)> { | 453 | + ) -> Option<(&W, Option<Point<i32, Logical>>)> { |
| 454 | match &self.workspace_switch { | 454 | match &self.workspace_switch { |
| 455 | Some(switch) => { | 455 | Some(switch) => { |
| 456 | let size = output_size(&self.output); | 456 | let size = output_size(&self.output); |
| @@ -469,7 +469,7 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 469 | 469 | ||
| 470 | let ws = &self.workspaces[idx]; | 470 | let ws = &self.workspaces[idx]; |
| 471 | let (win, win_pos) = ws.window_under(pos_within_output + ws_offset.to_f64())?; | 471 | let (win, win_pos) = ws.window_under(pos_within_output + ws_offset.to_f64())?; |
| 472 | - Some((win, win_pos - ws_offset)) | 472 | + Some((win, win_pos.map(|p| p - ws_offset))) |
| 473 | } | 473 | } |
| 474 | None => { | 474 | None => { |
| 475 | let ws = &self.workspaces[self.active_workspace_idx]; | 475 | let ws = &self.workspaces[self.active_workspace_idx]; |
src/layout/tile.rsmodified+6 -1
| @@ -6,7 +6,7 @@ use smithay::backend::renderer::element::solid::{SolidColorBuffer, SolidColorRen | |||
| 6 | use smithay::backend::renderer::element::utils::{Relocate, RelocateRenderElement}; | 6 | use smithay::backend::renderer::element::utils::{Relocate, RelocateRenderElement}; |
| 7 | use smithay::backend::renderer::element::Kind; | 7 | use smithay::backend::renderer::element::Kind; |
| 8 | use smithay::backend::renderer::{ImportAll, Renderer}; | 8 | use smithay::backend::renderer::{ImportAll, Renderer}; |
| 9 | -use smithay::utils::{Logical, Point, Scale, Size}; | 9 | +use smithay::utils::{Logical, Point, Rectangle, Scale, Size}; |
| 10 | 10 | ||
| 11 | use super::focus_ring::FocusRing; | 11 | use super::focus_ring::FocusRing; |
| 12 | use super::workspace::WorkspaceRenderElement; | 12 | use super::workspace::WorkspaceRenderElement; |
| @@ -150,6 +150,11 @@ impl<W: LayoutElement> Tile<W> { | |||
| 150 | self.window.is_in_input_region(point) | 150 | self.window.is_in_input_region(point) |
| 151 | } | 151 | } |
| 152 | 152 | ||
| 153 | + pub fn is_in_activation_region(&self, point: Point<f64, Logical>) -> bool { | ||
| 154 | + let activation_region = Rectangle::from_loc_and_size((0, 0), self.tile_size()); | ||
| 155 | + activation_region.to_f64().contains(point) | ||
| 156 | + } | ||
| 157 | + | ||
| 153 | pub fn request_tile_size(&mut self, mut size: Size<i32, Logical>) { | 158 | pub fn request_tile_size(&mut self, mut size: Size<i32, Logical>) { |
| 154 | // Can't go through effective_border_width() because we might be fullscreen. | 159 | // Can't go through effective_border_width() because we might be fullscreen. |
| 155 | if !self.border.is_off() { | 160 | if !self.border.is_off() { |
src/layout/workspace.rsmodified+16 -5
| @@ -761,7 +761,10 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 761 | self.column_x(self.active_column_idx) + self.view_offset | 761 | self.column_x(self.active_column_idx) + self.view_offset |
| 762 | } | 762 | } |
| 763 | 763 | ||
| 764 | - pub fn window_under(&self, pos: Point<f64, Logical>) -> Option<(&W, Point<i32, Logical>)> { | 764 | + pub fn window_under( |
| 765 | + &self, | ||
| 766 | + pos: Point<f64, Logical>, | ||
| 767 | + ) -> Option<(&W, Option<Point<i32, Logical>>)> { | ||
| 765 | if self.columns.is_empty() { | 768 | if self.columns.is_empty() { |
| 766 | return None; | 769 | return None; |
| 767 | } | 770 | } |
| @@ -775,8 +778,12 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 775 | self.column_x(self.active_column_idx) - view_pos, | 778 | self.column_x(self.active_column_idx) - view_pos, |
| 776 | col.tile_y(col.active_tile_idx), | 779 | col.tile_y(col.active_tile_idx), |
| 777 | )); | 780 | )); |
| 778 | - if active_tile.is_in_input_region(pos - tile_pos.to_f64()) { | 781 | + let pos_within_tile = pos - tile_pos.to_f64(); |
| 779 | - return Some((active_tile.window(), tile_pos + active_tile.buf_loc())); | 782 | + if active_tile.is_in_input_region(pos_within_tile) { |
| 783 | + let pos_within_surface = tile_pos + active_tile.buf_loc(); | ||
| 784 | + return Some((active_tile.window(), Some(pos_within_surface))); | ||
| 785 | + } else if active_tile.is_in_activation_region(pos_within_tile) { | ||
| 786 | + return Some((active_tile.window(), None)); | ||
| 780 | } | 787 | } |
| 781 | 788 | ||
| 782 | let mut x = -view_pos; | 789 | let mut x = -view_pos; |
| @@ -788,8 +795,12 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 788 | } | 795 | } |
| 789 | 796 | ||
| 790 | let tile_pos = Point::from((x, y)); | 797 | let tile_pos = Point::from((x, y)); |
| 791 | - if tile.is_in_input_region(pos - tile_pos.to_f64()) { | 798 | + let pos_within_tile = pos - tile_pos.to_f64(); |
| 792 | - return Some((tile.window(), tile_pos + tile.buf_loc())); | 799 | + if tile.is_in_input_region(pos_within_tile) { |
| 800 | + let pos_within_surface = tile_pos + tile.buf_loc(); | ||
| 801 | + return Some((tile.window(), Some(pos_within_surface))); | ||
| 802 | + } else if tile.is_in_activation_region(pos_within_tile) { | ||
| 803 | + return Some((tile.window(), None)); | ||
| 793 | } | 804 | } |
| 794 | } | 805 | } |
| 795 | 806 | ||
src/niri.rsmodified+9 -0
| @@ -1035,6 +1035,10 @@ impl Niri { | |||
| 1035 | Some((output, pos_within_output)) | 1035 | Some((output, pos_within_output)) |
| 1036 | } | 1036 | } |
| 1037 | 1037 | ||
| 1038 | + /// Returns the window under the position to be activated. | ||
| 1039 | + /// | ||
| 1040 | + /// The cursor may be inside the window's activation region, but not within the window's input | ||
| 1041 | + /// region. | ||
| 1038 | pub fn window_under(&self, pos: Point<f64, Logical>) -> Option<&Window> { | 1042 | pub fn window_under(&self, pos: Point<f64, Logical>) -> Option<&Window> { |
| 1039 | if self.is_locked() || self.screenshot_ui.is_open() { | 1043 | if self.is_locked() || self.screenshot_ui.is_open() { |
| 1040 | return None; | 1044 | return None; |
| @@ -1045,6 +1049,10 @@ impl Niri { | |||
| 1045 | Some(window) | 1049 | Some(window) |
| 1046 | } | 1050 | } |
| 1047 | 1051 | ||
| 1052 | + /// Returns the window under the cursor to be activated. | ||
| 1053 | + /// | ||
| 1054 | + /// The cursor may be inside the window's activation region, but not within the window's input | ||
| 1055 | + /// region. | ||
| 1048 | pub fn window_under_cursor(&self) -> Option<&Window> { | 1056 | pub fn window_under_cursor(&self) -> Option<&Window> { |
| 1049 | let pos = self.seat.get_pointer().unwrap().current_location(); | 1057 | let pos = self.seat.get_pointer().unwrap().current_location(); |
| 1050 | self.window_under(pos) | 1058 | self.window_under(pos) |
| @@ -1103,6 +1111,7 @@ impl Niri { | |||
| 1103 | self.layout | 1111 | self.layout |
| 1104 | .window_under(output, pos_within_output) | 1112 | .window_under(output, pos_within_output) |
| 1105 | .and_then(|(window, win_pos_within_output)| { | 1113 | .and_then(|(window, win_pos_within_output)| { |
| 1114 | + let win_pos_within_output = win_pos_within_output?; | ||
| 1106 | window | 1115 | window |
| 1107 | .surface_under( | 1116 | .surface_under( |
| 1108 | pos_within_output - win_pos_within_output.to_f64(), | 1117 | pos_within_output - win_pos_within_output.to_f64(), |