atagen

monolith

public
Star0
Watch0

Commit 21c575475018

tarball

atagen <boss@atagen.co>2026-10-19 10:44 UTC

1 file changed+20-1
power: rerun the lid action after a wake with the lid shut

lid_acted stayed set for as long as the lid was closed, so a laptop woken by its power button with the lid still shut never suspended again. Input now clears it and schedules lid_act after a grace period. lid_act also waits for the first output, since a lid already closed at boot could run the action before the external displays were scanned.
Modified file: crates/monolith/src/power.rs+20 additions−1 deletions
@@ -12,6 +12,10 @@ use smithay::reexports::calloop::timer::{TimeoutAction, Timer};
1212 use std::collections::HashSet;
1313 use std::time::Duration;
1414
15+/// How long input with the lid shut may go on before the close action runs
16+/// again, so waking a closed laptop does not suspend it mid-keystroke.
17+const LID_GRACE: Duration = Duration::from_secs(5);
18+
1519 #[derive(Default)]
1620 pub struct Power {
1721 /// Absent on the nested backend, or when the system bus is unreachable.
@@ -120,6 +124,20 @@ impl State {
120124 self.wake_idle();
121125 self.apply_power();
122126 }
127+ let acts = !matches!(self.settings.config.lid.close, LidAction::Ignore);
128+ if acts
129+ && self.services.power.lid_closed
130+ && std::mem::take(&mut self.services.power.lid_acted)
131+ {
132+ let again = Timer::from_duration(LID_GRACE);
133+ let armed = self.core.handle.insert_source(again, |_, _, state| {
134+ state.lid_act();
135+ TimeoutAction::Drop
136+ });
137+ if let Err(e) = armed {
138+ tracing::warn!("could not arm the lid action: {e}");
139+ }
140+ }
123141 }
124142
125143 /// The lid switch moved. Closing it darkens the internal panel when
@@ -140,8 +158,9 @@ impl State {
140158 /// Also called when outputs come and go, since unplugging the last
141159 /// external display of a closed laptop is when it should sleep.
142160 pub fn lid_act(&mut self) {
161+ let lit = self.wm.space.outputs().next().is_some();
143162 let power = &mut self.services.power;
144- if !power.lid_closed || power.lid_acted || power.panel_off {
163+ if !lit || !power.lid_closed || power.lid_acted || power.panel_off {
145164 return;
146165 }
147166 power.lid_acted = true;