qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] Implementing QKeyCode in cocoa.m
@ 2016-02-26  3:18 Programmingkid
  2016-02-29 17:17 ` Peter Maydell
  0 siblings, 1 reply; 2+ messages in thread
From: Programmingkid @ 2016-02-26  3:18 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel qemu-devel

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,
    MAC_KEY_D = 2,
    MAC_KEY_E = 14,
    MAC_KEY_F = 3,
    MAC_KEY_G = 5,
    MAC_KEY_H = 4,
    MAC_KEY_I = 34,
    MAC_KEY_J = 38,
    MAC_KEY_LEFTSHIFT = 56,
    MAC_KEY_RIGHTSHIFT = 60,
    MAC_KEY_SPACEBAR = 49,
    ...
};

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. 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,
	...
};

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? 

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] Implementing QKeyCode in cocoa.m
  2016-02-26  3:18 [Qemu-devel] Implementing QKeyCode in cocoa.m Programmingkid
@ 2016-02-29 17:17 ` Peter Maydell
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Maydell @ 2016-02-29 17:17 UTC (permalink / raw)
  To: Programmingkid; +Cc: qemu-devel qemu-devel

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-02-29 17:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-26  3:18 [Qemu-devel] Implementing QKeyCode in cocoa.m Programmingkid
2016-02-29 17:17 ` Peter Maydell

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).