Aldaviva/PowerMate

PowerMateVolume: receive reliable notifications when the computer resumes from standby, so device settings can be reset

Closed this issue · 1 comments

Problem

PowerMate devices do not persist their settings (like LED brightness) when the computer resumes from standby. On its own, the device will revert its brightness to the default value when the computer resumes, as if you had replugged it.

Broken workaround

#1: To work around this, PowerMateVolume listens for the SystemEvents.PowerModeChanged event, and uses that to reset the device settings when resuming from standby by setting all the HID features again based on the in-memory values. It also resets all the features on any device input (like rotation) if the expected and actual settings differ, but this relies on the user manually using the PowerMate to fix the settings.

Unfortunately, SystemEvents only fires the PowerModeChanged event on resume roughly 95% of the time. In the remaining occurrences, the event is not fired and PowerMateVolume does not reset the settings, so the LED brightness and other settings will be wrong.

Better workaround

To fix this, maybe we should detect resumes using ETW instead of whatever message pump bullshit SystemEvents uses.

Fail2Ban4Win has an example of programmatically listening for ETW records, although that's written for .NET Framework instead of .NET Core, so the dependencies may be different.

Standby and resume records are found in the System log, from the Kernel-Power source, with event IDs 42 (standby) and 107 (resume).

The Event Log listener solution seems to be working well so far.