qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [RFC PATCH v2 1/7] kbd-state: add keyboard state tracke


From: Eric Blake
Subject: Re: [Qemu-devel] [RFC PATCH v2 1/7] kbd-state: add keyboard state tracker
Date: Tue, 22 Jan 2019 10:52:46 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0

On 12/19/18 6:08 AM, Gerd Hoffmann wrote:
> Now that most user interfaces are using QKeyCodes it is easier to have
> common keyboard code useable by all user interfaces.
> 
> This patch adds helper code to track the state of all keyboard keys,
> using a bitmap indexed by QKeyCode.  Modifier state is tracked too,
> as separate bitmap.  That makes checking modifier state easier.
> Likewise we can easily apply special handling for capslock & numlock
> (toggles on keypress) and ctrl + shift (we have two keys for that).
> 
> Signed-off-by: Gerd Hoffmann <address@hidden>
> ---
>  include/ui/kbd-state.h |  32 +++++++++++++
>  ui/kbd-state.c         | 125 
> +++++++++++++++++++++++++++++++++++++++++++++++++
>  ui/Makefile.objs       |   2 +-
>  3 files changed, 158 insertions(+), 1 deletion(-)
>  create mode 100644 include/ui/kbd-state.h
>  create mode 100644 ui/kbd-state.c
> 

> +
> +void kbd_state_key_event(KbdState *kbd, QKeyCode qcode, bool down)
> +{
> +    bool state = test_bit(qcode, kbd->keys);
> +
> +    if (state == down) {
> +        /*
> +         * Filter out events which don't change the keyboard state.
> +         *
> +         * Most notably this allows to simply send along all key-up
> +         * events, and this function will filter out everything where
> +         * the corresponding key-down event wasn't send to the guest,

s/send/sent/

> +         * for example due to being a host hotkey.
> +         */
> +        return;

> +void kbd_state_lift_all_keys(KbdState *kbd)
> +{
> +    int qcode;
> +
> +    for (qcode = 0; qcode < Q_KEY_CODE__MAX; qcode++) {
> +        if (test_bit(qcode, kbd->keys)) {
> +            kbd_state_key_event(kbd, qcode, false);

Is there a more efficient iteration through the bitmap when looking for
the next set bit, or is the map small enough that it doesn't matter?

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]