On 26 February 2016 at 03:18, Programmingkid <programmingk...@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 via email to