forge
Explore
Log in

Don't you dare go Hollow

Make hot corners configurable, including per-output (#2108)

Browse files at this commit

08f5c6fecb3c5c81d63a0bf7248c85ae3299a4a5UnverifiedKai Koehler and Aadniz, Ivan MolodetskikhParent: bffc5c1
* Add corner selection in config

* Add hot corner docs

* Working per-monitor hot corners

Handle defaults

* run cargo fmt --all

* Fix hot corners in is_sticky_obscured_under

* Change default to fall back to gesture hot corners if output hot corners are unset

* Add hot corner output config docs

* Support fractional scaling

* Trigger hot corners over widgets

* Improve float handling
Fixed YaLTeR/niri/pull/2108

* Refactor

* Bug Fixes

* Amend docs

Fix styling

Co-authored-by: Ivan Molodetskikh <yalterz@gmail.com>

* Integrate code review

Move is_inside_hot_corner

* fixes

---------
docs/wiki/Configuration:-Gestures.mdmodified+19 -0
@@ -23,6 +23,10 @@ gestures {
23 23
24 hot-corners {24 hot-corners {
25 // off25 // off
26+ top-left
27+ // top-right
28+ // bottom-left
29+ // bottom-right
26 }30 }
27 }31 }
28 ```32 ```
@@ -94,3 +98,18 @@ gestures {
94 }98 }
95 }99 }
96 ```100 ```
101+
102+<sup>Since: next release</sup> You can choose specific hot corners by name: `top-left`, `top-right`, `bottom-left`, `bottom-right`.
103+If no corners are explicitly set, the top-left corner will be active by default.
104+
105+```kdl
106+// Enable the top-right and bottom-right hot corners.
107+gestures {
108+ hot-corners {
109+ top-right
110+ bottom-right
111+ }
112+}
113+```
114+
115+You can also customize hot corners per-output [in the output config](./Configuration:-Outputs.md#hot-corners).
docs/wiki/Configuration:-Outputs.mdmodified+36 -0
@@ -16,6 +16,14 @@ output "eDP-1" {
16 focus-at-startup16 focus-at-startup
17 background-color "#003300"17 background-color "#003300"
18 backdrop-color "#001100"18 backdrop-color "#001100"
19+
20+ hot-corners {
21+ // off
22+ top-left
23+ // top-right
24+ // bottom-left
25+ // bottom-right
26+ }
19 }27 }
20 28
21 output "HDMI-A-1" {29 output "HDMI-A-1" {
@@ -217,3 +225,31 @@ output "HDMI-A-1" {
217 backdrop-color "#001100"225 backdrop-color "#001100"
218 }226 }
219 ```227 ```
228+
229+### `hot-corners`
230+
231+<sup>Since: next release</sup>
232+
233+Customize the hot corners for this output.
234+By default, hot corners [in the gestures settings](./Configuration:-Gestures.md#hot-corners) are used for all outputs.
235+
236+Hot corners toggle the overview when you put your mouse at the very corner of a monitor.
237+
238+`off` will disable the hot corners on this output, and writing specific corners will enable only those hot corners on this output.
239+
240+```kdl
241+// Enable the bottom-left and bottom-right hot corners on HDMI-A-1.
242+output "HDMI-A-1" {
243+ hot-corners {
244+ bottom-left
245+ bottom-right
246+ }
247+}
248+
249+// Disable the hot corners on DP-2.
250+output "DP-2" {
251+ hot-corners {
252+ off
253+ }
254+}
255+```
niri-config/src/gestures.rsmodified+8 -0
@@ -54,4 +54,12 @@ impl Default for DndEdgeWorkspaceSwitch {
54 pub struct HotCorners {54 pub struct HotCorners {
55 #[knuffel(child)]55 #[knuffel(child)]
56 pub off: bool,56 pub off: bool,
57+ #[knuffel(child)]
58+ pub top_left: bool,
59+ #[knuffel(child)]
60+ pub top_right: bool,
61+ #[knuffel(child)]
62+ pub bottom_left: bool,
63+ #[knuffel(child)]
64+ pub bottom_right: bool,
57 }65 }
niri-config/src/lib.rsmodified+20 -0
@@ -348,6 +348,13 @@ mod tests {
348 mode "1920x1080@144"348 mode "1920x1080@144"
349 variable-refresh-rate on-demand=true349 variable-refresh-rate on-demand=true
350 background-color "rgba(25, 25, 102, 1.0)"350 background-color "rgba(25, 25, 102, 1.0)"
351+ hot-corners {
352+ off
353+ top-left
354+ top-right
355+ bottom-left
356+ bottom-right
357+ }
351 }358 }
352 359
353 layout {360 layout {
@@ -742,6 +749,15 @@ mod tests {
742 },749 },
743 ),750 ),
744 backdrop_color: None,751 backdrop_color: None,
752+ hot_corners: Some(
753+ HotCorners {
754+ off: true,
755+ top_left: true,
756+ top_right: true,
757+ bottom_left: true,
758+ bottom_right: true,
759+ },
760+ ),
745 },761 },
746 ],762 ],
747 ),763 ),
@@ -1158,6 +1174,10 @@ mod tests {
1158 },1174 },
1159 hot_corners: HotCorners {1175 hot_corners: HotCorners {
1160 off: false,1176 off: false,
1177+ top_left: false,
1178+ top_right: false,
1179+ bottom_left: false,
1180+ bottom_right: false,
1161 },1181 },
1162 },1182 },
1163 overview: Overview {1183 overview: Overview {
niri-config/src/output.rsmodified+4 -0
@@ -1,5 +1,6 @@
1 use niri_ipc::{ConfiguredMode, Transform};1 use niri_ipc::{ConfiguredMode, Transform};
2 2
3+use crate::gestures::HotCorners;
3 use crate::{Color, FloatOrInt};4 use crate::{Color, FloatOrInt};
4 5
5 #[derive(Debug, Default, Clone, PartialEq)]6 #[derive(Debug, Default, Clone, PartialEq)]
@@ -27,6 +28,8 @@ pub struct Output {
27 pub background_color: Option<Color>,28 pub background_color: Option<Color>,
28 #[knuffel(child)]29 #[knuffel(child)]
29 pub backdrop_color: Option<Color>,30 pub backdrop_color: Option<Color>,
31+ #[knuffel(child)]
32+ pub hot_corners: Option<HotCorners>,
30 }33 }
31 34
32 impl Output {35 impl Output {
@@ -56,6 +59,7 @@ impl Default for Output {
56 variable_refresh_rate: None,59 variable_refresh_rate: None,
57 background_color: None,60 background_color: None,
58 backdrop_color: None,61 backdrop_color: None,
62+ hot_corners: None,
59 }63 }
60 }64 }
61 }65 }
src/niri.rsmodified+48 -13
@@ -3118,6 +3118,49 @@ impl Niri {
3118 Some((output, pos_within_output))3118 Some((output, pos_within_output))
3119 }3119 }
3120 3120
3121+ fn is_inside_hot_corner(&self, output: &Output, pos: Point<f64, Logical>) -> bool {
3122+ let config = self.config.borrow();
3123+ let hot_corners = output
3124+ .user_data()
3125+ .get::<OutputName>()
3126+ .and_then(|name| config.outputs.find(name))
3127+ .and_then(|c| c.hot_corners)
3128+ .unwrap_or(config.gestures.hot_corners);
3129+
3130+ if hot_corners.off {
3131+ return false;
3132+ }
3133+
3134+ // Use size from the ceiled output geometry, since that's what we currently use for pointer
3135+ // motion clamping.
3136+ let geom = self.global_space.output_geometry(output).unwrap();
3137+ let size = geom.size.to_f64();
3138+
3139+ let contains = move |corner: Point<f64, Logical>| {
3140+ Rectangle::new(corner, Size::new(1., 1.)).contains(pos)
3141+ };
3142+
3143+ if hot_corners.top_right && contains(Point::new(size.w - 1., 0.)) {
3144+ return true;
3145+ }
3146+ if hot_corners.bottom_left && contains(Point::new(0., size.h - 1.)) {
3147+ return true;
3148+ }
3149+ if hot_corners.bottom_right && contains(Point::new(size.w - 1., size.h - 1.)) {
3150+ return true;
3151+ }
3152+
3153+ // If the user didn't explicitly set any corners, we default to top-left.
3154+ if (hot_corners.top_left
3155+ || !(hot_corners.top_right || hot_corners.bottom_right || hot_corners.bottom_left))
3156+ && contains(Point::new(0., 0.))
3157+ {
3158+ return true;
3159+ }
3160+
3161+ false
3162+ }
3163+
3121 pub fn is_sticky_obscured_under(3164 pub fn is_sticky_obscured_under(
3122 &self,3165 &self,
3123 output: &Output,3166 output: &Output,
@@ -3161,12 +3204,8 @@ impl Niri {
3161 return false;3204 return false;
3162 }3205 }
3163 3206
3164- let hot_corners = self.config.borrow().gestures.hot_corners;3207+ if self.is_inside_hot_corner(output, pos_within_output) {
3165- if !hot_corners.off {3208+ return true;
3166- let hot_corner = Rectangle::from_size(Size::from((1., 1.)));
3167- if hot_corner.contains(pos_within_output) {
3168- return true;
3169- }
3170 }3209 }
3171 3210
3172 if layer_popup_under(Layer::Top) || layer_toplevel_under(Layer::Top) {3211 if layer_popup_under(Layer::Top) || layer_toplevel_under(Layer::Top) {
@@ -3438,13 +3477,9 @@ impl Niri {
3438 .or_else(|| layer_toplevel_under(Layer::Bottom))3477 .or_else(|| layer_toplevel_under(Layer::Bottom))
3439 .or_else(|| layer_toplevel_under(Layer::Background));3478 .or_else(|| layer_toplevel_under(Layer::Background));
3440 } else {3479 } else {
3441- let hot_corners = self.config.borrow().gestures.hot_corners;3480+ if self.is_inside_hot_corner(output, pos_within_output) {
3442- if !hot_corners.off {3481+ rv.hot_corner = true;
3443- let hot_corner = Rectangle::from_size(Size::from((1., 1.)));3482+ return rv;
3444- if hot_corner.contains(pos_within_output) {
3445- rv.hot_corner = true;
3446- return rv;
3447- }
3448 }3483 }
3449 3484
3450 under = under3485 under = under