From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: David Herrmann <dh.herrmann@googlemail.com>
Cc: linux-input@vger.kernel.org, Ran Benita <ran234@gmail.com>
Subject: Re: [PATCH] Input: new EVIOCGKEYF to get keystate and flush queues
Date: Sat, 16 Feb 2013 13:10:17 -0800 [thread overview]
Message-ID: <20130216211017.GB22044@core.coreip.homeip.net> (raw)
In-Reply-To: <1357559903-1881-1-git-send-email-dh.herrmann@googlemail.com>
Hi David,
On Mon, Jan 07, 2013 at 12:58:23PM +0100, David Herrmann wrote:
> EVIOCGKEYF returns the current keystate similar to EVIOCGKEY but also
> flushes the outgoing evdev event queue. This allows user-space devices to
> reliably retrieve the current state without having old events still in the
> read()-queue.
>
> Userspace libraries like XKB/xkbcommon use stacking key trackers, so they
> allow the kernel to map multiple keys to the same keycode. For instance if
> left-shift and right-shift map to the same keycode, xkbcommon allows the
> kernel to send key-down twice but also requires it to send key-up twice. A
> single input device doesn't support that, but this is very useful if you want
> multiple connected keyboards to have one shared modifier state: Pressing Shift
> on the one keyboard affects keys on the other keyboard. This is not the usual
> setup but it is supported and known to be used (for instance if you have
> external num-pads etc.).
>
> When a program opens input devices, it can read the keystate via EVIOCGKEY
> to update its internal keyboard state. This allows to keep CTRL pressed
> while switching VTs and having both applications remember that CTRL is
> still pressed.
> However, if there are still outgoing events in the evdev queue, the
> application will update its internal keyboard state and then read the
> event again, even though it already processed it via EVIOCGKEY.
>
> EVIOCGKEYF solves this race condition by flushing the evdev queue while
> returning the keystate. We cannot change EVIOCGKEY because we don't know
> whether userspace depends on a clean read() history and flushing the queue
> effectively drops events.
>
> This race could be fixed in user-space by keeping an exact copy of the keystate
> array for each input device that we opened and ignoring double-events for a
> single keycode. However, if we, as mentioned, want a shared keyboard-state, it
> seems to be a waste of computing power and memory to keep another copy for each
> input device if we could just use something like EVIOCGKEYF.
I do not think we should introduce the new ioctl as I really doubt
anyone is using it and even if they do I really doubt they will have
problems if we flush the events.
But rather that flushing all events we should only flush the key events.
The relative, absolute, and other events should be kept in the queue.
Thanks.
--
Dmitry
next prev parent reply other threads:[~2013-02-16 21:10 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-07 11:58 [PATCH] Input: new EVIOCGKEYF to get keystate and flush queues David Herrmann
2013-02-16 21:10 ` Dmitry Torokhov [this message]
2013-03-27 21:02 ` David Herrmann
2013-03-27 21:15 ` Dmitry Torokhov
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=20130216211017.GB22044@core.coreip.homeip.net \
--to=dmitry.torokhov@gmail.com \
--cc=dh.herrmann@googlemail.com \
--cc=linux-input@vger.kernel.org \
--cc=ran234@gmail.com \
/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).