Skip to content

power: Add sysfs and logind fallback for keyboard and display backlight - #476

Closed
DerLinke wants to merge 2 commits into
linuxmint:masterfrom
DerLinke:fix-wayland-backlight
Closed

DerLinke wants to merge 2 commits into
linuxmint:masterfrom
DerLinke:fix-wayland-backlight

Conversation

@DerLinke

Copy link
Copy Markdown

Problem Description

When running under Wayland or on modern Linux distributions without legacy UPower KbdBacklight, the keyboard backlight and display brightness controls disappear from the Cinnamon power applet (Cinnamon issue linuxmint/cinnamon#13854).

Root Causes

  1. Keyboard backlight: csd-power-manager.c exclusively queried org.freedesktop.UPower at path /org/freedesktop/UPower/KbdBacklight. Modern distributions (Debian 12/13, Ubuntu 24.04+, systemd >= 252) no longer expose KbdBacklight on UPower when managed directly by logind or when no device was present at upowerd start. When UPower fails, CSD set max brightness to 0 and returned NOT_SUPPORTED, causing power@cinnamon.org/applet.js to never show the slider.
  2. Display backlight: In csd-backlight-helper.c, preference matching stopped at the first match even if the candidate interface (e.g. inactive ACPI video device on hybrid AMD+NVIDIA laptops) had an unreadable or zero max_brightness. Furthermore, on_rr_screen_acquired() aborted the entire CSD power manager initialization on error instead of continuing with sysfs fallbacks, and called X11 DPMS functions unguarded on Wayland displays.

Changes Made

  1. Keyboard backlight:
    • Probe /sys/class/leds/ for devices matching *kbd_backlight* if UPower does not provide the KbdBacklight interface.
    • Read brightness and max brightness directly from sysfs.
    • Watch brightness_hw_changed via GIOChannel for hardware/hotkey changes.
    • Set brightness via org.freedesktop.login1.Session.SetBrightness("leds", device, value) on /org/freedesktop/login1/session/auto.
  2. Display backlight and Wayland resilience:
    • In csd-backlight-helper.c, validate that candidate devices have readable max_brightness > 0 before selecting them, and fall back to any valid backlight device.
    • In on_rr_screen_acquired(), do not abort on GnomeRRScreen acquisition errors under Wayland; proceed with sysfs and helper fallbacks.
    • Guard X11 DPMS calls with GDK_IS_X11_DISPLAY() to prevent crashes under Wayland.

dan added 2 commits October 15, 2026 00:03
When running under Wayland or on modern Linux distributions without
legacy UPower KbdBacklight, the keyboard backlight and display brightness
controls disappear from the power applet (Cinnamon issue #13854).

1. Keyboard backlight:
   - Probe /sys/class/leds/ for devices matching '*kbd_backlight*' if UPower
     does not provide the KbdBacklight interface or has no methods.
   - Read current and maximum brightness directly from sysfs.
   - Watch brightness_hw_changed for hotkey / firmware updates.
   - Control brightness using systemd-logind's SetBrightness method on
     /org/freedesktop/login1/session/auto.

2. Display backlight and Wayland resilience:
   - In csd-backlight-helper, validate that candidate backlight devices have
     a readable max_brightness > 0 before selecting them, preventing broken
     ACPI video devices on hybrid graphics laptops from breaking backlight
     controls. Fall back to any available valid backlight device if preference
     matching finds no usable candidate.
   - In on_rr_screen_acquired(), do not abort initialization if GnomeRRScreen
     fails to acquire under Wayland; proceed with sysfs and helper fallbacks.
   - Guard X11 DPMS calls with GDK_IS_X11_DISPLAY() to prevent crashes under Wayland.
@mtwebster

Copy link
Copy Markdown
Member

Please stop, I can do this myself if I wanted.

@mtwebster mtwebster closed this Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants