@@ -112,6 +112,9 @@ use smithay::{
112112} ;
113113use time:: UtcOffset ;
114114
115+ #[ cfg( feature = "systemd" ) ]
116+ use std:: os:: fd:: OwnedFd ;
117+
115118use std:: {
116119 cell:: RefCell ,
117120 cmp:: min,
@@ -249,6 +252,9 @@ pub struct Common {
249252
250253 pub atspi_state : AtspiState ,
251254 pub atspi_ei : crate :: wayland:: handlers:: atspi:: AtspiEiState ,
255+
256+ #[ cfg( feature = "systemd" ) ]
257+ inhibit_lid_fd : Option < OwnedFd > ,
252258}
253259
254260#[ derive( Debug ) ]
@@ -504,6 +510,7 @@ impl<'a> LockedBackend<'a> {
504510 }
505511
506512 loop_handle. insert_idle ( move |state| {
513+ state. update_inhibitor_locks ( ) ;
507514 state. common . update_xwayland_scale ( ) ;
508515 state. common . update_xwayland_primary_output ( ) ;
509516 } ) ;
@@ -707,6 +714,9 @@ impl State {
707714
708715 atspi_state,
709716 atspi_ei : Default :: default ( ) ,
717+
718+ #[ cfg( feature = "systemd" ) ]
719+ inhibit_lid_fd : None ,
710720 } ,
711721 backend : BackendData :: Unset ,
712722 ready : Once :: new ( ) ,
@@ -726,6 +736,34 @@ impl State {
726736 security_context : None ,
727737 }
728738 }
739+
740+ fn update_inhibitor_locks ( & mut self ) {
741+ #[ cfg( feature = "systemd" ) ]
742+ {
743+ use tracing:: { debug, error} ;
744+
745+ let outputs = self . backend . lock ( ) . all_outputs ( ) ;
746+ let should_handle_lid = outputs. iter ( ) . any ( |o| o. is_internal ( ) ) && outputs. len ( ) >= 2 ;
747+
748+ if should_handle_lid {
749+ if self . common . inhibit_lid_fd . is_none ( ) {
750+ match crate :: dbus:: logind:: inhibit_lid ( ) {
751+ Ok ( fd) => {
752+ debug ! ( "Inhibiting lid switch" ) ;
753+ self . common . inhibit_lid_fd = Some ( fd) ;
754+ }
755+ Err ( err) => {
756+ error ! ( "Failed to inhibit lid switch: {}" , err) ;
757+ }
758+ }
759+ }
760+ } else {
761+ if self . common . inhibit_lid_fd . take ( ) . is_some ( ) {
762+ debug ! ( "Removing inhibitor-lock on lid switch" )
763+ }
764+ }
765+ }
766+ }
729767}
730768
731769fn primary_scanout_output_compare < ' a > (
0 commit comments