Skip to contentSkip to conversation

Input: Add a helper for reporting a screen lock key sequence

PATCH In review Mario Limonciello 2 participants 5 messages Apr 7, 2025 – Apr 16, 2025

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

PATCH 1/2 Input: Add a helper for reporting a screen lock key sequence

From: Mario Limonciello <[email protected]>

In the PC industry KEY_SCREENLOCK isn't used as frequently as it used to be. Modern versions of Windows [1], GNOME and KDE support "META" + "L" to lock the screen. Modern hardware [2] also sends this sequence of events for keys with a silkscreen for screen lock.

Introduced a helper input_report_lock_sequence() for drivers to utilize if they want to send this sequence.

---
 drivers/input/input.c | 20 ++++++++++++++++++++
 include/linux/input.h |  2 ++
 2 files changed, 22 insertions(+)
drivers/input/input.c +20 -0
index ec4346f20efdd..dfeace85c4710 100644
@@ -508,6 +508,26 @@ void input_copy_abs(struct input_dev *dst, unsigned int dst_axis,
 }
 EXPORT_SYMBOL(input_copy_abs);
 
+/**
+ * input_report_lock_sequence - Report key combination to lock the screen
+ * @dev: input device
+ *
+ * Key combination used in the PC industry since Windows 7 for locking display
+ * is META + L. This is also used in GNOME and KDE by default.
+ * See https://support.microsoft.com/en-us/windows/keyboard-shortcuts-in-windows-dcc61a57-8ff0-cffe-9796-cb9706c75eec
+ */
+void input_report_lock_sequence(struct input_dev *dev)
+{
+	input_report_key(dev, KEY_LEFTMETA, 1);
+	input_report_key(dev, KEY_L, 1);
+	input_sync(dev);
+	input_report_key(dev, KEY_L, 0);
+	input_sync(dev);
+	input_report_key(dev, KEY_LEFTMETA, 0);
+	input_sync(dev);
+}
+EXPORT_SYMBOL(input_report_lock_sequence);
+
 /**
  * input_grab_device - grabs device for exclusive use
  * @handle: input handle that wants to own the device
include/linux/input.h +2 -0
index 7d7cb0593a63e..16f7bef12f1c1 100644
@@ -492,6 +492,8 @@ void input_set_abs_params(struct input_dev *dev, unsigned int axis,
 void input_copy_abs(struct input_dev *dst, unsigned int dst_axis,
 		    const struct input_dev *src, unsigned int src_axis);
 
+void input_report_lock_sequence(struct input_dev *dev);
+
 #define INPUT_GENERATE_ABS_ACCESSORS(_suffix, _item)			\
 static inline int input_abs_get_##_suffix(struct input_dev *dev,	\
 					  unsigned int axis)		\
Signature · 1 line
2.43.0
#1 lore raw

PATCH 2/2 platform/x86/amd: pmf: Use meta + L for screen lock command

From: Mario Limonciello <[email protected]>

In practice userspace software doesn't react to KEY_SCREENLOCK by default. So any time that the PMF policies would suggest to lock the screen (for example from an HPD sensor event) userspace isn't configured to do it.

However userspace is configured for meta + L as this is the default in the PC ecosystem. Adjust the PMF driver to send meta + L.

---
v2:
* Use helper from linux-input

---
 drivers/platform/x86/amd/pmf/tee-if.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/platform/x86/amd/pmf/tee-if.c +3 -2
index 20521d1f28f22..4bda905c3ba5c 100644
@@ -170,7 +170,7 @@ static void amd_pmf_apply_policies(struct amd_pmf_dev *dev, struct ta_pmf_enact_
 				amd_pmf_update_uevents(dev, KEY_SUSPEND);
 				break;
 			case 2:
-				amd_pmf_update_uevents(dev, KEY_SCREENLOCK);
+				input_report_lock_sequence(dev->pmf_idev);
 				break;
 			default:
 				dev_err(dev->dev, "Invalid PMF policy system state: %d\n", val);
@@ -441,8 +441,9 @@ int amd_pmf_register_input_device(struct amd_pmf_dev *dev)
 	dev->pmf_idev->phys = "amd-pmf/input0";
 
 	input_set_capability(dev->pmf_idev, EV_KEY, KEY_SLEEP);
-	input_set_capability(dev->pmf_idev, EV_KEY, KEY_SCREENLOCK);
 	input_set_capability(dev->pmf_idev, EV_KEY, KEY_SUSPEND);
+	input_set_capability(dev->pmf_idev, EV_KEY, KEY_L);
+	input_set_capability(dev->pmf_idev, EV_KEY, KEY_LEFTMETA);
 
 	err = input_register_device(dev->pmf_idev);
 	if (err) {
Signature · 1 line
2.43.0
#2 lore raw
In reply to Mario Limonciello

Am 07.04.25 um 17:27 schrieb Mario Limonciello:

Quoted 25 lines

From: Mario Limonciello <[email protected]>

In the PC industry KEY_SCREENLOCK isn't used as frequently as it used to be. Modern versions of Windows [1], GNOME and KDE support "META" + "L" to lock the screen. Modern hardware [2] also sends this sequence of events for keys with a silkscreen for screen lock.

Introduced a helper input_report_lock_sequence() for drivers to utilize if they want to send this sequence.

---
  drivers/input/input.c | 20 ++++++++++++++++++++
  include/linux/input.h |  2 ++
  2 files changed, 22 insertions(+)
drivers/input/input.c +0 -0
index ec4346f20efdd..dfeace85c4710 100644
@@ -508,6 +508,26 @@ void input_copy_abs(struct input_dev *dst, unsigned int dst_axis,
  }

drivers/input/input.c void input_copy_abs(struct input_dev *dst, unsigned int dst_axis, · line 518

Quoted 10 lines
drivers/input/input.c +8 -0
  EXPORT_SYMBOL(input_copy_abs);
 
+/**
+ * input_report_lock_sequence - Report key combination to lock the screen
+ * @dev: input device
+ *
+ * Key combination used in the PC industry since Windows 7 for locking display
+ * is META + L. This is also used in GNOME and KDE by default.
+ * See https://support.microsoft.com/en-us/windows/keyboard-shortcuts-in-windows-dcc61a57-8ff0-cffe-9796-cb9706c75eec
+ */

