mate-desktop / mate-power-manager

Power management tool for the MATE desktop
https://mate-desktop.org
GNU General Public License v2.0
59 stars 51 forks source link

gpm-brightness: add systemd-logind fallback #380

Closed impl closed 3 months ago

impl commented 2 years ago

systemd 243 added support for an additional mechanism for managing backlight brightness in the form of a D-Bus call to the current logind session. The feature allows any user to manipulate backlights and LEDs without superuser privileges.

This change modifies the brightness backend so that it uses the logind API as a fallback with a higher preference than the external binary helper. In other words, we will try to adjust brightness by:

  1. Changing the Backlight or BACKLIGHT property on the XRandR output
  2. Making a D-Bus SetBrightness call to the logind session
  3. Calling the external helper with pkexec

This change is roughly inspired by a similar adjustment to gnome-settings-daemon, although in their case they prefer the D-Bus approach over XRR; this seems overly blunt to me but perhaps makes sense in the context of future Wayland support.

Unfortunately, there's no corresponding GetBrightness call available, nor is there any way to enumerate backlight devices through D-Bus. We add libgudev as a dependency so that we can look up current backlights and brightness values as needed. In theory, a future revision to this code could eliminate the get-brightness and get-max-brightness options to the external helper, as they are Linux-dependent anyway (they use Linux sysfs paths), preferring the same in-process udev lookups we use here.

We gate this feature entirely behind a --with-udev configure flag so users who don't have a sufficient libgudev version won't be stuck. As the required version has landed in Debian stable, we may be able to make it a hard requirement on Linux in the not-too-distant future.

I've also included a small bugfix to the OSD window class. It seems that when a compositor is switched out from under the daemon while it has an OSD window open, the callback to close the window after a given time will cause a segfault.

lukefromdc commented 1 year ago

Do we have a tester with a non-systemd distro(e.g Devuan, BSD) on a laptop to test this for function. I don't have one set up myself

raveit65 commented 11 months ago

@impl How can this be tested?