diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e70b78..b2a3ddd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - Add support for user-defined control codes in services. (See: `Service::notify` and `notify_service.rs` example) +- Add support for `LidSwitchStateChange` in `PowerBroadcastSetting`. + (See: `LidSwitchStateChange`) ## [0.6.0] - 2023-03-07 diff --git a/src/service.rs b/src/service.rs index 7a2f4a5..b7ef62a 100644 --- a/src/service.rs +++ b/src/service.rs @@ -770,6 +770,29 @@ impl AwayModeState { } } +/// Enum indicates the current lid switch state as +/// the Data member of GUID_LIDSWITCH_STATE_CHANGE notification +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[repr(u32)] +pub enum LidSwitchStateChange { + Closed = 0, + Open = 1, +} + +impl LidSwitchStateChange { + pub fn to_raw(&self) -> u32 { + *self as u32 + } + + pub fn from_raw(raw: u32) -> Result { + match raw { + x if x == LidSwitchStateChange::Closed.to_raw() => Ok(LidSwitchStateChange::Closed), + x if x == LidSwitchStateChange::Open.to_raw() => Ok(LidSwitchStateChange::Open), + _ => Err(ParseRawError::InvalidInteger(raw)), + } + } +} + /// Struct converted from Power::POWERBROADCAST_SETTING /// /// Please refer to MSDN for more info about the data members: @@ -785,6 +808,7 @@ pub enum PowerBroadcastSetting { PowerSavingStatus(BatterySaverState), PowerSchemePersonality(PowerSchemePersonality), SystemAwayMode(AwayModeState), + LidSwitchStateChange(LidSwitchStateChange), } impl PowerBroadcastSetting { @@ -850,6 +874,12 @@ impl PowerBroadcastSetting { AwayModeState::from_raw(away_mode_state)?, )) } + x if is_equal_guid(x, &SystemServices::GUID_LIDSWITCH_STATE_CHANGE) => { + let lid_switch_state = *(data as *const u32); + Ok(PowerBroadcastSetting::LidSwitchStateChange( + LidSwitchStateChange::from_raw(lid_switch_state)?, + )) + } x => Err(ParseRawError::InvalidGuid(string_from_guid(x))), } }