Hi,

maybe it would make more sense to have the input subsystem transparently translate between KEY_SCREENLOCK and this special screen lock sequence. This way there would be no room for regressions as people could enable/disable this behavior via Kconfig.

Thanks,
Armin Wolf

Quoted 28 lines
drivers/input/input.c +12 -0
+void input_report_lock_sequence(struct input_dev *dev)
+{
+	input_report_key(dev, KEY_LEFTMETA, 1);
+	input_report_key(dev, KEY_L, 1);
+	input_sync(dev);
+	input_report_key(dev, KEY_L, 0);
+	input_sync(dev);
+	input_report_key(dev, KEY_LEFTMETA, 0);
+	input_sync(dev);
+}
+EXPORT_SYMBOL(input_report_lock_sequence);
+
  /**
   * input_grab_device - grabs device for exclusive use
   * @handle: input handle that wants to own the device
include/linux/input.h +2 -0
index 7d7cb0593a63e..16f7bef12f1c1 100644
@@ -492,6 +492,8 @@ void input_set_abs_params(struct input_dev *dev, unsigned int axis,
  void input_copy_abs(struct input_dev *dst, unsigned int dst_axis,
  		    const struct input_dev *src, unsigned int src_axis);
 
+void input_report_lock_sequence(struct input_dev *dev);
+
  #define INPUT_GENERATE_ABS_ACCESSORS(_suffix, _item)			\
  static inline int input_abs_get_##_suffix(struct input_dev *dev,	\
  					  unsigned int axis)		\
#3 lore raw
Quoted 43 lines · Armin Wolf

Am 07.04.25 um 17:27 schrieb Mario Limonciello:

Quoted 30 lines

From: Mario Limonciello <[email protected]>

In the PC industry KEY_SCREENLOCK isn't used as frequently as it used to be. Modern versions of Windows [1], GNOME and KDE support "META" + "L" to lock the screen. Modern hardware [2] also sends this sequence of events for keys with a silkscreen for screen lock.

Introduced a helper input_report_lock_sequence() for drivers to utilize if they want to send this sequence.

---
  drivers/input/input.c | 20 ++++++++++++++++++++
  include/linux/input.h |  2 ++

  2 files changed, 22 insertions(+)
drivers/input/input.c +2 -0
index ec4346f20efdd..dfeace85c4710 100644
@@ -508,6 +508,26 @@ void input_copy_abs(struct input_dev *dst, 
 unsigned int dst_axis,
   }
   EXPORT_SYMBOL(input_copy_abs);
+/**
+ * input_report_lock_sequence - Report key combination to lock the 

screen

Quoted 8 lines

+ * @dev: input device
+ *
+ * Key combination used in the PC industry since Windows 7 for locking display
+ * is META + L. This is also used in GNOME and KDE by default.
+ * See https://support.microsoft.com/en-us/windows/keyboard-
shortcuts-in-windows-dcc61a57-8ff0-cffe-9796-cb9706c75eec
+ */

Hi,

Quoted 3 lines

maybe it would make more sense to have the input subsystem transparently translate between KEY_SCREENLOCK and this special screen lock sequence. This way there would be no room for regressions as people could enable/disable this behavior via Kconfig.

Wouldn't all drivers that emit KEY_SCREENLOCK still need to be modified to have support to emit KEY_LEFTMETA and KEY_L?

Wouldn't that mean conditional code in every single driver based on the Kconfig?

