forge
Explore
Log in

Don't you dare go Hollow

Implement top-left hot corner to toggle the Overview

Browse files at this commit

e6d82d3ee34a7ac225d07ca3f4f4365cf27292d1Ivan MolodetskikhParent: fae3a27
Compared to third-party implementations such as waycorner:

- It works during interactive window move (no surfaces receive pointer
  focus in this case, so this cannot work through layer-shell).
- It works during drag-and-drop.
- It disables itself over fullscreen windows.
- It does not prevent direct scanout.
niri-config/src/lib.rsmodified+11 -0
@@ -1210,6 +1210,8 @@ pub struct Gestures {
12101210 pub dnd_edge_view_scroll: DndEdgeViewScroll,
12111211 #[knuffel(child, default)]
12121212 pub dnd_edge_workspace_switch: DndEdgeWorkspaceSwitch,
1213+ #[knuffel(child, default)]
1214+ pub hot_corners: HotCorners,
12131215 }
12141216
12151217 #[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)]
@@ -1252,6 +1254,12 @@ impl Default for DndEdgeWorkspaceSwitch {
12521254 }
12531255 }
12541256
1257+#[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq)]
1258+pub struct HotCorners {
1259+ #[knuffel(child)]
1260+ pub off: bool,
1261+}
1262+
12551263 #[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)]
12561264 pub struct Overview {
12571265 #[knuffel(child, unwrap(argument), default = Self::default().zoom)]
@@ -4587,6 +4595,9 @@ mod tests {
45874595 1500.0,
45884596 ),
45894597 },
4598+ hot_corners: HotCorners {
4599+ off: false,
4600+ },
45904601 },
45914602 overview: Overview {
45924603 zoom: FloatOrInt(
src/input/mod.rsmodified+41 -1
@@ -29,7 +29,7 @@ use smithay::input::touch::{
2929 };
3030 use smithay::input::SeatHandler;
3131 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};
3333 use smithay::wayland::keyboard_shortcuts_inhibit::KeyboardShortcutsInhibitor;
3434 use smithay::wayland::pointer_constraints::{with_pointer_constraint, PointerConstraint};
3535 use smithay::wayland::selection::data_device::DnDGrab;
@@ -1995,6 +1995,10 @@ impl State {
19951995 }
19961996
19971997 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+
19982002 // We need an output to be able to move the pointer.
19992003 if self.niri.global_space.outputs().next().is_none() {
20002004 return;
@@ -2171,6 +2175,22 @@ impl State {
21712175
21722176 pointer.frame(self);
21732177
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+
21742194 // Activate a new confinement if necessary.
21752195 self.niri.maybe_activate_pointer_constraint();
21762196
@@ -2195,6 +2215,10 @@ impl State {
21952215 &mut self,
21962216 event: I::PointerMotionAbsoluteEvent,
21972217 ) {
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+
21982222 let Some(pos) = self.compute_absolute_location(&event, None).or_else(|| {
21992223 self.global_bounding_rectangle().map(|output_geo| {
22002224 event.position_transformed(output_geo.size) + output_geo.loc.to_f64()
@@ -2240,6 +2264,22 @@ impl State {
22402264
22412265 pointer.frame(self);
22422266
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+
22432283 self.niri.maybe_activate_pointer_constraint();
22442284
22452285 // We moved the pointer, show it.
src/niri.rsmodified+12 -0
@@ -347,6 +347,7 @@ pub struct Niri {
347347 /// Used for limiting the notify to once per iteration, so that it's not spammed with high
348348 /// resolution mice.
349349 pub notified_activity_this_iteration: bool,
350+ pub pointer_inside_hot_corner: bool,
350351 pub tablet_cursor_location: Option<Point<f64, Logical>>,
351352 pub gesture_swipe_3f_cumulative: Option<(f64, f64)>,
352353 pub overview_scroll_swipe_gesture: ScrollSwipeGesture,
@@ -2427,6 +2428,7 @@ impl Niri {
24272428 pointer_inactivity_timer: None,
24282429 pointer_inactivity_timer_got_reset: false,
24292430 notified_activity_this_iteration: false,
2431+ pointer_inside_hot_corner: false,
24302432 tablet_cursor_location: None,
24312433 gesture_swipe_3f_cumulative: None,
24322434 overview_scroll_swipe_gesture: ScrollSwipeGesture::new(),
@@ -2920,6 +2922,11 @@ impl Niri {
29202922 return false;
29212923 }
29222924
2925+ let hot_corner = Rectangle::from_size(Size::from((1., 1.)));
2926+ if hot_corner.contains(pos_within_output) {
2927+ return true;
2928+ }
2929+
29232930 if layer_popup_under(Layer::Top) || layer_toplevel_under(Layer::Top) {
29242931 return true;
29252932 }
@@ -3175,6 +3182,11 @@ impl Niri {
31753182 .or_else(|| layer_toplevel_under(Layer::Bottom))
31763183 .or_else(|| layer_toplevel_under(Layer::Background));
31773184 } 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+
31783190 under = under
31793191 .or_else(|| layer_popup_under(Layer::Top))
31803192 .or_else(|| layer_toplevel_under(Layer::Top));