qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: Programmingkid <programmingkidx@gmail.com>
Cc: qemu-devel qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] Implementing QKeyCode in cocoa.m
Date: Mon, 29 Feb 2016 17:17:18 +0000	[thread overview]
Message-ID: <CAFEAcA_1d7YF0Ypx-+-ZiVkDMfpcBCrrZ6hc-cOLr46ZNSS67w@mail.gmail.com> (raw)
In-Reply-To: <675C1D3C-07F8-48B5-95F2-6F4217882594@gmail.com>

On 26 February 2016 at 03:18, Programmingkid <programmingkidx@gmail.com> wrote:
> A long time ago we talked about removing the pc/xt keyboard layout in
> the ui/cocoa.m file and replacing it with QKeyCode. I wanted to do this
> originally because the pc/xt layout does not support several keys found
> on a Macintosh keyboard (like keypad =).
>
> https://lists.gnu.org/archive/html/qemu-devel/2015-02/msg01322.html
> This link gives some info about this topic.
>
> What I currently plan on doing is implementing an enum that defines
> all the Mac keys like this:
>
> // Macintosh keyboard keycodes
> enum {
>     MAC_KEY_A = 0,
>     MAC_KEY_B = 11,
>     MAC_KEY_C = 8,

> Then implementing a translation array that translates mac keycodes to QKeyCode like this:
>
> // Mac to QKeyCode conversion
> int macToQKeyCodeMap[] = {
>     [MAC_KEY_A] = Q_KEY_CODE_A,
>     [MAC_KEY_B] = Q_KEY_CODE_B,
>     [MAC_KEY_C] = Q_KEY_CODE_C,
>     [MAC_KEY_D] = Q_KEY_CODE_D,
>     [MAC_KEY_E] = Q_KEY_CODE_E,
>     [MAC_KEY_F] = Q_KEY_CODE_F,
>     [MAC_KEY_G] = Q_KEY_CODE_G,
>     [MAC_KEY_H] = Q_KEY_CODE_H,
>     [MAC_KEY_I] = Q_KEY_CODE_I,
>     [MAC_KEY_J] = Q_KEY_CODE_J,
>     [MAC_KEY_LEFTSHIFT] = Q_KEY_CODE_SHIFT,
>     [MAC_KEY_RIGHTSHIFT] = Q_KEY_CODE_SHIFT_R,
>     [MAC_KEY_SPACEBAR] = Q_KEY_CODE_SPC,
>     ...
> };
>
> This macToQKeyCodeMap code will be in the cocoa.m file.

http://stackoverflow.com/questions/3202629/where-can-i-find-a-list-of-mac-virtual-key-codes?rq=1
suggests that we can do
   #include <HIToolbox/Events.h>

and then we get a set of symbols like kVK_ANSI_A, kVK_ANSI_B,
kVK_RightShift, kVK_Space, etc. This is what you want to use
for the macToQKeyCodeMap conversion. (This keeps the UI code
separate from the back end code and avoids it having to
include a header from hw/.)

> The enum will probably be in include/hw/input/adb.h. Then I will
> probably implement another translation array in the file
> hw/input/adb.c called QKeyCode_to_ADB_keycode that will look
> something like this:
>
> int QKeyCode_to_ADB_keycode[] = {
>         [Q_KEY_CODE_A] = MAC_KEY_A,
>         [Q_KEY_CODE_B] = MAC_KEY_B,
>         ...
> };

For the QKey-to-ADB-keycode you will want your own enum
and another translation array in adb.c/adb.h as you suggest,
though (because the adb code needs to compile on non-osx hosts).

> These changes shouldn't effect the gtk and sdl libraries because
> I don't plan on deleting any code they depend on.
>
> Does this plan look acceptable?

Yes, this looks like the right approach to me. You'll want to
do this as two patches, one which only touches ui/cocoa.m
and one which only touches the adb device code in hw/.

thanks
-- PMM

      reply	other threads:[~2016-02-29 17:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-26  3:18 [Qemu-devel] Implementing QKeyCode in cocoa.m Programmingkid
2016-02-29 17:17 ` Peter Maydell [this message]

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=CAFEAcA_1d7YF0Ypx-+-ZiVkDMfpcBCrrZ6hc-cOLr46ZNSS67w@mail.gmail.com \
    --to=peter.maydell@linaro.org \
    --cc=programmingkidx@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /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).