Skip to contentSkip to conversation

input: Add new keyboard backlight control keys to match modern notebooks

PATCH In review Werner Sembach 3 participants 6 messages May 30, 2023 – May 31, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 input: Add new keyboard backlight control keys to match modern notebooks

The old three KEY_KBDILLUM* keycodes don't reflect the current situation modern notebooks anymore. Especially the ones with RGB keyboards.

e.g.
- Clevo NL50NU has a toggle, an up, a down and a color-cycle key
- TongFang PH4ARX1 doesn't have a toggle key, but one that cycles through off, half-brightness, and full-brightness.

Also, on some devices these keys are already implemented in firmware. It would still be nice if there is a way to let userspace know when one of these keys is pressed to display the OSD, but don't advice it to actually do anything. This is the intended purpose of the KEY_KBDILLUMCHANGE define.

---
 include/uapi/linux/input-event-codes.h | 4 ++++
 1 file changed, 4 insertions(+)
include/uapi/linux/input-event-codes.h +4 -0
index 022a520e31fc2..05287bf9a77f7 100644
@@ -803,6 +803,10 @@
 #define BTN_TRIGGER_HAPPY39		0x2e6
 #define BTN_TRIGGER_HAPPY40		0x2e7
 
+#define KEY_KBDILLUMCYCLE		0x2e8
+#define KEY_KBDILLUMCOLORCYCLE		0x2e9
+#define KEY_KBDILLUMCHANGE		0x2ea
+
 /* We avoid low common keys in module aliases so they don't get huge. */
 #define KEY_MIN_INTERESTING	KEY_MUTE
 #define KEY_MAX			0x2ff
Signature · 1 line
2.34.1
#1 lore raw
Quoted 19 lines · Werner Sembach

The old three KEY_KBDILLUM* keycodes don't reflect the current situation
modern notebooks anymore. Especially the ones with RGB keyboards.

e.g.
- Clevo NL50NU has a toggle, an up, a down and a color-cycle key
- TongFang PH4ARX1 doesn't have a toggle key, but one that cycles through
  off, half-brightness, and full-brightness.

Also, on some devices these keys are already implemented in firmware. It
would still be nice if there is a way to let userspace know when one of
these keys is pressed to display the OSD, but don't advice it to actually
do anything. This is the intended purpose of the KEY_KBDILLUMCHANGE define.

Quoted 1 line

Can you please point to the user-space patches (or issues filed) that would integrate the support for those keycodes, and make the key presses do something?

Has anyone tested that those keycodes are fit for purpose when mixed with other brightness changes that don't happen through key presses?

Quoted 21 lines

---
 include/uapi/linux/input-event-codes.h | 4 ++++

 1 file changed, 4 insertions(+)
include/uapi/linux/input-event-codes.h +0 -0
index 022a520e31fc2..05287bf9a77f7 100644
@@ -803,6 +803,10 @@
  #define BTN_TRIGGER_HAPPY39            0x2e6
  #define BTN_TRIGGER_HAPPY40            0x2e7

include/uapi/linux/input-event-codes.h +4 -0
+#define KEY_KBDILLUMCYCLE              0x2e8
+#define KEY_KBDILLUMCOLORCYCLE         0x2e9
+#define KEY_KBDILLUMCHANGE             0x2ea
+

 /* We avoid low common keys in module aliases so they don't get huge. */
 #define KEY_MIN_INTERESTING    KEY_MUTE
 #define KEY_MAX                        0x2ff

#2 lore raw

Hi,

Am 30.05.23 um 15:33 schrieb Bastien Nocera:

Quoted 20 lines · Werner Sembach
Quoted 19 lines

The old three KEY_KBDILLUM* keycodes don't reflect the current situation
modern notebooks anymore. Especially the ones with RGB keyboards.

e.g.
- Clevo NL50NU has a toggle, an up, a down and a color-cycle key
- TongFang PH4ARX1 doesn't have a toggle key, but one that cycles through
  off, half-brightness, and full-brightness.

Also, on some devices these keys are already implemented in firmware. It
would still be nice if there is a way to let userspace know when one of
these keys is pressed to display the OSD, but don't advice it to actually
do anything. This is the intended purpose of the KEY_KBDILLUMCHANGE define.

Quoted 4 lines
Quoted 1 line

Can you please point to the user-space patches (or issues filed) that would integrate the support for those keycodes, and make the key presses do something?

I'm sorry to say that these don't exist yet. So I guess the process is similar to DRM uAPI additions? https://docs.kernel.org/gpu/drm-uapi.html#open-source-userspace-requirements

