linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paul Collins <paul@burly.ondioline.org>
To: Jiri Kosina <jkosina@suse.cz>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] hid/apple: add module parameter to swap the Command and Option keys
Date: Fri, 06 Mar 2009 18:33:18 +1300	[thread overview]
Message-ID: <87zlfz8bc1.fsf@burly.wgtn.ondioline.org> (raw)

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(-)

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) {

-- 
Paul Collins
Wellington, New Zealand

Dag vijandelijk luchtschip de huismeester is dood

             reply	other threads:[~2009-03-06  5:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-06  5:33 Paul Collins [this message]
2009-03-06  5:41 ` [PATCH] hid/apple: add module parameter to swap the Command and Option keys Randy Dunlap
2009-03-06  5:55   ` Paul Collins
2009-03-06 22:13 ` Jiri Slaby
2009-03-07  4:07   ` [PATCH 1/2] hid/apple: add module parameter to swap " Paul Collins
2009-03-07  4:07     ` [PATCH 2/2] hid/apple: constify arrays of struct apple_key_translation and adjust users Paul Collins
2009-03-18 12:59       ` Jiri Kosina
2009-03-07 19:12     ` [PATCH 1/2] hid/apple: add module parameter to swap Command and Option keys Dmitry Torokhov
2009-03-11 12:31     ` Jiri Kosina

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zlfz8bc1.fsf@burly.wgtn.ondioline.org \
    --to=paul@burly.ondioline.org \
    --cc=jkosina@suse.cz \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).