forge
Explore
Log in

Don't you dare go Hollow

Disable laptop panel when the lid is closed

Browse files at this commit

cd90dfc7be11147936c2b637ae822ff0adf5a7b7Ivan MolodetskikhParent: a778ab3
niri-config/src/lib.rsmodified+2 -0
@@ -1533,6 +1533,8 @@ pub struct DebugConfig {
15331533 pub disable_resize_throttling: bool,
15341534 #[knuffel(child)]
15351535 pub disable_transactions: bool,
1536+ #[knuffel(child)]
1537+ pub keep_laptop_panel_on_when_lid_is_closed: bool,
15361538 }
15371539
15381540 #[derive(knuffel::DecodeScalar, Debug, Clone, Copy, PartialEq, Eq)]
src/backend/tty.rsmodified+6 -2
@@ -783,6 +783,10 @@ impl Tty {
783783 debug!("output is disabled in the config");
784784 return Ok(());
785785 }
786+ if !niri.should_enable_laptop_panel(&output_name.connector) {
787+ debug!("output is disabled because it is a laptop panel and the lid is closed");
788+ return Ok(());
789+ }
786790
787791 for m in connector.modes() {
788792 trace!("{m:?}");
@@ -1723,7 +1727,7 @@ impl Tty {
17231727 .find(&surface.name)
17241728 .cloned()
17251729 .unwrap_or_default();
1726- if config.off {
1730+ if config.off || !niri.should_enable_laptop_panel(&surface.name.connector) {
17271731 to_disconnect.push((node, crtc));
17281732 continue;
17291733 }
@@ -1833,7 +1837,7 @@ impl Tty {
18331837 .cloned()
18341838 .unwrap_or_default();
18351839
1836- if !config.off {
1840+ if !config.off && niri.should_enable_laptop_panel(&output_name.connector) {
18371841 to_connect.push((node, connector.clone(), crtc));
18381842 }
18391843 }
src/input/mod.rsmodified+7 -0
@@ -2434,6 +2434,13 @@ impl State {
24342434 return;
24352435 };
24362436
2437+ if switch == Switch::Lid {
2438+ let is_closed = evt.state() == SwitchState::On;
2439+ debug!("lid switch {}", if is_closed { "closed" } else { "opened" });
2440+ self.niri.is_lid_closed = is_closed;
2441+ self.reload_output_config();
2442+ }
2443+
24372444 let action = {
24382445 let bindings = &self.niri.config.borrow().switch_events;
24392446 find_configured_switch_action(bindings, switch, evt.state())
src/niri.rsmodified+32 -2
@@ -143,8 +143,9 @@ use crate::ui::screenshot_ui::{OutputScreenshot, ScreenshotUi, ScreenshotUiRende
143143 use crate::utils::scale::{closest_representable_scale, guess_monitor_scale};
144144 use crate::utils::spawning::CHILD_ENV;
145145 use crate::utils::{
146- center, center_f64, get_monotonic_time, ipc_transform_to_smithay, logical_output,
147- make_screenshot_path, output_matches_name, output_size, send_scale_transform, write_png_rgba8,
146+ center, center_f64, get_monotonic_time, ipc_transform_to_smithay, is_laptop_panel,
147+ logical_output, make_screenshot_path, output_matches_name, output_size, send_scale_transform,
148+ write_png_rgba8,
148149 };
149150 use crate::window::{InitialConfigureState, Mapped, ResolvedWindowRules, Unmapped, WindowRef};
150151 use crate::{animation, niri_render_elements};
@@ -207,6 +208,12 @@ pub struct Niri {
207208 // When false, we're idling with monitors powered off.
208209 pub monitors_active: bool,
209210
211+ /// Whether the laptop lid is closed.
212+ ///
213+ /// Libinput guarantees that the lid switch starts in open state, and if it was closed during
214+ /// startup, libinput will immediately send a closed event.
215+ pub is_lid_closed: bool,
216+
210217 pub devices: HashSet<input::Device>,
211218 pub tablets: HashMap<input::Device, TabletData>,
212219 pub touch: HashSet<input::Device>,
@@ -1101,6 +1108,12 @@ impl State {
11011108
11021109 if config.debug != old_config.debug {
11031110 debug_config_changed = true;
1111+
1112+ if config.debug.keep_laptop_panel_on_when_lid_is_closed
1113+ != old_config.debug.keep_laptop_panel_on_when_lid_is_closed
1114+ {
1115+ output_config_changed = true;
1116+ }
11041117 }
11051118
11061119 *old_config = config;
@@ -1831,6 +1844,7 @@ impl Niri {
18311844 blocker_cleared_tx,
18321845 blocker_cleared_rx,
18331846 monitors_active: true,
1847+ is_lid_closed: false,
18341848
18351849 devices: HashSet::new(),
18361850 tablets: HashMap::new(),
@@ -4797,6 +4811,22 @@ impl Niri {
47974811 .unwrap();
47984812 self.pointer_inactivity_timer = Some(token);
47994813 }
4814+
4815+ pub fn should_enable_laptop_panel(&self, connector: &str) -> bool {
4816+ // Make sure the output config is reloaded when any of the conditions in this function
4817+ // change.
4818+
4819+ let config = self.config.borrow();
4820+
4821+ // We reload the output config when this flag changes.
4822+ if config.debug.keep_laptop_panel_on_when_lid_is_closed {
4823+ return true;
4824+ }
4825+
4826+ // We reload the output config when the lid switch is toggled, and the connector name is
4827+ // static.
4828+ !(self.is_lid_closed && is_laptop_panel(connector))
4829+ }
48004830 }
48014831
48024832 pub struct ClientState {
wiki/Configuration:-Debug-Options.mdmodified+14 -0
@@ -22,6 +22,7 @@ debug {
2222 emulate-zero-presentation-time
2323 disable-resize-throttling
2424 disable-transactions
25+ keep-laptop-panel-on-when-lid-is-closed
2526 }
2627
2728 binds {
@@ -165,6 +166,19 @@ debug {
165166 }
166167 ```
167168
169+### `keep-laptop-panel-on-when-lid-is-closed`
170+
171+<sup>Since: 0.1.10</sup>
172+
173+By default, niri will disable the internal laptop monitor when the laptop lid is closed.
174+This flag turns off this behavior and will leave the internal laptop monitor on.
175+
176+```kdl
177+debug {
178+ keep-laptop-panel-on-when-lid-is-closed
179+}
180+```
181+
168182 ### Key Bindings
169183
170184 These are not debug options, but rather key bindings.
wiki/Configuration:-Switch-Events.mdmodified+5 -5
@@ -8,8 +8,8 @@ Here are all the events that you can bind at a glance:
88
99 ```kdl
1010 switch-events {
11- lid-close { spawn "bash" "-c" "niri msg output \"eDP-1\" off"; }
12- lid-open { spawn "bash" "-c" "niri msg output \"eDP-1\" on"; }
11+ lid-close { spawn "notify-send" "The laptop lid is closed!"; }
12+ lid-open { spawn "notify-send" "The laptop lid is open!"; }
1313 tablet-mode-on { spawn "bash" "-c" "gsettings set org.gnome.desktop.a11y.applications screen-keyboard-enabled true"; }
1414 tablet-mode-off { spawn "bash" "-c" "gsettings set org.gnome.desktop.a11y.applications screen-keyboard-enabled false"; }
1515 }
@@ -25,12 +25,12 @@ Currently, only the `spawn` action are supported.
2525
2626 These events correspond to closing and opening of the laptop lid.
2727
28-You could use them to turn the laptop internal monitor off and on (until niri gets this functionality built-in).
28+Note that niri will already automatically turn the internal laptop monitor on and off in accordance with the laptop lid.
2929
3030 ```kdl
3131 switch-events {
32- lid-close { spawn "bash" "-c" "niri msg output \"eDP-1\" off"; }
33- lid-open { spawn "bash" "-c" "niri msg output \"eDP-1\" on"; }
32+ lid-close { spawn "notify-send" "The laptop lid is closed!"; }
33+ lid-open { spawn "notify-send" "The laptop lid is open!"; }
3434 }
3535 ```
3636