All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 5.7-rc5] HID: apple: Swap the Fn and Left Control keys on Apple keyboards
@ 2020-05-15  6:14 free5lot
  2020-05-15 10:26 ` Jiri Kosina
  0 siblings, 1 reply; 2+ messages in thread
From: free5lot @ 2020-05-15  6:14 UTC (permalink / raw)
  To: Jiri Kosina; +Cc: Benjamin Tissoires, Jiri Kosina, linux-input, linux-kernel

This patch allows users to swap the Fn and left Control keys on all Apple
keyboards: internal (e.g. Macbooks) and external (both wired and wireless).
The patch adds a new hid-apple module param: swap_fn_leftctrl (off by default).

Signed-off-by: Zakhar Semenov <mail@free5lot.com>
---
This patch was created to eliminate the inconvenience of having an unusual
order of 4 left-bottom keys on Apple keyboards for GNU+Linux users.
Now it's possible to swap the Fn and left Control keys on Macbooks and
external Apple keyboards and have the same experience as on usual PC layout.

The patch has been heavily tested for about 5 years by community at:
https://github.com/free5lot/hid-apple-patched
The patch is small and straightforward. The modified version of hid-apple
is currently mentioned in wiki-documentation of several major GNU/Linux
distributions (e.g. Ubuntu, Arch, openSUSE).


--- hid-apple.c.orig	2020-05-12 11:06:26.000000000 +0300
+++ hid-apple.c	2020-05-15 20:00:00.000000000 +0300
@@ -51,6 +51,12 @@ MODULE_PARM_DESC(swap_opt_cmd, "Swap the
  		"(For people who want to keep Windows PC keyboard muscle memory. "
  		"[0] = as-is, Mac layout. 1 = swapped, Windows layout.)");

+static unsigned int swap_fn_leftctrl;
+module_param(swap_fn_leftctrl, uint, 0644);
+MODULE_PARM_DESC(swap_fn_leftctrl, "Swap the Fn and left Control keys. "
+		"(For people who want to keep PC keyboard muscle memory. "
+		"[0] = as-is, Mac layout, 1 = swapped, PC layout)");
+
  struct apple_sc {
  	unsigned long quirks;
  	unsigned int fn_on;
@@ -162,6 +168,11 @@ static const struct apple_key_translatio
  	{ }
  };

+static const struct apple_key_translation swapped_fn_leftctrl_keys[] = {
+	{ KEY_FN, KEY_LEFTCTRL },
+	{ }
+};
+
  static const struct apple_key_translation *apple_find_translation(
  		const struct apple_key_translation *table, u16 from)
  {
@@ -183,9 +194,11 @@ static int hidinput_apple_event(struct h
  	bool do_translate;
  	u16 code = 0;

-	if (usage->code == KEY_FN) {
+	u16 fn_keycode = (swap_fn_leftctrl) ? (KEY_LEFTCTRL) : (KEY_FN);
+
+	if (usage->code == fn_keycode) {
  		asc->fn_on = !!value;
-		input_event(input, usage->type, usage->code, value);
+		input_event(input, usage->type, KEY_FN, value);
  		return 1;
  	}

@@ -270,6 +283,14 @@ static int hidinput_apple_event(struct h
  		}
  	}

+	if (swap_fn_leftctrl) {
+		trans = apple_find_translation(swapped_fn_leftctrl_keys, usage->code);
+		if (trans) {
+			input_event(input, usage->type, trans->to, value);
+			return 1;
+		}
+	}
+
  	return 0;
  }

@@ -333,6 +354,11 @@ static void apple_setup_input(struct inp

  	for (trans = apple_iso_keyboard; trans->from; trans++)
  		set_bit(trans->to, input->keybit);
+
+	if (swap_fn_leftctrl) {
+		for (trans = swapped_fn_leftctrl_keys; trans->from; trans++)
+			set_bit(trans->to, input->keybit);
+	}
  }

  static int apple_input_mapping(struct hid_device *hdev, struct hid_input *hi,

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

* Re: [PATCH 5.7-rc5] HID: apple: Swap the Fn and Left Control keys on Apple keyboards
  2020-05-15  6:14 [PATCH 5.7-rc5] HID: apple: Swap the Fn and Left Control keys on Apple keyboards free5lot
@ 2020-05-15 10:26 ` Jiri Kosina
  0 siblings, 0 replies; 2+ messages in thread
From: Jiri Kosina @ 2020-05-15 10:26 UTC (permalink / raw)
  To: free5lot; +Cc: Benjamin Tissoires, linux-input, linux-kernel

On Fri, 15 May 2020, free5lot wrote:

> This patch allows users to swap the Fn and left Control keys on all Apple
> keyboards: internal (e.g. Macbooks) and external (both wired and wireless).
> The patch adds a new hid-apple module param: swap_fn_leftctrl (off by
> default).
> 
> Signed-off-by: Zakhar Semenov <mail@free5lot.com>
> ---
> This patch was created to eliminate the inconvenience of having an unusual
> order of 4 left-bottom keys on Apple keyboards for GNU+Linux users.
> Now it's possible to swap the Fn and left Control keys on Macbooks and
> external Apple keyboards and have the same experience as on usual PC layout.
> 
> The patch has been heavily tested for about 5 years by community at:
> https://github.com/free5lot/hid-apple-patched
> The patch is small and straightforward. The modified version of hid-apple
> is currently mentioned in wiki-documentation of several major GNU/Linux
> distributions (e.g. Ubuntu, Arch, openSUSE).

Hi,

thanks for sending the patch.

The one in this mail was whitespace-corrupted by your mail client, but the 
one you attached to the other mail was fine, so I've used that.

> --- hid-apple.c.orig	2020-05-12 11:06:26.000000000 +0300
> +++ hid-apple.c	2020-05-15 20:00:00.000000000 +0300

For any next submissions, pelase send the patch in -p ab format and with 
full path in the kernel tree.

Thanks,

-- 
Jiri Kosina
SUSE Labs


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

end of thread, other threads:[~2020-05-15 10:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-15  6:14 [PATCH 5.7-rc5] HID: apple: Swap the Fn and Left Control keys on Apple keyboards free5lot
2020-05-15 10:26 ` Jiri Kosina

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.