Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp1860700ybi; Mon, 1 Jul 2019 01:37:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqyKbh6PdY3G2OSJVveIx5N4LdQhonTq/m4m6y4dic7dqd2hV87Nai1+5f+v/i8Ic9484bih X-Received: by 2002:a17:90a:21ac:: with SMTP id q41mr30236958pjc.31.1561970239081; Mon, 01 Jul 2019 01:37:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561970239; cv=none; d=google.com; s=arc-20160816; b=eYIUbeEWFZDOHarfraECU7N1WtrbCbv0w52cCpDxCqDcv9aYv9Sfy+WzxIrUVINz2z wJtyDwyVAEe31rud7yZBqVTX0IwWbO2iFsu4xaQ7gVr0rGb6RBOn0NpxfLBpYFKj6AgR BMUs1+FkHBu/ipX8XqLnMyp4+g7swc1Vtt6/D2+Vi8nU9Y4VwW2eab/R6LGu6DPPgQ39 cDvs1NBdQE10mUHhRAXBPxlBRYPWN/xwOsDF0KJxm69brm5dVoMfsJw45sAZqbDhj9rh TuvLHhRAmYpT5PuN+/k2S88OYMQvY0VOVQEdJ1hbZ+R/oivgTvJLkX2TV00dabC7dz+E qqSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=YRdBBKfq68izMRNoECEIlZj7I9j6zVa5Ztq2nz20ab8=; b=C64HHrrT/dbrJPbcEsx7JiR0lbMW30AIFrfKogYyeTLpMH9ZW/BFoY9OPUG7haWRNp la5lIA7u6mYbCs0c54HtQbZEPt4jTlAHGqSTmmXsV757uxr/v21FMNFZNA0F4uDBziaP 3my0LwUnsr9YJbEVMFqaKJBUPDbwCx/t9XT84nQQGEx6xbvjWy3cbmk6SGrV91QyX1Uz YxJXF63LOVUJpGIFdvec4QCwobZBSRMWXUQMAP9e8W+TXajzqKetLInGP7XhDatDI+a5 CrLK+ADD5Ksmuunf3fFqziCf0RW8CMgLumRFuksdh3pua15Nw9G3igZ7fROxR6XghQ2g aNKA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t186si10747599pfb.19.2019.07.01.01.37.03; Mon, 01 Jul 2019 01:37:19 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727626AbfGAIc5 convert rfc822-to-8bit (ORCPT + 99 others); Mon, 1 Jul 2019 04:32:57 -0400 Received: from mail-qt1-f194.google.com ([209.85.160.194]:33019 "EHLO mail-qt1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727031AbfGAIc4 (ORCPT ); Mon, 1 Jul 2019 04:32:56 -0400 Received: by mail-qt1-f194.google.com with SMTP id h24so10722617qto.0 for ; Mon, 01 Jul 2019 01:32:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=R/dnpSNZfbK9SytPEk8BpB1UB4x7kkm8B/EmwIRcbdc=; b=i76MTsma/ggQMKF5+hHBgvg9MNBc5YQdTBr1uagoOfb0ZaZw3NNsIByGWpLkg0SG/B 7WVhbblzspDgruRILei76HYkPrxUJi/LMq0R/Q8W26bVhtxmaLbBxpKNk6OnpQZMlchC nUH/v927QWPrN9buowTSSXB8UcUHe4kIDIuk6E2SUPuYKZagsEmJVc6XmP762ItTtB9S 7jkgd4WYKYAD4vAzFvKyR24or8rm4xdVuKc525pU8dVO7fKjJK3aLu5xbt240PIADPH2 dHM6OW/pSwwqotS+8fDjnO3eX3GMpTgvLhZM5iEZ/sftpnurrBA9oJy9B32SsK/DKZM+ w3Vw== X-Gm-Message-State: APjAAAVC5T8vTIfGPhjW7go5O3eXD7PVrszVammI5CLRc53rXrU1TQFr updTRiQ2PJrFOgKAl3O3v+pqjaGx1akY4SJxNKXFnQ== X-Received: by 2002:ac8:275a:: with SMTP id h26mr19095323qth.345.1561969975710; Mon, 01 Jul 2019 01:32:55 -0700 (PDT) MIME-Version: 1.0 References: <20190610213106.19342-1-mail@joaomoreno.com> In-Reply-To: From: Benjamin Tissoires Date: Mon, 1 Jul 2019 10:32:44 +0200 Message-ID: Subject: Re: [PATCH] HID: apple: Fix stuck function keys when using FN To: =?UTF-8?B?Sm/Do28gTW9yZW5v?= Cc: Jiri Kosina , "open list:HID CORE LAYER" , lkml Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi João, On Sun, Jun 30, 2019 at 10:15 PM João Moreno wrote: > > Hi Jiri & Benjamin, > > Let me know if you need something else to get this patch moving forward. This > fixes an issue I hit daily, it would be great to get it fixed. Sorry for the delay, I am very busy with internal corporate stuff, and I tried setting up a new CI system at home, and instead of spending a couple of ours, I am down to 2 weeks of hard work, without possibility to switch to the new right now :( Anyway. > > Thanks. > > On Mon, 10 Jun 2019 at 23:31, Joao Moreno wrote: > > > > This fixes an issue in which key down events for function keys would be > > repeatedly emitted even after the user has raised the physical key. For > > example, the driver fails to emit the F5 key up event when going through > > the following steps: > > - fnmode=1: hold FN, hold F5, release FN, release F5 > > - fnmode=2: hold F5, hold FN, release F5, release FN Ouch :/ > > > > The repeated F5 key down events can be easily verified using xev. > > > > Signed-off-by: Joao Moreno > > --- > > drivers/hid/hid-apple.c | 21 +++++++++++---------- > > 1 file changed, 11 insertions(+), 10 deletions(-) > > > > diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c > > index 1cb41992aaa1..81867a6fa047 100644 > > --- a/drivers/hid/hid-apple.c > > +++ b/drivers/hid/hid-apple.c > > @@ -205,20 +205,21 @@ static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input, > > trans = apple_find_translation (table, usage->code); > > > > if (trans) { > > - if (test_bit(usage->code, asc->pressed_fn)) > > - do_translate = 1; > > - else if (trans->flags & APPLE_FLAG_FKEY) > > - do_translate = (fnmode == 2 && asc->fn_on) || > > - (fnmode == 1 && !asc->fn_on); > > + int fn_on = value ? asc->fn_on : > > + test_bit(usage->code, asc->pressed_fn); > > + > > + if (!value) > > + clear_bit(usage->code, asc->pressed_fn); > > + else if (asc->fn_on) > > + set_bit(usage->code, asc->pressed_fn); I have the feeling that this is not the correct fix here. I might be wrong, but the following sequence might also mess up the driver state, depending on how the reports are emitted: - hold FN, hold F4, hold F5, release F4, release FN, release F5 The reason is that the driver only considers you have one key pressed with the modifier, and as the code changed its state based on the last value. IMO a better fix would: - keep the existing `trans` mapping lookout - whenever a `trans` mapping gets found: * get both translated and non-translated currently reported values (`test_bit(keycode, input_dev->key)`) * if one of them is set to true, then consider the keycode to be the one of the key (no matter fn_on) -> deal with `value` with the corrected keycode * if the key was not pressed: -> chose the keycode based on `fn_on` and `fnmode` states and report the key press event This should remove the nasty pressed_fn state which depends on the other pressed keys. Cheers, Benjamin > > + > > + if (trans->flags & APPLE_FLAG_FKEY) > > + do_translate = (fnmode == 2 && fn_on) || > > + (fnmode == 1 && !fn_on); > > else > > do_translate = asc->fn_on; > > > > if (do_translate) { > > - if (value) > > - set_bit(usage->code, asc->pressed_fn); > > - else > > - clear_bit(usage->code, asc->pressed_fn); > > - > > input_event(input, usage->type, trans->to, > > value); > > > > -- > > 2.19.1 > >