linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 1/2] Input: Add a Kconfig to emulate KEY_SCREENLOCK with META + L
@ 2025-04-17  1:37 Mario Limonciello
  2025-04-17  1:37 ` [PATCH v3 2/2] platform/x86/amd: pmf: Use META + L for screen lock command Mario Limonciello
  2025-04-17 10:48 ` [PATCH v3 1/2] Input: Add a Kconfig to emulate KEY_SCREENLOCK with META + L Hans de Goede
  0 siblings, 2 replies; 4+ messages in thread
From: Mario Limonciello @ 2025-04-17  1:37 UTC (permalink / raw)
  To: Dmitry Torokhov, Shyam Sundar S K, Ilpo Järvinen
  Cc: Hans de Goede,
	open list:INPUT (KEYBOARD, MOUSE, JOYSTICK, TOUCHSCREEN)...,
	open list, open list:AMD PMF DRIVER, Mario Limonciello,
	Armin Wolf

From: Mario Limonciello <mario.limonciello@amd.com>

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 new Kconfig option that will change KEY_SCREENLOCK when
emitted by driver to META + L.

Link: https://support.microsoft.com/en-us/windows/keyboard-shortcuts-in-windows-dcc61a57-8ff0-cffe-9796-cb9706c75eec [1]
Link: https://www.logitech.com/en-us/shop/p/k860-split-ergonomic.920-009166 [2]
Suggested-by: Armin Wolf <W_Armin@gmx.de>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
v3:
 * Emulation in the input core instead

 drivers/input/Kconfig |  8 ++++++++
 drivers/input/input.c | 19 +++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
index 88ecdf5218ee9..ffb4163fe315f 100644
--- a/drivers/input/Kconfig
+++ b/drivers/input/Kconfig
@@ -174,6 +174,14 @@ config INPUT_APMPOWER
 	  To compile this driver as a module, choose M here: the
 	  module will be called apm-power.
 
+config INPUT_SCREENLOCK_EMULATION
+	bool "Pass KEY_SCREENLOCK as META + L"
+	help
+	  Say Y here if you want KEY_SCREENLOCK to be passed to userspace as
+	  META + L.
+
+	  If unsure, say Y.
+
 comment "Input Device Drivers"
 
 source "drivers/input/keyboard/Kconfig"
diff --git a/drivers/input/input.c b/drivers/input/input.c
index dfeace85c4710..08a857cea0c5d 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -370,6 +370,13 @@ void input_handle_event(struct input_dev *dev,
 	}
 }
 
