Commit 21c575475018
tarball1 file changed+20-1
@@ -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 runs16
+/// 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 acts129
+ && self.services.power.lid_closed130
+ && 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::Drop136
+ });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 last141159
/// 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;