@@ -25,6 +25,7 @@ use input::{
2525 Libinput , LibinputInterface , Device as InputDevice ,
2626 event:: {
2727 Event , device:: DeviceEvent , EventTrait ,
28+ switch:: { Switch , SwitchEvent , SwitchState } ,
2829 touch:: { TouchEvent , TouchEventPosition , TouchEventSlot }
2930 }
3031} ;
@@ -358,6 +359,7 @@ fn main() {
358359 let mut digitizer: Option < InputDevice > = None ;
359360 let mut touches = HashMap :: new ( ) ;
360361 let mut last_active = Instant :: now ( ) ;
362+ let mut lid_state = SwitchState :: Off ;
361363 let mut current_bl = 42 ;
362364 loop {
363365 if needs_redraw {
@@ -429,12 +431,26 @@ fn main() {
429431 } ,
430432 Event :: Keyboard ( _) | Event :: Pointer ( _) => {
431433 last_active = Instant :: now ( ) ;
434+ } ,
435+ Event :: Switch ( SwitchEvent :: Toggle ( toggle) ) => {
436+ match toggle. switch ( ) {
437+ Some ( Switch :: Lid ) => {
438+ lid_state = toggle. switch_state ( ) ;
439+ println ! ( "Lid Switch event: {lid_state:?}" ) ;
440+ if toggle. switch_state ( ) == SwitchState :: Off {
441+ last_active = Instant :: now ( ) ;
442+ }
443+ }
444+ _ => { }
445+ }
432446 }
433447 _ => { }
434448 }
435449 }
436450 let since_last_active = ( Instant :: now ( ) - last_active) . as_millis ( ) as u64 ;
437- let new_bl = if since_last_active < TIMEOUT_MS as u64 {
451+ let new_bl = if lid_state == SwitchState :: On {
452+ 0
453+ } else if since_last_active < TIMEOUT_MS as u64 {
438454 128
439455 } else if since_last_active < TIMEOUT_MS as u64 * 2 {
440456 1
0 commit comments