gsd: Fix keyboard backlight toggle state machines
Some laptops like ASUS UX550GE has a hotkey (Fn+F7) for keyboard backlight toggle. In this UX550GE, the hotkey not only switches on/off the keyboard backlight, but also increments the level of brightness from 1 to max 3. In this case, it will trigger the keyboard backlight StepUp and Toggle events and execute the handle_method_call_keyboard function of gsd_power_manager.c in GNOME settings daemon when the hotkey is pressed.
The ideal scenario of pressing hotkey should trigger the events like:
.. StepUp -> Toggle -> StepUp -> StepUp -> StepUp -> Toggle -> StepUp ..
However, we noticed the actual processes are:
.. StepUp -> Toggle -> Toggle -> StepUp -> StepUp -> StepUp -> Toggle ..
It triggers Toggle event two times between StepUp events.
We check the upower_kbd_toggle function called in handle_method_call_keyboard when the event is Toggle, and find out it checks only the state of old brightness without current brightness. That misses some other states changing.
So, here is the list of the Toggle Method's state machines:
- brightness_now: 0, brightness_old: 1 ~ max level of brightness -> toggle to old brightness
- brightness_now: 0, brightness_old: -1 or 0 -> toggle to max brightness
- brightness_now: 1 ~ max level of brightness, brightness_old: all -> toggle to 0 brightness
This commit fixes and implements the state machines. Closes #41
Signed-off-by: Jian-Hong Pan email@example.com