Skip to content

Commit 7ccfd73

Browse files
committed
input: Handle lid-switch and disable/enable built-in display
1 parent f2fc1e9 commit 7ccfd73

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

src/input/mod.rs

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
cosmic_keystate_from_smithay, cosmic_modifiers_eq_smithay,
88
cosmic_modifiers_from_smithay,
99
},
10-
Action, Config, PrivateAction,
10+
Action, Config, OutputConfig, OutputState, PrivateAction,
1111
},
1212
input::gestures::{GestureState, SwipeAction},
1313
shell::{
@@ -41,9 +41,9 @@ use smithay::{
4141
backend::input::{
4242
AbsolutePositionEvent, Axis, AxisSource, Device, DeviceCapability, GestureBeginEvent,
4343
GestureEndEvent, GesturePinchUpdateEvent as _, GestureSwipeUpdateEvent as _, InputBackend,
44-
InputEvent, KeyState, KeyboardKeyEvent, PointerAxisEvent, ProximityState,
45-
TabletToolButtonEvent, TabletToolEvent, TabletToolProximityEvent, TabletToolTipEvent,
46-
TabletToolTipState, TouchEvent,
44+
InputEvent, KeyState, KeyboardKeyEvent, PointerAxisEvent, ProximityState, Switch,
45+
SwitchState, SwitchToggleEvent, TabletToolButtonEvent, TabletToolEvent,
46+
TabletToolProximityEvent, TabletToolTipEvent, TabletToolTipState, TouchEvent,
4747
},
4848
desktop::{utils::under_from_surface_tree, PopupKeyboardGrab, WindowSurfaceType},
4949
input::{
@@ -1507,7 +1507,40 @@ impl State {
15071507
}
15081508
}
15091509
InputEvent::Special(_) => {}
1510-
InputEvent::SwitchToggle { event: _ } => {}
1510+
InputEvent::SwitchToggle { event } => {
1511+
if event.switch() == Some(Switch::Lid) {
1512+
let outputs = self.backend.lock().all_outputs();
1513+
if let Some(internal) = outputs.into_iter().find(|o| o.is_internal()) {
1514+
let config = internal.user_data().get::<RefCell<OutputConfig>>().unwrap();
1515+
let enabled = config.borrow().enabled.clone();
1516+
if enabled != OutputState::Disabled && event.state() == SwitchState::On {
1517+
config.borrow_mut().enabled = OutputState::Disabled;
1518+
self.common
1519+
.output_configuration_state
1520+
.remove_heads(std::iter::once(&internal));
1521+
} else if enabled == OutputState::Disabled
1522+
&& event.state() == SwitchState::Off
1523+
{
1524+
self.common
1525+
.output_configuration_state
1526+
.add_heads(std::iter::once(&internal));
1527+
} else {
1528+
return;
1529+
}
1530+
1531+
self.common.config.read_outputs(
1532+
&mut self.common.output_configuration_state,
1533+
&mut self.backend,
1534+
&self.common.shell,
1535+
&self.common.event_loop_handle,
1536+
&mut self.common.workspace_state.update(),
1537+
&self.common.xdg_activation_state,
1538+
self.common.startup_done.clone(),
1539+
&self.common.clock,
1540+
);
1541+
}
1542+
}
1543+
}
15111544
}
15121545
}
15131546

src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ impl BackendData {
400400
}
401401

402402
impl<'a> LockedBackend<'a> {
403-
fn all_outputs(&self) -> Vec<Output> {
403+
pub fn all_outputs(&self) -> Vec<Output> {
404404
match self {
405405
LockedBackend::Kms(state) => state.all_outputs(),
406406
LockedBackend::X11(state) => state.all_outputs(),

0 commit comments

Comments
 (0)