From patchwork Fri May 1 14:56:00 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: free5lot X-Patchwork-Id: 6309791 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Original-To: patchwork-linux-input@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C00579F373 for ; Fri, 1 May 2015 15:07:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B074620435 for ; Fri, 1 May 2015 15:07:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 78ABF20426 for ; Fri, 1 May 2015 15:07:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753623AbbEAPHB (ORCPT ); Fri, 1 May 2015 11:07:01 -0400 Received: from forward6l.mail.yandex.net ([84.201.143.139]:45852 "EHLO forward6l.mail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753345AbbEAPHA (ORCPT ); Fri, 1 May 2015 11:07:00 -0400 X-Greylist: delayed 653 seconds by postgrey-1.27 at vger.kernel.org; Fri, 01 May 2015 11:06:59 EDT Received: from smtp2h.mail.yandex.net (smtp2h.mail.yandex.net [IPv6:2a02:6b8:0:f05::116]) by forward6l.mail.yandex.net (Yandex) with ESMTP id BADE214E131A; Fri, 1 May 2015 17:56:01 +0300 (MSK) Received: from smtp2h.mail.yandex.net (localhost [127.0.0.1]) by smtp2h.mail.yandex.net (Yandex) with ESMTP id EED1917090F3; Fri, 1 May 2015 17:56:00 +0300 (MSK) Received: from l37-192-42-195.novotelecom.ru (l37-192-42-195.novotelecom.ru [37.192.42.195]) by smtp2h.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id RYNEgXvXe0-u00iW3sY; Fri, 1 May 2015 17:56:00 +0300 (using TLSv1.2 with cipher AES128-SHA (128/128 bits)) (Client certificate not present) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=free5lot.com; s=mail; t=1430492160; bh=NxI2/sQwl1lBAv3WI7/4U3Vl+3nZHHatO2xnMcIYfsg=; h=Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject: Content-Type:Content-Transfer-Encoding; b=wj5uMnAdTbVVdopJYI4CxMYDql+N7aPtlXJBKk+lFtnmvueXC7Vd2iy4XNHHa9wBk zoMUBtmjrFPZCc4VC4qRguQSz8EEutKbvaij817c92WMLDKeq9ZL+O80/p7T6VK8gj r/dM8cwTeUK/k5Ft2flLluyVv0bYbKQfxJAQWjvY= Authentication-Results: smtp2h.mail.yandex.net; dkim=pass header.i=@free5lot.com Message-ID: <55439400.3010100@free5lot.com> Date: Fri, 01 May 2015 20:56:00 +0600 From: Zakhar Semenov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Jiri Kosina CC: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4.0.1] HID: apple: option to swap the 'FN' and 'Left Control' keys. Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch allows Apple users to swap the FN and left Control keys on Macbook Pro, external Apple keyboards and some other Apple devices. And it also allows to use EjectCD key as missing Delete key. New hid-apple module params are swap_fn_leftctrl and ejectcd_as_delete. Signed-off-by: Zakhar Semenov --- This patch was created because Apple keyboards on Macbook Pro and external keyboard models have an unusual placement of special keys and a lot of users want the FN key and left Control key to be swapped. Similar patch for hid-apple but for other keys was accepted in 2013: https://lkml.org/lkml/2013/12/6/246 This patch was tested on Macbook Pro of 2013/2014 and an external keyboard. The same code style was used as in the original hid-apple.c, Some additional information and discussion on github: https://github.com/free5lot/hid-apple-patched -- To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- linux/drivers/hid/hid-apple.c.orig 2015-05-01 00:00:00.000000000 +0300 +++ linux/drivers/hid/hid-apple.c 2015-05-01 00:00:00.000000000 +0300 @@ -36,6 +36,9 @@ #define APPLE_FLAG_FKEY 0x01 +/* The fn key on Apple keyboards */ +#define APPLE_KEY_FN 84 + static unsigned int fnmode = 1; module_param(fnmode, uint, 0644); MODULE_PARM_DESC(fnmode, "Mode of fn key on Apple keyboards (0 = disabled, " @@ -52,6 +55,17 @@ 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)"); + +static unsigned int ejectcd_as_delete; +module_param(ejectcd_as_delete, uint, 0644); +MODULE_PARM_DESC(ejectcd_as_delete, "Use Eject-CD key as Delete key. " + "([0] = disabled, 1 = enabled)"); + struct apple_sc { unsigned long quirks; unsigned int fn_on; @@ -164,6 +178,16 @@ static const struct apple_key_translatio { } }; +static const struct apple_key_translation swapped_fn_leftctrl_keys[] = { + { APPLE_KEY_FN, KEY_LEFTCTRL }, + { } +}; + +static const struct apple_key_translation ejectcd_as_delete_keys[] = { + { KEY_EJECTCD, KEY_DELETE }, + { } +}; + static const struct apple_key_translation *apple_find_translation( const struct apple_key_translation *table, u16 from) { @@ -183,9 +207,11 @@ static int hidinput_apple_event(struct h struct apple_sc *asc = hid_get_drvdata(hid); const struct apple_key_translation *trans, *table; - 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; } @@ -264,6 +290,22 @@ 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; + } + } + + if (ejectcd_as_delete) { + trans = apple_find_translation(ejectcd_as_delete_keys, usage->code); + if (trans) { + input_event(input, usage->type, trans->to, value); + return 1; + } + } + return 0; } @@ -327,6 +369,16 @@ 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); + } + + if (ejectcd_as_delete) { + for (trans = ejectcd_as_delete_keys; trans->from; trans++) + set_bit(trans->to, input->keybit); + } } static int apple_input_mapping(struct hid_device *hdev, struct hid_input *hi, @@ -335,8 +387,10 @@ static int apple_input_mapping(struct hi { if (usage->hid == (HID_UP_CUSTOM | 0x0003)) { /* The fn key on Apple USB keyboards */ + u16 fn_keycode = (swap_fn_leftctrl) ? (KEY_LEFTCTRL) : (KEY_FN); + set_bit(EV_REP, hi->input->evbit); - hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_FN); + hid_map_usage_clear(hi, usage, bit, max, EV_KEY, fn_keycode); apple_setup_input(hi->input); return 1; }