hid/apple: add module parameter to swap the Command and Option keys
diff mbox series

Message ID 87zlfz8bc1.fsf@burly.wgtn.ondioline.org
State New, archived
Headers show
Series
  • hid/apple: add module parameter to swap the Command and Option keys
Related show

Commit Message

Paul Collins March 6, 2009, 5:33 a.m. UTC
Apple keyboards have the Command keys (a.k.a. the Apple or "waffle" key)
in the positions normally occupied on PC keyboards by the Alt/AltGr keys,
and the Option or Alt keys in the position occupied by the so-called
Windows keys.  Folks who have been using PC-type computers for too long
generally have insurmountable muscle memory in this regard.

This patch adds a module parameter, defaulting to off, that swaps these keys.

The same effect can also be achieved by changing the console and X
keymaps, but this approach does not scale.  For example, I don't want to
have to learn how to reconfigure Wayland's keymaps when the future
arrives and we all start using it, and there may be applications I don't
know about that also read keyboard events directly.

Signed-off-by: Paul Collins <paul@ondioline.org>
---
 drivers/hid/hid-apple.c |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)

Comments

Randy Dunlap March 6, 2009, 5:41 a.m. UTC | #1
Paul Collins wrote:
> Apple keyboards have the Command keys (a.k.a. the Apple or "waffle" key)
> in the positions normally occupied on PC keyboards by the Alt/AltGr keys,
> and the Option or Alt keys in the position occupied by the so-called
> Windows keys.  Folks who have been using PC-type computers for too long
> generally have insurmountable muscle memory in this regard.
> 
> This patch adds a module parameter, defaulting to off, that swaps these keys.
> 
> The same effect can also be achieved by changing the console and X
> keymaps, but this approach does not scale.  For example, I don't want to
> have to learn how to reconfigure Wayland's keymaps when the future
> arrives and we all start using it, and there may be applications I don't
> know about that also read keyboard events directly.

Hi,
Where do you suggest that this option be documented?