Quoted 3 lines

Has anyone tested that those keycodes are fit for purpose when mixed with other brightness changes that don't happen through key presses?

Color control is not yet implemented in any DE afaik, so there is not yet a collision with the color cycle key.

For the brightness cycle key, I would assume that it functions the same as the brightness up key unless brightness == brightness max. In this case it sets brightness to 0. I don't see a logical collision here as brightness up and brightness down are already implemented just fine in most DEs

Quoted 22 lines
Quoted 22 lines
---
  include/uapi/linux/input-event-codes.h | 4 ++++
  1 file changed, 4 insertions(+)
include/uapi/linux/input-event-codes.h +4 -0
index 022a520e31fc2..05287bf9a77f7 100644
@@ -803,6 +803,10 @@
  #define BTN_TRIGGER_HAPPY39            0x2e6
  #define BTN_TRIGGER_HAPPY40            0x2e7
 
+#define KEY_KBDILLUMCYCLE              0x2e8
+#define KEY_KBDILLUMCOLORCYCLE         0x2e9
+#define KEY_KBDILLUMCHANGE             0x2ea
+
  /* We avoid low common keys in module aliases so they don't get

huge. */
 #define KEY_MIN_INTERESTING    KEY_MUTE
 #define KEY_MAX                        0x2ff

#3 lore raw

Am 30.05.23 um 16:28 schrieb Werner Sembach:

Quoted 23 lines

Hi,

Am 30.05.23 um 15:33 schrieb Bastien Nocera:

Quoted 20 lines · Werner Sembach
Quoted 19 lines

The old three KEY_KBDILLUM* keycodes don't reflect the current situation
modern notebooks anymore. Especially the ones with RGB keyboards.

e.g.
- Clevo NL50NU has a toggle, an up, a down and a color-cycle key
- TongFang PH4ARX1 doesn't have a toggle key, but one that cycles through
   off, half-brightness, and full-brightness.

Also, on some devices these keys are already implemented in firmware. It
would still be nice if there is a way to let userspace know when one of
these keys is pressed to display the OSD, but don't advice it to actually
do anything. This is the intended purpose of the KEY_KBDILLUMCHANGE define.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Can you please point to the user-space patches (or issues filed) that would integrate the support for those keycodes, and make the key presses do something?

I'm sorry to say that these don't exist yet. So I guess the process is similar to DRM uAPI additions? https://docs.kernel.org/gpu/drm-uapi.html#open-source-userspace-requirements

I asked the KDE and Gnome maintainers for feedback: https://bugs.kde.org/show_bug.cgi?id=470453 https://gitlab.gnome.org/GNOME/gnome-settings-daemon/-/issues/746

Quoted 30 lines
Quoted 4 lines

Has anyone tested that those keycodes are fit for purpose when mixed with other brightness changes that don't happen through key presses?

Color control is not yet implemented in any DE afaik, so there is not yet a collision with the color cycle key.

For the brightness cycle key, I would assume that it functions the same as the brightness up key unless brightness == brightness max. In this case it sets brightness to 0. I don't see a logical collision here as brightness up and brightness down are already implemented just fine in most DEs

Quoted 21 lines
Quoted 21 lines

---
  include/uapi/linux/input-event-codes.h | 4 ++++

  1 file changed, 4 insertions(+)
include/uapi/linux/input-event-codes.h +0 -0
index 022a520e31fc2..05287bf9a77f7 100644
@@ -803,6 +803,10 @@
   #define BTN_TRIGGER_HAPPY39            0x2e6
   #define BTN_TRIGGER_HAPPY40            0x2e7

  +#define KEY_KBDILLUMCYCLE              0x2e8

include/uapi/linux/input-event-codes.h +3 -0
+#define KEY_KBDILLUMCOLORCYCLE         0x2e9
+#define KEY_KBDILLUMCHANGE             0x2ea
+

  /* We avoid low common keys in module aliases so they don't get huge. */
  #define KEY_MIN_INTERESTING    KEY_MUTE
  #define KEY_MAX                        0x2ff

#4 lore raw
In reply to Werner Sembach

Am 30.05.23 um 13:05 schrieb Werner Sembach:

Quoted 8 lines

The old three KEY_KBDILLUM* keycodes don't reflect the current situation modern notebooks anymore. Especially the ones with RGB keyboards.

e.g.
- Clevo NL50NU has a toggle, an up, a down and a color-cycle key
- TongFang PH4ARX1 doesn't have a toggle key, but one that cycles through off, half-brightness, and full-brightness.

Quoted 4 lines

