@@ -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
0 commit comments