Is that worth it?

Quoted 32 lines

Thanks,
Armin Wolf

Quoted 28 lines
drivers/input/input.c +12 -0
+void input_report_lock_sequence(struct input_dev *dev)
+{
+    input_report_key(dev, KEY_LEFTMETA, 1);
+    input_report_key(dev, KEY_L, 1);
+    input_sync(dev);
+    input_report_key(dev, KEY_L, 0);
+    input_sync(dev);
+    input_report_key(dev, KEY_LEFTMETA, 0);
+    input_sync(dev);
+}
+EXPORT_SYMBOL(input_report_lock_sequence);
+

  /**
   * input_grab_device - grabs device for exclusive use
   * @handle: input handle that wants to own the device

include/linux/input.h +2 -0
index 7d7cb0593a63e..16f7bef12f1c1 100644
@@ -492,6 +492,8 @@ void input_set_abs_params(struct input_dev *dev, 
 unsigned int axis,
   void input_copy_abs(struct input_dev *dst, unsigned int dst_axis,
               const struct input_dev *src, unsigned int src_axis);
+void input_report_lock_sequence(struct input_dev *dev);
+
   #define INPUT_GENERATE_ABS_ACCESSORS(_suffix, _item)            \
   static inline int input_abs_get_##_suffix(struct input_dev *dev,    \
                         unsigned int axis)        \
#4 lore raw

Am 16.04.25 um 22:43 schrieb Mario Limonciello:

Quoted 49 lines · Armin Wolf
Quoted 44 lines

Am 07.04.25 um 17:27 schrieb Mario Limonciello:

Quoted 31 lines

From: Mario Limonciello <[email protected]>

In the PC industry KEY_SCREENLOCK isn't used as frequently as it used to be. Modern versions of Windows [1], GNOME and KDE support "META"
+ "L"
to lock the screen. Modern hardware [2] also sends this sequence of events for keys with a silkscreen for screen lock.

Introduced a helper input_report_lock_sequence() for drivers to utilize if they want to send this sequence.

---
  drivers/input/input.c | 20 ++++++++++++++++++++
  include/linux/input.h |  2 ++

  2 files changed, 22 insertions(+)
drivers/input/input.c +2 -0
index ec4346f20efdd..dfeace85c4710 100644
@@ -508,6 +508,26 @@ void input_copy_abs(struct input_dev *dst, 
 unsigned int dst_axis,
   }
   EXPORT_SYMBOL(input_copy_abs);
+/**
+ * input_report_lock_sequence - Report key combination to lock the 

screen

Quoted 8 lines

+ * @dev: input device
+ *
+ * Key combination used in the PC industry since Windows 7 for locking display
+ * is META + L. This is also used in GNOME and KDE by default.
+ * See https://support.microsoft.com/en-us/windows/keyboard-
shortcuts-in-windows-dcc61a57-8ff0-cffe-9796-cb9706c75eec
+ */

Hi,

Quoted 3 lines

maybe it would make more sense to have the input subsystem transparently translate between KEY_SCREENLOCK and this special screen lock sequence. This way there would be no room for regressions as people could enable/disable this behavior via Kconfig.

Quoted 6 lines

Wouldn't all drivers that emit KEY_SCREENLOCK still need to be modified to have support to emit KEY_LEFTMETA and KEY_L?

Wouldn't that mean conditional code in every single driver based on the Kconfig?

Is that worth it?

This translation code could live inside the input code itself. This way all drivers would benefit from it.

Thanks,
Armin Wolf

Quoted 33 lines
Quoted 32 lines

Thanks,
Armin Wolf

Quoted 28 lines
drivers/input/input.c +12 -0
+void input_report_lock_sequence(struct input_dev *dev)
+{
+    input_report_key(dev, KEY_LEFTMETA, 1);
+    input_report_key(dev, KEY_L, 1);
+    input_sync(dev);
+    input_report_key(dev, KEY_L, 0);
+    input_sync(dev);
+    input_report_key(dev, KEY_LEFTMETA, 0);
+    input_sync(dev);
+}
+EXPORT_SYMBOL(input_report_lock_sequence);
+

  /**
   * input_grab_device - grabs device for exclusive use
   * @handle: input handle that wants to own the device

include/linux/input.h +2 -0
index 7d7cb0593a63e..16f7bef12f1c1 100644
@@ -492,6 +492,8 @@ void input_set_abs_params(struct input_dev *dev, 
 unsigned int axis,
   void input_copy_abs(struct input_dev *dst, unsigned int dst_axis,
               const struct input_dev *src, unsigned int src_axis);
+void input_report_lock_sequence(struct input_dev *dev);
+
   #define INPUT_GENERATE_ABS_ACCESSORS(_suffix, _item)            \
   static inline int input_abs_get_##_suffix(struct input_dev *dev,    \
                         unsigned int axis)        \