Also, on some devices these keys are already implemented in firmware. It would still be nice if there is a way to let userspace know when one of these keys is pressed to display the OSD, but don't advice it to actually do anything. This is the intended purpose of the KEY_KBDILLUMCHANGE define.

Nevermind the KEY_KBDILLUMCHANGE. I just found out there is already a way to communicate this from kernel to userspace via sysfs https://docs.kernel.org/leds/leds-class.html#led-registration-api -> brightness_hw_changed

Quoted 21 lines
---
  include/uapi/linux/input-event-codes.h | 4 ++++
  1 file changed, 4 insertions(+)
include/uapi/linux/input-event-codes.h +4 -0
index 022a520e31fc2..05287bf9a77f7 100644
@@ -803,6 +803,10 @@
  #define BTN_TRIGGER_HAPPY39		0x2e6
  #define BTN_TRIGGER_HAPPY40		0x2e7
 
+#define KEY_KBDILLUMCYCLE		0x2e8
+#define KEY_KBDILLUMCOLORCYCLE		0x2e9
+#define KEY_KBDILLUMCHANGE		0x2ea
+
  /* We avoid low common keys in module aliases so they don't get huge. */
  #define KEY_MIN_INTERESTING	KEY_MUTE
  #define KEY_MAX			0x2ff
#5 lore raw
In reply to Werner Sembach

Hi Werner,

Thank you for your patch.

Quoted 23 lines · Werner Sembach

The old three KEY_KBDILLUM* keycodes don't reflect the current situation modern notebooks anymore. Especially the ones with RGB keyboards.

e.g.
- Clevo NL50NU has a toggle, an up, a down and a color-cycle key
- TongFang PH4ARX1 doesn't have a toggle key, but one that cycles through off, half-brightness, and full-brightness.

Also, on some devices these keys are already implemented in firmware. It would still be nice if there is a way to let userspace know when one of these keys is pressed to display the OSD, but don't advice it to actually do anything. This is the intended purpose of the KEY_KBDILLUMCHANGE define.

---
 include/uapi/linux/input-event-codes.h | 4 ++++
 1 file changed, 4 insertions(+)
include/uapi/linux/input-event-codes.h +0 -0
index 022a520e31fc2..05287bf9a77f7 100644

include/uapi/linux/input-event-codes.h line 806

Quoted 4 lines
include/uapi/linux/input-event-codes.h +1 -0
@@ -803,6 +803,10 @@
 #define BTN_TRIGGER_HAPPY39		0x2e6
 #define BTN_TRIGGER_HAPPY40		0x2e7
 
+#define KEY_KBDILLUMCYCLE		0x2e8

I do not really see what the difference is between this and the existing KEY_KBDILLUMTOGGLE, userspace can already choice whether it toggles to a number of states or just toggles on/off.

So IMHO this one should be dropped.

include/uapi/linux/input-event-codes.h line 807

Quoted 1 line
include/uapi/linux/input-event-codes.h +1 -0
+#define KEY_KBDILLUMCOLORCYCLE		0x2e9

This one is fine.

include/uapi/linux/input-event-codes.h line 808

Quoted 1 line
include/uapi/linux/input-event-codes.h +1 -0
+#define KEY_KBDILLUMCHANGE		0x2ea

Keyboard backlight support should be exported to userspace as a LED class device, see e.g. :

drivers/platform/x86/thinkpad_acpi.c : tpacpi_led_kbdlight
drivers/platform/x86/dell/dell-laptop.c : kbd_led

And the LED class device sysfs API already has a mechanism for signalling kbd-brightness changes triggered by the hw itself (e.g. by the embedded controller) to userspace. See the use of the LED_BRIGHT_HW_CHANGED flag and the calling of led_classdev_notify_brightness_hw_changed() in the 2 above drivers.

So strong NACK for adding KEY_KBDILLUMCHANGE, this is duplicate with the led_classdev_notify_brightness_hw_changed() functionality which is already supported by userspace. E.g. GNOME will show an OSD notification similar to the sound volume change OSD when changing the keyboard brightness through EC handled hotkeys on ThinkPads and various Dell models.

TL;DR: to me only KEY_KBDILLUMCOLORCYCLE makes sense, assuming that this needs to be handled by userspace, if this is handled in the EC then this too should simply call led_classdev_notify_brightness_hw_changed()

Regards,

Hans

Quoted 4 lines
include/uapi/linux/input-event-codes.h +1 -0
+
 /* We avoid low common keys in module aliases so they don't get huge. */
 #define KEY_MIN_INTERESTING	KEY_MUTE
 #define KEY_MAX			0x2ff