forge
Explore
Log in

Don't you dare go Hollow

Add disable-power-key-handling option

Browse files at this commit

249f2b7a21f883726e0c8c49cc3bbec52cc1b6ccIvan MolodetskikhParent: f3e5e13
resources/default-config.kdlmodified+6 -0
@@ -37,6 +37,12 @@ input {
37 // existing outputs.37 // existing outputs.
38 map-to-output "eDP-1"38 map-to-output "eDP-1"
39 }39 }
40+
41+ // By default, niri will take over the power button to make it sleep
42+ // instead of power off.
43+ // Uncomment this if you would like to configure the power button elsewhere
44+ // (i.e. logind.conf).
45+ // disable-power-key-handling
40 }46 }
41 47
42 // You can configure outputs by their name, which you can find with wayland-info(1).48 // You can configure outputs by their name, which you can find with wayland-info(1).
src/config.rsmodified+5 -0
@@ -55,6 +55,8 @@ pub struct Input {
55 pub touchpad: Touchpad,55 pub touchpad: Touchpad,
56 #[knuffel(child, default)]56 #[knuffel(child, default)]
57 pub tablet: Tablet,57 pub tablet: Tablet,
58+ #[knuffel(child)]
59+ pub disable_power_key_handling: bool,
58 }60 }
59 61
60 #[derive(knuffel::Decode, Debug, Default, PartialEq, Eq)]62 #[derive(knuffel::Decode, Debug, Default, PartialEq, Eq)]
@@ -585,6 +587,8 @@ mod tests {
585 tablet {587 tablet {
586 map-to-output "eDP-1"588 map-to-output "eDP-1"
587 }589 }
590+
591+ disable-power-key-handling
588 }592 }
589 593
590 output "eDP-1" {594 output "eDP-1" {
@@ -666,6 +670,7 @@ mod tests {
666 tablet: Tablet {670 tablet: Tablet {
667 map_to_output: Some("eDP-1".to_owned()),671 map_to_output: Some("eDP-1".to_owned()),
668 },672 },
673+ disable_power_key_handling: true,
669 },674 },
670 outputs: vec![Output {675 outputs: vec![Output {
671 off: false,676 off: false,
src/input.rsmodified+15 -2
@@ -209,6 +209,7 @@ impl State {
209 pressed,209 pressed,
210 *mods,210 *mods,
211 &this.niri.screenshot_ui,211 &this.niri.screenshot_ui,
212+ this.niri.config.borrow().input.disable_power_key_handling,
212 )213 )
213 },214 },
214 ) else {215 ) else {
@@ -1165,6 +1166,7 @@ fn should_intercept_key(
1165 pressed: bool,1166 pressed: bool,
1166 mods: ModifiersState,1167 mods: ModifiersState,
1167 screenshot_ui: &ScreenshotUi,1168 screenshot_ui: &ScreenshotUi,
1169+ disable_power_key_handling: bool,
1168 ) -> FilterResult<Option<Action>> {1170 ) -> FilterResult<Option<Action>> {
1169 // Actions are only triggered on presses, release of the key1171 // Actions are only triggered on presses, release of the key
1170 // shouldn't try to intercept anything unless we have marked1172 // shouldn't try to intercept anything unless we have marked
@@ -1173,7 +1175,14 @@ fn should_intercept_key(
1173 return FilterResult::Forward;1175 return FilterResult::Forward;
1174 }1176 }
1175 1177
1176- let mut final_action = action(bindings, comp_mod, modified, raw, mods);1178+ let mut final_action = action(
1179+ bindings,
1180+ comp_mod,
1181+ modified,
1182+ raw,
1183+ mods,
1184+ disable_power_key_handling,
1185+ );
1177 1186
1178 // Allow only a subset of compositor actions while the screenshot UI is open, since the user1187 // Allow only a subset of compositor actions while the screenshot UI is open, since the user
1179 // cannot see the screen.1188 // cannot see the screen.
@@ -1210,6 +1219,7 @@ fn action(
1210 modified: Keysym,1219 modified: Keysym,
1211 raw: Option<Keysym>,1220 raw: Option<Keysym>,
1212 mods: ModifiersState,1221 mods: ModifiersState,
1222+ disable_power_key_handling: bool,
1213 ) -> Option<Action> {1223 ) -> Option<Action> {
1214 use keysyms::*;1224 use keysyms::*;
1215 1225
@@ -1220,7 +1230,7 @@ fn action(
1220 let vt = (modified - KEY_XF86Switch_VT_1 + 1) as i32;1230 let vt = (modified - KEY_XF86Switch_VT_1 + 1) as i32;
1221 return Some(Action::ChangeVt(vt));1231 return Some(Action::ChangeVt(vt));
1222 }1232 }
1223- KEY_XF86PowerOff => return Some(Action::Suspend),1233+ KEY_XF86PowerOff if !disable_power_key_handling => return Some(Action::Suspend),
1224 _ => (),1234 _ => (),
1225 }1235 }
1226 1236
@@ -1325,6 +1335,7 @@ mod tests {
1325 let mut suppressed_keys = HashSet::new();1335 let mut suppressed_keys = HashSet::new();
1326 1336
1327 let screenshot_ui = ScreenshotUi::new();1337 let screenshot_ui = ScreenshotUi::new();
1338+ let disable_power_key_handling = false;
1328 1339
1329 // The key_code we pick is arbitrary, the only thing1340 // The key_code we pick is arbitrary, the only thing
1330 // that matters is that they are different between cases.1341 // that matters is that they are different between cases.
@@ -1341,6 +1352,7 @@ mod tests {
1341 pressed,1352 pressed,
1342 mods,1353 mods,
1343 &screenshot_ui,1354 &screenshot_ui,
1355+ disable_power_key_handling,
1344 )1356 )
1345 };1357 };
1346 1358
@@ -1356,6 +1368,7 @@ mod tests {
1356 pressed,1368 pressed,
1357 mods,1369 mods,
1358 &screenshot_ui,1370 &screenshot_ui,
1371+ disable_power_key_handling,
1359 )1372 )
1360 };1373 };
1361 1374
src/main.rsmodified+4 -2
@@ -163,8 +163,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
163 163
164 // Inhibit power key handling so we can suspend on it.164 // Inhibit power key handling so we can suspend on it.
165 #[cfg(feature = "dbus")]165 #[cfg(feature = "dbus")]
166- if let Err(err) = state.niri.inhibit_power_key() {166+ if !state.niri.config.borrow().input.disable_power_key_handling {
167- warn!("error inhibiting power key: {err:?}");167+ if let Err(err) = state.niri.inhibit_power_key() {
168+ warn!("error inhibiting power key: {err:?}");
169+ }
168 }170 }
169 }171 }
170 172