Implement top-left hot corner to toggle the Overview
Browse files at this commite6d82d3ee34a7ac225d07ca3f4f4365cf27292d1Parent: fae3a273 changed files +64 -1
- niri-config/src/lib.rs +11 -0
- src/input/mod.rs +41 -1
- src/niri.rs +12 -0
niri-config/src/lib.rsmodified+11 -0
| @@ -1210,6 +1210,8 @@ pub struct Gestures { | |||
| 1210 | pub dnd_edge_view_scroll: DndEdgeViewScroll, | 1210 | pub dnd_edge_view_scroll: DndEdgeViewScroll, |
| 1211 | #[knuffel(child, default)] | 1211 | #[knuffel(child, default)] |
| 1212 | pub dnd_edge_workspace_switch: DndEdgeWorkspaceSwitch, | 1212 | pub dnd_edge_workspace_switch: DndEdgeWorkspaceSwitch, |
| 1213 | + #[knuffel(child, default)] | ||
| 1214 | + pub hot_corners: HotCorners, | ||
| 1213 | } | 1215 | } |
| 1214 | 1216 | ||
| 1215 | #[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)] | 1217 | #[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)] |
| @@ -1252,6 +1254,12 @@ impl Default for DndEdgeWorkspaceSwitch { | |||
| 1252 | } | 1254 | } |
| 1253 | } | 1255 | } |
| 1254 | 1256 | ||
| 1257 | +#[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq)] | ||
| 1258 | +pub struct HotCorners { | ||
| 1259 | + #[knuffel(child)] | ||
| 1260 | + pub off: bool, | ||
| 1261 | +} | ||
| 1262 | + | ||
| 1255 | #[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)] | 1263 | #[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)] |
| 1256 | pub struct Overview { | 1264 | pub struct Overview { |
| 1257 | #[knuffel(child, unwrap(argument), default = Self::default().zoom)] | 1265 | #[knuffel(child, unwrap(argument), default = Self::default().zoom)] |
| @@ -4587,6 +4595,9 @@ mod tests { | |||
| 4587 | 1500.0, | 4595 | 1500.0, |
| 4588 | ), | 4596 | ), |
| 4589 | }, | 4597 | }, |
| 4598 | + hot_corners: HotCorners { | ||
| 4599 | + off: false, | ||
| 4600 | + }, | ||
| 4590 | }, | 4601 | }, |
| 4591 | overview: Overview { | 4602 | overview: Overview { |
| 4592 | zoom: FloatOrInt( | 4603 | zoom: FloatOrInt( |
src/input/mod.rsmodified+41 -1
| @@ -29,7 +29,7 @@ use smithay::input::touch::{ | |||
| 29 | }; | 29 | }; |
| 30 | use smithay::input::SeatHandler; | 30 | use smithay::input::SeatHandler; |
| 31 | use smithay::output::Output; | 31 | use smithay::output::Output; |
| 32 | -use smithay::utils::{Logical, Point, Rectangle, Transform, SERIAL_COUNTER}; | 32 | +use smithay::utils::{Logical, Point, Rectangle, Size, Transform, SERIAL_COUNTER}; |
| 33 | use smithay::wayland::keyboard_shortcuts_inhibit::KeyboardShortcutsInhibitor; | 33 | use smithay::wayland::keyboard_shortcuts_inhibit::KeyboardShortcutsInhibitor; |
| 34 | use smithay::wayland::pointer_constraints::{with_pointer_constraint, PointerConstraint}; | 34 | use smithay::wayland::pointer_constraints::{with_pointer_constraint, PointerConstraint}; |
| 35 | use smithay::wayland::selection::data_device::DnDGrab; | 35 | use smithay::wayland::selection::data_device::DnDGrab; |
| @@ -1995,6 +1995,10 @@ impl State { | |||
| 1995 | } | 1995 | } |
| 1996 | 1996 | ||
| 1997 | fn on_pointer_motion<I: InputBackend>(&mut self, event: I::PointerMotionEvent) { | 1997 | fn on_pointer_motion<I: InputBackend>(&mut self, event: I::PointerMotionEvent) { |
| 1998 | + let was_inside_hot_corner = self.niri.pointer_inside_hot_corner; | ||
| 1999 | + // Any of the early returns here mean that the pointer is not inside the hot corner. | ||
| 2000 | + self.niri.pointer_inside_hot_corner = false; | ||
| 2001 | + | ||
| 1998 | // We need an output to be able to move the pointer. | 2002 | // We need an output to be able to move the pointer. |
| 1999 | if self.niri.global_space.outputs().next().is_none() { | 2003 | if self.niri.global_space.outputs().next().is_none() { |
| 2000 | return; | 2004 | return; |
| @@ -2171,6 +2175,22 @@ impl State { | |||
| 2171 | 2175 | ||
| 2172 | pointer.frame(self); | 2176 | pointer.frame(self); |
| 2173 | 2177 | ||
| 2178 | + // contents_under() will return no surface when the hot corner should trigger. | ||
| 2179 | + let hot_corners = self.niri.config.borrow().gestures.hot_corners; | ||
| 2180 | + if !hot_corners.off | ||
| 2181 | + && pointer.current_focus().is_none() | ||
| 2182 | + && !self.niri.screenshot_ui.is_open() | ||
| 2183 | + { | ||
| 2184 | + let hot_corner = Rectangle::from_size(Size::from((1., 1.))); | ||
| 2185 | + if let Some((_, pos_within_output)) = self.niri.output_under(pos) { | ||
| 2186 | + let inside_hot_corner = hot_corner.contains(pos_within_output); | ||
| 2187 | + if inside_hot_corner && !was_inside_hot_corner { | ||
| 2188 | + self.niri.layout.toggle_overview(); | ||
| 2189 | + } | ||
| 2190 | + self.niri.pointer_inside_hot_corner = inside_hot_corner; | ||
| 2191 | + } | ||
| 2192 | + } | ||
| 2193 | + | ||
| 2174 | // Activate a new confinement if necessary. | 2194 | // Activate a new confinement if necessary. |
| 2175 | self.niri.maybe_activate_pointer_constraint(); | 2195 | self.niri.maybe_activate_pointer_constraint(); |
| 2176 | 2196 | ||
| @@ -2195,6 +2215,10 @@ impl State { | |||
| 2195 | &mut self, | 2215 | &mut self, |
| 2196 | event: I::PointerMotionAbsoluteEvent, | 2216 | event: I::PointerMotionAbsoluteEvent, |
| 2197 | ) { | 2217 | ) { |
| 2218 | + let was_inside_hot_corner = self.niri.pointer_inside_hot_corner; | ||
| 2219 | + // Any of the early returns here mean that the pointer is not inside the hot corner. | ||
| 2220 | + self.niri.pointer_inside_hot_corner = false; | ||
| 2221 | + | ||
| 2198 | let Some(pos) = self.compute_absolute_location(&event, None).or_else(|| { | 2222 | let Some(pos) = self.compute_absolute_location(&event, None).or_else(|| { |
| 2199 | self.global_bounding_rectangle().map(|output_geo| { | 2223 | self.global_bounding_rectangle().map(|output_geo| { |
| 2200 | event.position_transformed(output_geo.size) + output_geo.loc.to_f64() | 2224 | event.position_transformed(output_geo.size) + output_geo.loc.to_f64() |
| @@ -2240,6 +2264,22 @@ impl State { | |||
| 2240 | 2264 | ||
| 2241 | pointer.frame(self); | 2265 | pointer.frame(self); |
| 2242 | 2266 | ||
| 2267 | + // contents_under() will return no surface when the hot corner should trigger. | ||
| 2268 | + let hot_corners = self.niri.config.borrow().gestures.hot_corners; | ||
| 2269 | + if !hot_corners.off | ||
| 2270 | + && pointer.current_focus().is_none() | ||
| 2271 | + && !self.niri.screenshot_ui.is_open() | ||
| 2272 | + { | ||
| 2273 | + let hot_corner = Rectangle::from_size(Size::from((1., 1.))); | ||
| 2274 | + if let Some((_, pos_within_output)) = self.niri.output_under(pos) { | ||
| 2275 | + let inside_hot_corner = hot_corner.contains(pos_within_output); | ||
| 2276 | + if inside_hot_corner && !was_inside_hot_corner { | ||
| 2277 | + self.niri.layout.toggle_overview(); | ||
| 2278 | + } | ||
| 2279 | + self.niri.pointer_inside_hot_corner = inside_hot_corner; | ||
| 2280 | + } | ||
| 2281 | + } | ||
| 2282 | + | ||
| 2243 | self.niri.maybe_activate_pointer_constraint(); | 2283 | self.niri.maybe_activate_pointer_constraint(); |
| 2244 | 2284 | ||
| 2245 | // We moved the pointer, show it. | 2285 | // We moved the pointer, show it. |
src/niri.rsmodified+12 -0
| @@ -347,6 +347,7 @@ pub struct Niri { | |||
| 347 | /// Used for limiting the notify to once per iteration, so that it's not spammed with high | 347 | /// Used for limiting the notify to once per iteration, so that it's not spammed with high |
| 348 | /// resolution mice. | 348 | /// resolution mice. |
| 349 | pub notified_activity_this_iteration: bool, | 349 | pub notified_activity_this_iteration: bool, |
| 350 | + pub pointer_inside_hot_corner: bool, | ||
| 350 | pub tablet_cursor_location: Option<Point<f64, Logical>>, | 351 | pub tablet_cursor_location: Option<Point<f64, Logical>>, |
| 351 | pub gesture_swipe_3f_cumulative: Option<(f64, f64)>, | 352 | pub gesture_swipe_3f_cumulative: Option<(f64, f64)>, |
| 352 | pub overview_scroll_swipe_gesture: ScrollSwipeGesture, | 353 | pub overview_scroll_swipe_gesture: ScrollSwipeGesture, |
| @@ -2427,6 +2428,7 @@ impl Niri { | |||
| 2427 | pointer_inactivity_timer: None, | 2428 | pointer_inactivity_timer: None, |
| 2428 | pointer_inactivity_timer_got_reset: false, | 2429 | pointer_inactivity_timer_got_reset: false, |
| 2429 | notified_activity_this_iteration: false, | 2430 | notified_activity_this_iteration: false, |
| 2431 | + pointer_inside_hot_corner: false, | ||
| 2430 | tablet_cursor_location: None, | 2432 | tablet_cursor_location: None, |
| 2431 | gesture_swipe_3f_cumulative: None, | 2433 | gesture_swipe_3f_cumulative: None, |
| 2432 | overview_scroll_swipe_gesture: ScrollSwipeGesture::new(), | 2434 | overview_scroll_swipe_gesture: ScrollSwipeGesture::new(), |
| @@ -2920,6 +2922,11 @@ impl Niri { | |||
| 2920 | return false; | 2922 | return false; |
| 2921 | } | 2923 | } |
| 2922 | 2924 | ||
| 2925 | + let hot_corner = Rectangle::from_size(Size::from((1., 1.))); | ||
| 2926 | + if hot_corner.contains(pos_within_output) { | ||
| 2927 | + return true; | ||
| 2928 | + } | ||
| 2929 | + | ||
| 2923 | if layer_popup_under(Layer::Top) || layer_toplevel_under(Layer::Top) { | 2930 | if layer_popup_under(Layer::Top) || layer_toplevel_under(Layer::Top) { |
| 2924 | return true; | 2931 | return true; |
| 2925 | } | 2932 | } |
| @@ -3175,6 +3182,11 @@ impl Niri { | |||
| 3175 | .or_else(|| layer_toplevel_under(Layer::Bottom)) | 3182 | .or_else(|| layer_toplevel_under(Layer::Bottom)) |
| 3176 | .or_else(|| layer_toplevel_under(Layer::Background)); | 3183 | .or_else(|| layer_toplevel_under(Layer::Background)); |
| 3177 | } else { | 3184 | } else { |
| 3185 | + let hot_corner = Rectangle::from_size(Size::from((1., 1.))); | ||
| 3186 | + if hot_corner.contains(pos_within_output) { | ||
| 3187 | + return rv; | ||
| 3188 | + } | ||
| 3189 | + | ||
| 3178 | under = under | 3190 | under = under |
| 3179 | .or_else(|| layer_popup_under(Layer::Top)) | 3191 | .or_else(|| layer_popup_under(Layer::Top)) |
| 3180 | .or_else(|| layer_toplevel_under(Layer::Top)); | 3192 | .or_else(|| layer_toplevel_under(Layer::Top)); |