LEDs:Sync with backlight

Trigger
Actually there is a LED trigger available to turn on/off some LEDs when the backlight goes on/off (link). For usage of LED triggers, see LEDs. Though probably it is currently not enabled in most of the kernel configs.

Scripts
If the backlight LED trigger is not available, does not work for some reason or when backlight handling is not yet implemented for the device, there are other ways to achieve such a behaviour.

One approach is having a look on dbus-monitor if some signals or method calls can be used parasitically to turn on/off the LEDs at certain situations. Check the screen blanking/unblanking behavior works best via ssh. For view the session bus, the DISPLAY variable needs to be exportet:. This is not needed to see the system bus but  shows singnals only. To see method calls on the system bus, sudo is required:.

Phosh
When the screen blanks or unblanks, there are some method calls concerning the color manager on the system bus. This can be used to turn on/off the leds. As method calls on the system bus need sudo, the command can be added to visusdo to avoid a password query for the command.

The dbus method call of the color manager unfortunately does not reveal whether the screen was blanked or unblanked. To find out about the state, the sysfs node  is queried. You might need to adapt the path according your setup. If your device doesn't provide dpms information, you need to find other ways to query the state of the screen, maybe looking for other dbus signals or method calls.

The example shows turning on/off the leds of tm2-touchkey (used by some samsung devices). To handle the LEDs in the script, the user needs permission to change them, see LEDs.

If the LEDs you want to use are turned off by default, you need to turn them on at boot. The keys for this example can be found by.



ACTION=="add", SUBSYSTEM=="leds", KERNEL=="tm2-touchkey", ATTR{brightness}="1"

Now let's create the script:

Make it executable:



Add the dbus command to the sudoers file:



user ALL=NOPASSWD: /usr/bin/dbus-monitor --system interface=org.freedesktop.ColorManager
 * 1) watch ColorManager changes to detect screen blanking

And create an autostart file:



[Desktop Entry] Type=Application Name=tm2-touchkey-leds-phosh Exec=/home/user/tm2-touchkey-leds-phosh.sh X-GNOME-Autostart-Phase=Initialization

Plasma Mobile
Unfortunately, dbus-monitor seems not easily accessible via ssh. This makes it harder to find appropriate signals or method calls that can be used.

Xfce4
See Screen locker:Disable inputs, a more extensive draft script that handles both input and LEDs.