+static void handle_screenlock_as_meta_l(struct input_dev *dev, unsigned int type,
+					int value)
+{
+	input_handle_event(dev, type, KEY_LEFTMETA, value);
+	input_handle_event(dev, type, KEY_L, value);
+}
+
 /**
  * input_event() - report new input event
  * @dev: device that generated the event
@@ -392,6 +399,12 @@ void input_event(struct input_dev *dev,
 {
 	if (is_event_supported(type, dev->evbit, EV_MAX)) {
 		guard(spinlock_irqsave)(&dev->event_lock);
+#ifdef CONFIG_INPUT_SCREENLOCK_EMULATION
+		if (code == KEY_SCREENLOCK) {
+			handle_screenlock_as_meta_l(dev, type, value);
+			return;
+		}
+#endif
 		input_handle_event(dev, type, code, value);
 	}
 }
@@ -2134,6 +2147,12 @@ void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int
 
 	switch (type) {
 	case EV_KEY:
+#ifdef CONFIG_INPUT_SCREENLOCK_EMULATION
+		if (code == KEY_SCREENLOCK) {
+			__set_bit(KEY_L, dev->keybit);
+			__set_bit(KEY_LEFTMETA, dev->keybit);
+		}
+#endif
 		__set_bit(code, dev->keybit);
 		break;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v3 2/2] platform/x86/amd: pmf: Use META + L for screen lock command
  2025-04-17  1:37 [PATCH v3 1/2] Input: Add a Kconfig to emulate KEY_SCREENLOCK with META + L Mario Limonciello
@ 2025-04-17  1:37 ` Mario Limonciello
  2025-04-17 10:48 ` [PATCH v3 1/2] Input: Add a Kconfig to emulate KEY_SCREENLOCK with META + L Hans de Goede
  1 sibling, 0 replies; 4+ messages in thread
From: Mario Limonciello @ 2025-04-17  1:37 UTC (permalink / raw)
  To: Dmitry Torokhov, Shyam Sundar S K, Ilpo Järvinen
  Cc: Hans de Goede,
	open list:INPUT (KEYBOARD, MOUSE, JOYSTICK, TOUCHSCREEN)...,
	open list, open list:AMD PMF DRIVER, Mario Limonciello

From: Mario Limonciello <mario.limonciello@amd.com>

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 select the Kconfig option
that makes the input core send META + L.

Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
v3:
    * Use Kconfig from linux-input
---
 drivers/platform/x86/amd/pmf/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/platform/x86/amd/pmf/Kconfig b/drivers/platform/x86/amd/pmf/Kconfig
index 25b8f7ae3abde..10089c69ce582 100644
--- a/drivers/platform/x86/amd/pmf/Kconfig
+++ b/drivers/platform/x86/amd/pmf/Kconfig
@@ -12,6 +12,7 @@ config AMD_PMF
 	depends on TEE && AMDTEE
 	depends on AMD_SFH_HID
 	depends on HAS_IOMEM
+	select INPUT_SCREENLOCK_EMULATION
 	help
 	  This driver provides support for the AMD Platform Management Framework.
 	  The goal is to enhance end user experience by making AMD PCs smarter,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v3 1/2] Input: Add a Kconfig to emulate KEY_SCREENLOCK with META + L
  2025-04-17  1:37 [PATCH v3 1/2] Input: Add a Kconfig to emulate KEY_SCREENLOCK with META + L Mario Limonciello
  2025-04-17  1:37 ` [PATCH v3 2/2] platform/x86/amd: pmf: Use META + L for screen lock command Mario Limonciello
@ 2025-04-17 10:48 ` Hans de Goede
  2025-04-17 12:02   ` Mario Limonciello
  1 sibling, 1 reply; 4+ messages in thread
From: Hans de Goede @ 2025-04-17 10:48 UTC (permalink / raw)
  To: Mario Limonciello, Dmitry Torokhov, Shyam Sundar S K,
	Ilpo Järvinen
  Cc: open list:INPUT (KEYBOARD, MOUSE, JOYSTICK, TOUCHSCREEN)...,
	open list, open list:AMD PMF DRIVER, Mario Limonciello,
	Armin Wolf

Hi Mario,

On 17-Apr-25 3:37 AM, Mario Limonciello wrote:
> From: Mario Limonciello <mario.limonciello@amd.com>
> 
> 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 new Kconfig option that will change KEY_SCREENLOCK when
> emitted by driver to META + L.
> 
> Link: https://support.microsoft.com/en-us/windows/keyboard-shortcuts-in-windows-dcc61a57-8ff0-cffe-9796-cb9706c75eec [1]
> Link: https://www.logitech.com/en-us/shop/p/k860-split-ergonomic.920-009166 [2]
> Suggested-by: Armin Wolf <W_Armin@gmx.de>
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> ---
> v3:
>  * Emulation in the input core instead
> 
>  drivers/input/Kconfig |  8 ++++++++
>  drivers/input/input.c | 19 +++++++++++++++++++
>  2 files changed, 27 insertions(+)
> 
> diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
> index 88ecdf5218ee9..ffb4163fe315f 100644
> --- a/drivers/input/Kconfig
> +++ b/drivers/input/Kconfig
> @@ -174,6 +174,14 @@ config INPUT_APMPOWER
>  	  To compile this driver as a module, choose M here: the
>  	  module will be called apm-power.
>  
> +config INPUT_SCREENLOCK_EMULATION
> +	bool "Pass KEY_SCREENLOCK as META + L"
> +	help
> +	  Say Y here if you want KEY_SCREENLOCK to be passed to userspace as
> +	  META + L.
> +
> +	  If unsure, say Y.
> +
>  comment "Input Device Drivers"
>  
>  source "drivers/input/keyboard/Kconfig"
> diff --git a/drivers/input/input.c b/drivers/input/input.c
> index dfeace85c4710..08a857cea0c5d 100644
> --- a/drivers/input/input.c
> +++ b/drivers/input/input.c
> @@ -370,6 +370,13 @@ void input_handle_event(struct input_dev *dev,
>  	}
>  }
>  
> +static void handle_screenlock_as_meta_l(struct input_dev *dev, unsigned int type,
> +					int value)
> +{
> +	input_handle_event(dev, type, KEY_LEFTMETA, value);
> +	input_handle_event(dev, type, KEY_L, value);
> +}
> +
>  /**
>   * input_event() - report new input event
>   * @dev: device that generated the event
> @@ -392,6 +399,12 @@ void input_event(struct input_dev *dev,
>  {
>  	if (is_event_supported(type, dev->evbit, EV_MAX)) {
>  		guard(spinlock_irqsave)(&dev->event_lock);
> +#ifdef CONFIG_INPUT_SCREENLOCK_EMULATION
> +		if (code == KEY_SCREENLOCK) {
> +			handle_screenlock_as_meta_l(dev, type, value);
> +			return;
> +		}
> +#endif
>  		input_handle_event(dev, type, code, value);
>  	}
>  }
> @@ -2134,6 +2147,12 @@ void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int
>  
>  	switch (type) {
>  	case EV_KEY:
> +#ifdef CONFIG_INPUT_SCREENLOCK_EMULATION
> +		if (code == KEY_SCREENLOCK) {
> +			__set_bit(KEY_L, dev->keybit);
> +			__set_bit(KEY_LEFTMETA, dev->keybit);
> +		}

Shouldn't there be a "break;" inside the if?

Since KEY_SCREENLOCK events will never get reported when
CONFIG_INPUT_SCREENLOCK_EMULATION is set, I think it would
be netter to not set it in dev->keybit ?

Regards,

Hans




> +#endif
>  		__set_bit(code, dev->keybit);
>  		break;
>  


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3 1/2] Input: Add a Kconfig to emulate KEY_SCREENLOCK with META + L
  2025-04-17 10:48 ` [PATCH v3 1/2] Input: Add a Kconfig to emulate KEY_SCREENLOCK with META + L Hans de Goede
@ 2025-04-17 12:02   ` Mario Limonciello
  0 siblings, 0 replies; 4+ messages in thread
From: Mario Limonciello @ 2025-04-17 12:02 UTC (permalink / raw)
  To: Hans de Goede, Dmitry Torokhov, Shyam Sundar S K,
	Ilpo Järvinen
  Cc: open list:INPUT (KEYBOARD, MOUSE, JOYSTICK, TOUCHSCREEN)...,
	open list, open list:AMD PMF DRIVER, Mario Limonciello,
	Armin Wolf



On 4/17/25 05:48, Hans de Goede wrote:
> Hi Mario,
> 
> On 17-Apr-25 3:37 AM, Mario Limonciello wrote:
>> From: Mario Limonciello <mario.limonciello@amd.com>
>>
>> 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 new Kconfig option that will change KEY_SCREENLOCK when
>> emitted by driver to META + L.
>>
>> Link: https://support.microsoft.com/en-us/windows/keyboard-shortcuts-in-windows-dcc61a57-8ff0-cffe-9796-cb9706c75eec [1]
>> Link: https://www.logitech.com/en-us/shop/p/k860-split-ergonomic.920-009166 [2]
>> Suggested-by: Armin Wolf <W_Armin@gmx.de>
>> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
>> ---
>> v3:
>>   * Emulation in the input core instead
>>
>>   drivers/input/Kconfig |  8 ++++++++
>>   drivers/input/input.c | 19 +++++++++++++++++++
>>   2 files changed, 27 insertions(+)
>>
>> diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
>> index 88ecdf5218ee9..ffb4163fe315f 100644
>> --- a/drivers/input/Kconfig
>> +++ b/drivers/input/Kconfig
>> @@ -174,6 +174,14 @@ config INPUT_APMPOWER
>>   	  To compile this driver as a module, choose M here: the
>>   	  module will be called apm-power.
>>   
>> +config INPUT_SCREENLOCK_EMULATION
>> +	bool "Pass KEY_SCREENLOCK as META + L"
>> +	help
>> +	  Say Y here if you want KEY_SCREENLOCK to be passed to userspace as
>> +	  META + L.
>> +
>> +	  If unsure, say Y.
>> +
>>   comment "Input Device Drivers"
>>   
>>   source "drivers/input/keyboard/Kconfig"
>> diff --git a/drivers/input/input.c b/drivers/input/input.c
>> index dfeace85c4710..08a857cea0c5d 100644
>> --- a/drivers/input/input.c
>> +++ b/drivers/input/input.c
>> @@ -370,6 +370,13 @@ void input_handle_event(struct input_dev *dev,
>>   	}
>>   }
>>   
>> +static void handle_screenlock_as_meta_l(struct input_dev *dev, unsigned int type,
>> +					int value)
>> +{
>> +	input_handle_event(dev, type, KEY_LEFTMETA, value);
>> +	input_handle_event(dev, type, KEY_L, value);
>> +}
>> +
>>   /**
>>    * input_event() - report new input event
>>    * @dev: device that generated the event
>> @@ -392,6 +399,12 @@ void input_event(struct input_dev *dev,
>>   {
>>   	if (is_event_supported(type, dev->evbit, EV_MAX)) {
>>   		guard(spinlock_irqsave)(&dev->event_lock);
>> +#ifdef CONFIG_INPUT_SCREENLOCK_EMULATION
>> +		if (code == KEY_SCREENLOCK) {
>> +			handle_screenlock_as_meta_l(dev, type, value);
>> +			return;
>> +		}
>> +#endif
>>   		input_handle_event(dev, type, code, value);
>>   	}
>>   }
>> @@ -2134,6 +2147,12 @@ void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int
>>   
>>   	switch (type) {
>>   	case EV_KEY:
>> +#ifdef CONFIG_INPUT_SCREENLOCK_EMULATION
>> +		if (code == KEY_SCREENLOCK) {
>> +			__set_bit(KEY_L, dev->keybit);
>> +			__set_bit(KEY_LEFTMETA, dev->keybit);
>> +		}
> 
> Shouldn't there be a "break;" inside the if?
> 
> Since KEY_SCREENLOCK events will never get reported when
> CONFIG_INPUT_SCREENLOCK_EMULATION is set, I think it would
> be netter to not set it in dev->keybit ?
> 
> Regards,

This is something I wasn't sure about.

I was worried there might be other parts of the kernel that check for a 
capability of a specific keycode and conditionalize behavior.

If that isn't a concern yes I could add a break into this block in the 
next version.

> 
> Hans
> 
> 
> 
> 
>> +#endif
>>   		__set_bit(code, dev->keybit);
>>   		break;
>>   
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-04-17 12:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-17  1:37 [PATCH v3 1/2] Input: Add a Kconfig to emulate KEY_SCREENLOCK with META + L Mario Limonciello
2025-04-17  1:37 ` [PATCH v3 2/2] platform/x86/amd: pmf: Use META + L for screen lock command Mario Limonciello
2025-04-17 10:48 ` [PATCH v3 1/2] Input: Add a Kconfig to emulate KEY_SCREENLOCK with META + L Hans de Goede
2025-04-17 12:02   ` Mario Limonciello

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).