> Signed-off-by: Paul Collins <paul@ondioline.org>
> ---
>  drivers/hid/hid-apple.c |   21 +++++++++++++++++++++
>  1 files changed, 21 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
> index 7ed94cf..63e9ee3 100644
> --- a/drivers/hid/hid-apple.c
> +++ b/drivers/hid/hid-apple.c
> @@ -40,6 +40,11 @@ module_param(fnmode, uint, 0644);
>  MODULE_PARM_DESC(fnmode, "Mode of fn key on Apple keyboards (0 = disabled, "
>  		"[1] = fkeyslast, 2 = fkeysfirst)");
>  
> +static unsigned int swapmodifiers = 0;
> +module_param(swapmodifiers, uint, 0644);
> +MODULE_PARM_DESC(fnmode, "Modifiers match labels or positions "
> +		 "([0] = labels, 1 = positions)");
> +
>  struct apple_sc {
>  	unsigned long quirks;
>  	unsigned int fn_on;
> @@ -123,6 +128,14 @@ static struct apple_key_translation apple_iso_keyboard[] = {
>  	{ }
>  };
>  
> +static struct apple_key_translation apple_swap_modifiers[] = {
> +	{ KEY_LEFTALT,	KEY_LEFTMETA },
> +	{ KEY_RIGHTALT,	KEY_RIGHTMETA },
> +	{ KEY_LEFTMETA,	KEY_LEFTALT },
> +	{ KEY_RIGHTMETA, KEY_RIGHTALT },
> +	{ }
> +};
> +
>  static struct apple_key_translation *apple_find_translation(
>  		struct apple_key_translation *table, u16 from)
>  {
> @@ -199,6 +212,14 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
>  		}
>  	}
>  
> +	if (swapmodifiers) {
> +		trans = apple_find_translation(apple_swap_modifiers, usage->code);
> +		if (trans) {
> +			input_event(input, usage->type, trans->to, value);
> +			return 1;
> +		}
> +	}
> +
>  	if (asc->quirks & APPLE_ISO_KEYBOARD) {
>  		trans = apple_find_translation(apple_iso_keyboard, usage->code);
>  		if (trans) {
> 

Thanks,
Paul Collins March 6, 2009, 5:55 a.m. UTC | #2
Randy Dunlap <randy.dunlap@oracle.com> writes:

> Paul Collins wrote:
>> Apple keyboards have the Command keys (a.k.a. the Apple or "waffle" key)
>> in the positions normally occupied on PC keyboards by the Alt/AltGr keys,
>> and the Option or Alt keys in the position occupied by the so-called
>> Windows keys.  Folks who have been using PC-type computers for too long
>> generally have insurmountable muscle memory in this regard.
>> 
>> This patch adds a module parameter, defaulting to off, that swaps these keys.
>
> Where do you suggest that this option be documented?

Existing practice is to not document hid-apple options

        [burly(linux-2.6)] grep -r fnmode Documentation/ | wc -l
        0

so I'm open to suggestions.
Jiri Slaby March 6, 2009, 10:13 p.m. UTC | #3
On 6.3.2009 06:33, Paul Collins wrote:
> --- a/drivers/hid/hid-apple.c
> +++ b/drivers/hid/hid-apple.c
> @@ -40,6 +40,11 @@ module_param(fnmode, uint, 0644);
>   MODULE_PARM_DESC(fnmode, "Mode of fn key on Apple keyboards (0 = disabled, "
>   		"[1] = fkeyslast, 2 = fkeysfirst)");
>
> +static unsigned int swapmodifiers = 0;

Nowadays compilers optimize this away already, but no need to initialize 
.bss stuff to zero anyway.

> +module_param(swapmodifiers, uint, 0644);
> +MODULE_PARM_DESC(fnmode, "Modifiers match labels or positions "

Weird first parameter => swapmodifiers.

Maybe this should rather be a bool instead of uint.

> +		 "([0] = labels, 1 = positions)");
> +
>   struct apple_sc {
>   	unsigned long quirks;
>   	unsigned int fn_on;
> @@ -123,6 +128,14 @@ static struct apple_key_translation apple_iso_keyboard[] = {
>   	{ }
>   };
>
> +static struct apple_key_translation apple_swap_modifiers[] = {

This might go into .rodata, right? => const

Anyway this is not feasible to do in this patch. Would you like to post 
a followup patch which will also modify the functions which use the 
translation tables?
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Patch
diff mbox series

diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
index 7ed94cf..63e9ee3 100644
--- a/drivers/hid/hid-apple.c
+++ b/drivers/hid/hid-apple.c
@@ -40,6 +40,11 @@  module_param(fnmode, uint, 0644);
 MODULE_PARM_DESC(fnmode, "Mode of fn key on Apple keyboards (0 = disabled, "
 		"[1] = fkeyslast, 2 = fkeysfirst)");
 
+static unsigned int swapmodifiers = 0;
+module_param(swapmodifiers, uint, 0644);
+MODULE_PARM_DESC(fnmode, "Modifiers match labels or positions "
+		 "([0] = labels, 1 = positions)");
+
 struct apple_sc {
 	unsigned long quirks;
 	unsigned int fn_on;
@@ -123,6 +128,14 @@  static struct apple_key_translation apple_iso_keyboard[] = {
 	{ }
 };
 
+static struct apple_key_translation apple_swap_modifiers[] = {
+	{ KEY_LEFTALT,	KEY_LEFTMETA },
+	{ KEY_RIGHTALT,	KEY_RIGHTMETA },
+	{ KEY_LEFTMETA,	KEY_LEFTALT },
+	{ KEY_RIGHTMETA, KEY_RIGHTALT },
+	{ }
+};
+
 static struct apple_key_translation *apple_find_translation(
 		struct apple_key_translation *table, u16 from)
 {
@@ -199,6 +212,14 @@  static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
 		}
 	}
 
+	if (swapmodifiers) {
+		trans = apple_find_translation(apple_swap_modifiers, usage->code);
+		if (trans) {
+			input_event(input, usage->type, trans->to, value);
+			return 1;
+		}
+	}
+
 	if (asc->quirks & APPLE_ISO_KEYBOARD) {
 		trans = apple_find_translation(apple_iso_keyboard, usage->code);
 		if (trans) {