Skip to content

Commit

Permalink
gpm-brightness: add systemd-logind fallback
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
impl committed Jul 21, 2022
1 parent 0931455 commit df44c8c
Show file tree
Hide file tree
Showing 4 changed files with 441 additions and 14 deletions.
19 changes: 19 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ XRANDR_REQUIRED=1.3.0
XPROTO_REQUIRED=7.0.15
CANBERRA_REQUIRED=0.10
UPOWER_REQUIRED=0.99.8
LIBGUDEV_REQUIRED=234

dnl ---------------------------------------------------------------------------
dnl - Check library dependencies
Expand Down Expand Up @@ -172,6 +173,23 @@ if test "$with_libsecret" = "yes" -a "$with_keyring" = "yes"; then
AC_MSG_ERROR([Please select only 1, keyring or libsecret])
fi

dnl ---------------------------------------------------------------------------
dnl - Build udev support
dnl ---------------------------------------------------------------------------
AC_ARG_WITH(udev,
[AS_HELP_STRING([--with-udev],
[Directly query devices for enhanced hardware support])],
[],
[with_udev=no])

AM_CONDITIONAL([WITH_UDEV],[test "$with_udev" = "yes"])

if test "$with_udev" = "yes"; then
PKG_CHECK_MODULES(UDEV, gudev-1.0 >= $LIBGUDEV_REQUIRED)
AC_DEFINE([WITH_UDEV],[1],[Define if UDEV support is enabled])
fi


dnl ---------------------------------------------------------------------------
dnl - Build applets
dnl ---------------------------------------------------------------------------
Expand Down Expand Up @@ -249,6 +267,7 @@ Configure summary:

libsecret support ...........: ${with_libsecret}
gnome-keyring support .......: ${with_keyring}
udev support ................: ${with_udev}
Building extra applets ......: ${enable_applets}
Self test support ...........: ${have_tests}
dbus-1 services dir .........: $DBUS_SERVICES_DIR
Expand Down
5 changes: 5 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ AM_CPPFLAGS = \
$(CAIRO_CFLAGS) \
$(LIBSECRET_CFLAGS) \
$(KEYRING_CFLAGS) \
$(UDEV_CFLAGS) \
$(X11_CFLAGS) \
$(LIBNOTIFY_CFLAGS) \
$(CANBERRA_CFLAGS) \
Expand Down Expand Up @@ -84,6 +85,7 @@ mate_power_backlight_helper_SOURCES = \
mate_power_backlight_helper_LDADD = \
libgpmshared.a \
$(GLIB_LIBS) \
$(UDEV_LIBS) \
-lm

mate_power_backlight_helper_CFLAGS = \
Expand All @@ -109,6 +111,7 @@ mate_power_statistics_SOURCES = \
mate_power_statistics_LDADD = \
libgpmshared.a \
$(GLIB_LIBS) \
$(UDEV_LIBS) \
$(X11_LIBS) \
$(UPOWER_LIBS) \
$(CAIRO_LIBS) \
Expand Down Expand Up @@ -136,6 +139,7 @@ mate_power_preferences_SOURCES = \
mate_power_preferences_LDADD = \
libgpmshared.a \
$(GLIB_LIBS) \
$(UDEV_LIBS) \
$(X11_LIBS) \
$(CAIRO_LIBS) \
$(DBUS_LIBS) \
Expand Down Expand Up @@ -200,6 +204,7 @@ mate_power_manager_LDADD = \
$(CAIRO_LIBS) \
$(LIBSECRET_LIBS) \
$(KEYRING_LIBS) \
$(UDEV_LIBS) \
$(DBUS_LIBS) \
$(X11_LIBS) \
$(CANBERRA_LIBS) \
Expand Down
Loading

0 comments on commit df44c8c

Please sign in to comment.