Bug 246121 - [bhyve][PATCH] Append Keyboard Layout specified option for using VNC.
Summary: [bhyve][PATCH] Append Keyboard Layout specified option for using VNC.
Status: In Progress
Alias: None
Product: Base System
Classification: Unclassified
Component: bhyve (show other bugs)
Version: Unspecified
Hardware: amd64 Any
: --- Affects Only Me
Assignee: freebsd-virtualization (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-05-02 12:09 UTC by Koine Yuusuke
Modified: 2021-04-21 10:43 UTC (History)
11 users (show)

See Also:


Attachments
[bhyve][PATCH] Append Keyboard Layout specified option for using VNC. (9.45 KB, text/plain)
2020-05-02 12:09 UTC, Koine Yuusuke
no flags Details
[bhyve][PATCH] Append Keyboard Layout specified option for using VNC. (21.34 KB, text/plain)
2020-05-21 13:40 UTC, Koine Yuusuke
no flags Details
[bhyve][PATCH] Support QEMU Extended Key Event Message and Append keyboard layout specified option. (25.63 KB, text/plain)
2020-05-29 10:47 UTC, Koine Yuusuke
no flags Details
[PATCH] supporting QEMU Extended Keyboard Event Message (5.26 KB, text/plain)
2020-06-03 13:24 UTC, Koine Yuusuke
no flags Details
[PATCH] Append bhyve -k option for specified keyboard layout with layout setting files every languages. (22.67 KB, text/plain)
2020-06-03 13:28 UTC, Koine Yuusuke
no flags Details
[PATCH] supporting QEMU Extended Keyboard Event Message (4.15 KB, text/plain)
2020-06-14 13:20 UTC, Koine Yuusuke
no flags Details
[PATCH] Append bhyve -k option for specified keyboard layout with layout setting files every languages. (22.67 KB, text/plain)
2020-06-14 13:23 UTC, Koine Yuusuke
no flags Details
[PATCH] Append bhyve -k option for specified keyboard layout with layout setting files every languages. (23.21 KB, text/plain)
2021-01-02 00:57 UTC, Koine Yuusuke
no flags Details
[PATCH] supporting QEMU Extended Keyboard Event Message (4.69 KB, text/plain)
2021-01-02 01:01 UTC, Koine Yuusuke
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Koine Yuusuke 2020-05-02 12:09:04 UTC
Created attachment 214027 [details]
[bhyve][PATCH] Append Keyboard Layout specified option for using VNC.

When a guest OS is loaded using UEFI and connected with VNC, if the keyboard on the VNC client side is other than the US keyboard, some keys input may not be p
erformed correctly.
For example, if you press the '@' key on a Japanese keyboard, the number '2' will be entered on the guest OS.
The cause is that the '@' key on the US keyboard is assigned to Shift + '2' keys.
In addition, there is a problem that keys that do not exist on the US keyboard cannot be entered.
  (example, Zenkaku-Hankaku key in the Japanese Keyboard)

In the current bhyve(13-Current & 12.1-RELEASE-p3), in the virtual PS2 keyboard driver, there is a conversion table that converts from the key entered from the
 VNC client side to the virtual keyboard ScanCode for the Guest OS.
However, since this conversion table is set for US keyboards, the above problem will occur if the client side is not a US keyboard.

Therefore, I created a patch that allows the conversion table to be set in the external configuration file for each keyboard layout, and that the configuration
 file (=keyboard layout) can be specified by the option '-k' of the bhyve command.

The following shows how to apply the patch and how to use it.
Please merge it into the source tree if possible.

I'm new to creating a patch for the FreeBSD source tree, and I'm not sure if it's correct to submit to Bugzilla.
If it's wrong to submit it to Bugzilla, it would be very helpful if you could tell me how to submit it.


A. How to apply the patch ----------------------------------
  1. cd /usr/src/usr.sbin
  2. patch -u < bhyve_kbdlayout_fbsd13c.patch
  3. sh bhyve_kbdlayout.shar
  4. cd /usr/src/usr.sbin/bhyve
  5. make
  6. make install

  * If you use the FreeBSD 12.1-RELEASE, please replace the "fbsd13c" of the above No.2 to the "fbsd121r".


B. How to specified the keyboard layout --------------------
  If you use the bhyve command directly, specify the '-k layout' option for the bhyve command.
  You can specify the "layout" in the file name stored in /usr/share/bhyve/kbdlayout dir.
  If no '-k' option is specified, the US keyboard (default) is assumed to be selected.

  Others, If you use the bhyve via the vm-bhyve package, specify the following lines for the Guest OS configure file.
     bhyve_options="-k layout"

  
C. Request for Coooperation (The remaining tasks) ----------
  Currently, the keyboard layout setting file can only be created for Japanese keyboards.
   (Because, I have only the Japanese Keyboard...)

  If you would like to adopt this patch, I would like to ask those who use keyboards of the corresponding languages to create keyboard layout setting files oth
er than English and Japanese keyboards.
  See the 'default' file in the /usr/share/bhyve/kbdlayout dir. for how to create it.
Comment 1 Aleksandr Fedorov freebsd_committer 2020-05-04 12:58:50 UTC
It looks interesting, but can we use existing layout files: /usr/share/vt/keymaps or /usr/share/syscons/keymaps?

See format description: man 5 kbdmap
Comment 2 Koine Yuusuke 2020-05-05 11:51:05 UTC
Thank you for you interest in the patch.

Unfortunately, I understand that the your suggestions are difficult for the following reasons.

The virtual PS2 keyboard driver of the bhyve has a table for converting ASCII code for keys that can be expressed in ASCII characters and Xorg keysym code for keys that cannot be expressed in ASCII characters (example Enter or Escape key,etc) to ScanCode Set2 of the PS2 keyboard.
This patch updates this conversion table based on the layout setting file.

The /usr/share/vt/keymaps/* file contain the correspondence of ASCII characters or key names (key names is unique to vt/syscons, not Xorg keysym) corresponding to the scancode (for vt/syscons) converted from ScanCode Set2 of the PS2 keyboard device.
In addition, I confirmed that the conversion algorithm from ScanCode Set2 of the PS2 keyboard to scancode (for vt/syscons) is implemented in /usr/src/sys/dev/atkbdc/atkbd.c, so I think that it is not impossible to use the /usr/share/vt/keymaps/* file as the basis for the keys that can be represented by ASCII characters.
(Since it has not been examined in detail, I don't understand whether ScanCode Set2 of the PS2 keyboard can actually be converted from scancode (for vt/syscons) to the reverse.)

On the other hand, a key that cannot be represented by ASCII characters cannot be supported because the value of Xorg keysym value doesn't exist in /usr/share/vt/keymaps/* file.
 (For reference, the value of Xorg keysym value is in the /usr/local/include/X11/keysymdef.h)

Therefore, even if the key layout conversion information that can be expressed in ASCII characters is acquired from /usr/share/vt/keymaps/* file, the key that cannot be expressed in ASCII characters cannot be acquired from /usr/share/vt/keymaps/* file, and thus I think that a layout configuration file for each language is required.

If you have a good idea to use /usr/share/vt/keymaps/* file, please let me know.
 (I also don't want to have a layout configuration file for bhyve apart from /usr/share/vt/keymaps/* file.
  But I did this because I couldn't think of any other simple way...)

 - Koine Yuusuke (koinec)
Comment 3 Peter Grehan freebsd_committer 2020-05-13 10:55:22 UTC
Another way to solve this is to implement the "QEMU Extended Key Event Message" in the server (https://github.com/rfbproto/rfbproto/blob/master/rfbproto.rst#qemu-extended-key-event-message)

This allows scancodes to be sent end-end so avoids information loss and locale mis-translation when converting VNC keycodes to PS2 scancodes.

The downside is that client support is patchy :( It's in recent versions of TigerVNC and originated fron NoVMC, but isn't in VNCViewer, tightVNC or UltraVNC :(

However, it avoids the problem of having to create per-language maps.
Comment 4 Lars Engels freebsd_committer 2020-05-13 13:20:11 UTC
There's at least a workaround to make non-english keyboards work:

In the bhyve client configure the keyboard to your locale, e.g. de, jp, ...

On the host running the VNC client change your keyboard setting to "us" e.g. "setxkbmap us".

Then connect using TigerVNC or probably other clients. Inside the VNC client all keys e.g. German umlauts should work normally.
Comment 5 Koine Yuusuke 2020-05-21 13:40:44 UTC
Created attachment 214725 [details]
[bhyve][PATCH] Append Keyboard Layout specified option for using VNC.

Thank you for the various ideas!

As a result of thinking, I think that the method that has the keyboard-layout setting file is better.
However, I tried to automatically generate the keyboard-layout setting file for each language from the file existing /usr/share/vt/kbdmap for vt, so update the generated keyboard-layout patch files for each language.
Now that I can enter the following keys on the keyboards of all languages supported by vt, what about?

A. How to apply the patch ----------------------------------
  1. cd /usr/src/usr.sbin
  2. patch -u < bhyve_kbdlayout_fbsd13c.patch
  3. sh bhyve_kbdlayout.shar           (*Updated the bhyve_kbdlayou.shar file in this time.)
  4. cd /usr/src/usr.sbin/bhyve
  5. make
  6. make install

  * If you use the FreeBSD 12.1-RELEASE, please replace the "fbsd13c" of the above No.2 to the "fbsd121r".

B. Supoorting Keyboard map ---------------------------------
  You can use the following keyboard language layout.
   (Indicates the string that can be specified in the bhyve -k option.)
      am / be / be_acc / bg_bds / bg_phonetic / br / br_noacc / by
      ca / ca-fr / centraleuropean / centraleuropean_qwerty
      ch / ch_acc / ch-fr / ch-fr_acc / ch_macbook_acc / colemak_acc
      cz / de / de_acc / de_noacc / dk / dk_acc / dk_macbook
      ee / es / es_acc / es_dvorak / fi
      fr / fr_acc / fr_dvorak / fr_dvorak_acc / fr_macbook
      gr / gr_101_acc / gr_elot_acc / hr / hu_101 / hu_102
      il / is / is_acc / it / kz_io / kz_kst / lt
      latinamerican / latinamerican_acc / nl / no / no_dvorak / nordic_asus-eee
      pl / pl_dvorak / pt / pt_acc / ru / ru_shift / ru_win / se / si / sk
      tr / tr_f / ua / ua_shift_alt / uk / uk_capsctrl / uk_dvorak / uk_macbook
      us / us_acc / us_ctrl / us_emacs / us_macbook / us_unix
      us_dvorak / us_dvorakl / us_dvorakp / us_dvorakr / us_dvorakx
      jp / jp_capsctrl

C. Supporting Key with the above Keyboard-Layout file. ----
  Alphabetical Key ( [a-zA-Z] )
  Numeric Key      ( [0-9] )
  Sign mark Key    ( !"#$%&'()+-*/=^~\|@`[]{};:,.<>?_ )
  Enter / Escape / Tab / Shift(L/R) / Ctrl.(L/R) / Alt(L/R) / Home / End / Ins. / BackSpace / Delete
  Up Arrow / Down Arrow / Left Arrow / Right Arrow / PgUp / PgDown
  F1-12 / WinKey(L/R)

    * jp / jp_capsctl supports Japanese keyboard specific keys.

D. Thoghts on the ideas you taught ------------------------
 1. The workaround by executing "setxkbmap us" on the VNC client side.
   This method allows the guest OS to enter the correct key input, but there is a problem that the key cannot be input correctly on the client side(HyberVisor) terminal.
   Therefore, it is not possible to use the FreeBSD terminal on which bhyve runs and the guest OS as the same time.
   I knew it was also introduced as a workaround on other sites, but I patched this thread because of the above issue.

 2. The use of QEMU Extended Key Event Message
   I understand that this method is a drastic measure to avoid using the keyboard-layout files, and I would like to make the patch with it if possible ...
   However, in the current VNC clients that exist the FreeBSD ports, tigerVNC doesn't support this message because it is an old version, and it seems that tightVNC & ssvnc doesn't support this message in the first place.
   If the VNC clients that exist the FreeBSd ports supprots this message, I would like to try to support this message, but I can not support it because there is no VNCclient currently. And as far as I can see the bhyve source tree, I think the difficulty level of the modification is high.

 3. This proposal
   When we aim to make it easy to use any language using the current VNCclient on FreeBSD ports, I think that it is unavoidable to use the keyboard-layout setting file.
   However, it is difficult to create the keyboard-layout files for each launguage from the beginning, so the minimum keys such as alphabets, numbers, and symbols were automatically generated.
   I would like to ask if this method is acceptable, test the generating keyboard-layout setting file for each language, and add a unique key definition for each language.
Comment 6 Peter Grehan freebsd_committer 2020-05-28 11:44:47 UTC
TigerVNC in ports is v1.10.1, which is the latest official release. The Qemu key event code has been in there for a couple of years now.

I'll have a look at how much work it is to support that extension, but I grant that a) it isn't supported by other VNC clients, and b) the performance of TigerVNC is worse than TightVNC. So, the keymap change is still likely worthwhile. I'll take a closer look at your patch.
Comment 7 Koine Yuusuke 2020-05-29 10:47:36 UTC
Created attachment 215004 [details]
[bhyve][PATCH] Support QEMU Extended Key Event Message and Append keyboard layout specified option.

Thank you for telling me and I'm sorry for my lack of research.

With you help, I found that the TigerVNC supports QEMU Extended Key Event Message, so I immediately tried to create a patch.
As a result, when using TigerVNC, it is possible to support keys unique of each language without depending the keyboard layout setting file or specifying bhyve -k option.
However, I would like to preserve the keyboard layout configuration file and the bhyve -k option feature to allow use by VNC clients that don't support QEMU Extended Key Event Messages (such as tightVNC).

By the last time, the keyboard layout setting file should have been able to input alphabets, numbers, symbols, and a part of functional key(e.g. Enter/Space) in every languages keyboard, so I think that support has advanced considerably, but what about?


A. How to apply the NEW patch --------------------------------------------
  Same as last time. (See above)

B. Usage -----------------------------------------------------------------
  * VNC clients with supported the QEMU Extended Key Event Mesage (TigerVNC)
      Just use it as before.
      The keyboard layout of each language is automatically supported.
      Even if the -k option is specified, it will be ignored.

  * VNC clients WITHOUT supported the message (tightVNC, ssvnc, etc)
      You need to specify the keyboard layout name by the -k option.
      The method of specify the -k option is same as last time.
      If not specified, the US keyboard layout is assumed to have been specified.

I apologize for fixing the path many times, but I appreciate your cooperation.
Comment 8 Peter Grehan freebsd_committer 2020-06-01 12:30:34 UTC
Thanks - great work :)

I'll split this out into 2 parts. The first will be support for the qemu extended key event message, since this requires no documentation, and can provide a solution today for those willing to use TigerVNC (and it will also provide some impetus to fix the perf issues with TigerVNC). I'll put up a review for this shortly.

The second will be adding support for the translation-table file.
Comment 9 Koine Yuusuke 2020-06-03 13:24:46 UTC
Created attachment 215195 [details]
[PATCH] supporting QEMU Extended Keyboard Event Message

Thank you for everything.

The patch has been divided into two parts, so please use it if you like.

The first patch is "bhyve_qemu_ext_key_event_msg.tgz" for supporting QEMU Extended Keyboard Event Message.
It can be applied by executing the following command on /usr/src/usr.sbin
   patch -u < bhyve_qemu_ext_key_event_msg_fbsd13c.patch

   * If you use the FreeBSD 12.1-RELEASE, please replace the "fbsd13c" of the above to the "fbsd121r".
Comment 10 Koine Yuusuke 2020-06-03 13:28:10 UTC
Created attachment 215196 [details]
[PATCH] Append bhyve -k option for specified keyboard layout with layout setting files every languages.

Then, the second patch is "bhyve_kbdlayout_option.tgz" for supporting bhyve -k option that specify the keyboard layout name.
This patch can be applied be executing the following command.
   cd /usr/src/usr.sbin
   patch -u < bhyve_kbdlayout_option_fbsd13c.patch
   sh bhyve_kbdlayout_layoutfile.shar
   cd /usr/src/share
   patch -u < bhyve_kbdlayout_vmrunsh_fbsd13c.patch

In addition, the second patch has the following changes from the previous patch.
   * The first patch (for supporting QEMU Extended Keyboard Event Message) must be applied before applying this patch.
   * Fix an issue where the latest bhyve source tree (only FreeBSD 13.0-current) could not be patched correctly. (SORRY!)
   * Modified so that -k option can be specified from /usr/share/examples/bhyve/vmrun.sh.
      (However, vmrun.sh is only modified.)

If there is something, please point out.
Comment 11 Peter Grehan freebsd_committer 2020-06-05 03:15:33 UTC
(In reply to Koine Yuusuke from comment #9)

Thanks for the patch. I'd already broken out that section from your previous one so the review might look slightly different.

One issue I had with the qemu ext keyevent is that TigerVNC generates scanset 1 codes (with freebsd/macos/windows clients), whereas the atkbd emulation is expecting scanset 2 codes in the FIFO. There's a simple 1:1 translation between scanset 1 and 2, so I'll add a table for that conversion.
Comment 12 Koine Yuusuke 2020-06-06 03:23:53 UTC
(In reply to Peter Grehan from comment #11)

Thank you for responding.

I think it is unnecessary to add a translation table from scanset2 to scanset 1.
In the patch suggested this time, the translation process from scanset 2 to scanset 1 is bypassed in the atkbd emulation only when the QEMU Extended Key Event Message is received.
(Therefore, an argument that specifies whether scanset conversion is performed is added to the fifo_get() function and fifo_put() function arguments.)

There are two reasons for doing this.
 1) It is written that a simple 1:1 translation is possible from scanset2 to scanset 1, but I understand the following exceptions.
     Scanset 2      Scanset 1
   -----------------------------
     0x02/0x83  ->  0x41
     0x7f/0x84  ->  0x54
   There is no problem when tranlating from scanset 2 to scanset 1 as int the atkbd emulation, but when performing reverse tranlation, it is the recognition that 0x41/0x54 of scanset 1 cannot determine which value of scanset 2 is set.
   (However, as far as I know, this is only the F7 key(0x83->0x41), so it may not be a problem ...)

 2) In bhyve's code, translating from scanset 1 to scanset 2 in ps2kbd.c, and then translating from scanset 2 to scanset 1 in atkbd.c again immediately, it is 
considered redundant even if the effect on performance is slight I will.

In the future, if we decide to make the atkbd emulation(atkbdc.c) and PS2 virtual keyboard driver(ps2kbd.c) completely independent, I'm aware that there is a problem because the method suggested this time will not be able to make them independent.
However, in the current implementation, the function of the PS2 virtual keyboard driver is directly called from the atkbd emulation, so I couldn't understand the future course.

If necessary, I can stop the bypass process and add the translation process from scanset 1 to scanset 2.
I apologize for the inconvenience, but please would like to know the correspondence policy.
Comment 13 Peter Grehan freebsd_committer 2020-06-08 11:36:26 UTC
I'm not concerned at the double translation. scanset 1 is only used for BIOS/DOS applications so performance not an issue there.

For the 2 cases you mentioned where there is an ambiguous translation from 1 to 2, I think it's fine to use the 83/84 scanset 2 values - I wasn't able to find any references to the 02/7f so assuming they are rare, and in addition, the translation is not generic for XT keyboards, but is only for VNC clients which are much more recent.
Comment 14 Koine Yuusuke 2020-06-14 13:20:30 UTC
Created attachment 215545 [details]
[PATCH] supporting QEMU Extended Keyboard Event Message

Thank you for letting me know the implement policy.

You may have corrected it, but I also tried recreating the patch for my study.
I would appreciate it if you could use it.

It's my first time proposing a patch to FreeBSD Base System, so I don't understand what to do in the future.
If there is something, please point out.
Comment 15 Koine Yuusuke 2020-06-14 13:23:59 UTC
Created attachment 215546 [details]
[PATCH] Append bhyve -k option for specified keyboard layout with layout setting files every languages.

The patch of the layout specification option by the setting file was also fixed.
Please consider adopting this patch as well.
Comment 16 Peter Grehan freebsd_committer 2020-06-16 11:23:41 UTC
(In reply to Koine Yuusuke from comment #14)
Thanks for the update ! I'll incorporate that and test it out.
Comment 17 Michael Reifenberger freebsd_committer 2020-11-04 15:48:45 UTC
Hi,
I'm currently testing the patches with FreeBSD 12.2 STABLE.

Using both patches:
cd /usr/src
patch < bhyve_qemu_ext_key_event_msg_fbsd121r.patch
patch < bhyve_kbdlayout_option_fbsd121r.patch
sh bhyve_kbdlayout_layoutfile.shar
ls -l bhyve/*.rej
-rw-r--r--  1 root  wheel   199  4 Nov. 16:15 bhyve/bhyve.8.rej
-rw-r--r--  1 root  wheel   273  4 Nov. 16:15 bhyve/bhyverun.c.rej
-rw-r--r--  1 root  wheel  1167  3 Nov. 21:52 bhyve/ps2kbd.c.rej

If only using bhyve_qemu_ext_key_event_msg_fbsd121r.patch:
This seems to work as I can switch to a german layout (Windows10 VM) and use umlauts.

If only using bhyve_kbdlayout_option_fbsd121r.patch:
The patch doesn't apply cleanly:
-rw-r--r--  1 root  wheel  199  4 Nov. 16:35 bhyve/bhyve.8.rej
-rw-r--r--  1 root  wheel  273  4 Nov. 16:35 bhyve/bhyverun.c.rej

make install doesn't call kbdlayout/Makefile BTW.

If applying bhyverun.c.rej by hand I can start bhyve with 'bhyve_options="-k de"' but doesn't seem to work like the first patch.
(I can select the german keyboard in Windows but no umlauts are printed)

So it seems that for me only bhyve_qemu_ext_key_event_msg_fbsd121r.patch is working as expected.

Thanks for your work in this area BTW!
Comment 18 Ali Abdallah 2020-11-05 14:14:07 UTC
Just for sharing, I'm using also the bhyve_qemu_ext_key_event_msg_fbsd121r.patch from the first time I found it on the ML on my FreeBSD 12.1 box (which is now running FreeBSD 12.2). It finally allows me to use correctly my Italian keyboard layout on my VMs. 

I have it also on my T495 running 13-current. It would be very nice to include it in the official repo.
Comment 19 Peter Grehan freebsd_committer 2020-11-05 22:06:41 UTC
There is some activity on VNC (and TigerVNC client perf) in PR 250795 so I think the qemu ext kbd change could drop in when that is done.
Comment 20 marko 2020-11-11 16:27:41 UTC
I did try out this patch with freebsd 13, and it does work as advertised (I tried with fi keymap & TigerVNC 1.11.0). I found no issues.

I applied the patch on top of the patch from PR 250795.
Comment 21 Koine Yuusuke 2020-11-16 04:14:23 UTC
Thank you everyone for reporting.

When I tried it on FreeBSD 12.2-RELEASE, it was as follows.
 - bhyve_qemu_ext_key_event_msg_fbsd121r.patch: OK
 - bhyve_kbdlayout_option_fbsd121r.patch: NG
       (.rej occurs in bhyverun.c & bhyve.8 (man))
(I have just applied the patch and have not tested it yet.)

In Comment 17, I received a report that FreeBSD 12.2 Stable will generate ps2kbd.c.rej, but when was the updated source?
(Is it a newer source than 12.2-RELEASE?)

The cause of the problem that the .rej file is generated by bhyve_kbdlayout_option_fbsd121r.patch in 12.2-RELEASE is known, so I would like to post a correction patch at a later date.
Comment 22 Koine Yuusuke 2021-01-02 00:57:30 UTC
Created attachment 221184 [details]
[PATCH] Append bhyve -k option for specified keyboard layout with layout setting files every languages.

A happy new year!

I have created a patch for FreeBSD 12.2-RELEASE.
I also checked the operation on FreeBSD 13.0-current(20201224) and updated the patch.
I will upload the latest patch, so please give it a try.
Comment 23 Koine Yuusuke 2021-01-02 01:01:59 UTC
Created attachment 221185 [details]
[PATCH] supporting QEMU Extended Keyboard Event Message

In addtion, I fixed an issue where qemu-extended-key-event patch could not be applied correctly on FreeBSD 13.0-current(20201224) and 12.2-RELEASE.
Pleases try this patch as well.
Comment 24 Michael Reifenberger freebsd_committer 2021-02-21 18:16:26 UTC
Hi,
do you have by chance updated patches for stable/12 and main?

For me bhyve_kbdlayout_option_fbsd122r.patch doesn't seem to work as intended.

Running a Windows 10 VM with '-k de' and setting the Windows KBD-Lang to 'deu'
seems to work for the intended Layout for Keys like '\|-_' but I don't get Umlauts or €...

Also the bhyve_qemu_ext_key_event_msg patch doesn't apply cleanly on top of the
hyve_kbdlayout_option patch:

Patching file bhyve/ps2kbd.c using Plan A...
Hunk #1 succeeded at 185 (offset 7 lines).
Hunk #2 failed at 339.
Hunk #3 succeeded at 382 (offset 7 lines).
Hunk #4 succeeded at 393 (offset 7 lines).
1 out of 4 hunks failed--saving rejects to bhyve/ps2kbd.c.rej
Comment 25 Koine Yuusuke 2021-02-22 12:58:18 UTC
(In reply to Michael Reifenberger from comment #24)

Thank you for reporting the results.

> Hi,do you have by chance updated patches for stable/12 and main?
>
> For me bhyve_kbdlayout_option_fbsd122r.patch doesn't seem to work as intended.
>
> Running a Windows 10 VM with '-k de' and setting the Windows KBD-Lang to 'deu'
> seems to work for the intended Layout for Keys like '\|-_' but I don't get
> Umlauts or ???...

Currently, bhyve_kbdlayout_option_fbsd***.patch doesn't support language-specific keys other than alphabets, numbers, ASCII code symbols(e.g. !/#/$/etc), and control keys (Enter, Escape, Space, etc.) that are also found on US keyboards.
Because I only have a Japanese keyboard, I don't know what keys are on keyboards in other languages, how to type them, and what keycodes are output as a result.
For this reason, you should not be able to enter umlauts, etc.

If possible, I would be grateful if you could add the settings specific to the German keyboard to the "/usr/share/bhyve/kbdlayout/de" file.

This file has the following syntax.
----
'<ascii char>', hex (1byte); comment
hex (1or2byte), hex (1byte); comment
----
The first data is the state of the console that does not start Xorg, and if the character is displayed by pressing the key, enter the character separated by quotes.
If the control key does not display characters, enter the value of keysym displayed when the corresponding key is entered with the xev command in hexadecimal.
However, since umlauts are one letter in German, not control keys, I'm sorry I don't know if they can be represented by Xorg's keysym.

For the second data, enter the scancode (type2) value of the keyboard of each language corresponding to that key.
The value of scancode differs depending on the keyboard of each language, so please check it with google etc.
Then write a semicolon to mark the end of the line.
The line after the semicolon is considered a comment.

I'm sorry I think it's difficult, but if you understand it, please set it.


> Also the bhyve_qemu_ext_key_event_msg patch doesn't apply cleanly on top of the
> hyve_kbdlayout_option patch:
>
> Patching file bhyve/ps2kbd.c using Plan A...
> Hunk #1 succeeded at 185 (offset 7 lines).
> Hunk #2 failed at 339.
> Hunk #3 succeeded at 382 (offset 7 lines).
> Hunk #4 succeeded at 393 (offset 7 lines).
> 1 out of 4 hunks failed--saving rejects to bhyve/ps2kbd.c.rej

bhyve_kbdlayout_option_fbsd***.patch does not assume apply prior to bhyve_qemu_ext_key_event_msg_fbsd***.patch.
For this reason, I'm sorry, but I would like you to apply bhyve_qemu_ext_key_event_msg_fbsd***.patch first and then bhyve_kbdlayout_option_fbsd***.patch to the original bhyve source code.


Finally, I launched the git site for this patch, and in addition to the patch, I also released a tool to generate a layout file from a kbd file for FreeBSD's vt, so please refer to it.
https://osdn.net/users/koinec/pf/bhyve_keyboard_layout_patch/wiki/FrontPage

Best regards.
Comment 26 Michael Reifenberger freebsd_committer 2021-03-04 09:35:47 UTC
Hi,
yes.
After applying bhyve_qemu_ext_key_event_msg_fbsd***.patch first and then bhyve_kbdlayout_option_fbsd***.patch to the original bhyve source code
it applies mostly clean and works as intended.

In Windows even Umlauts show up.

Thanks for your work!

Now lets try to get it committed.
Comment 27 commit-hook freebsd_committer 2021-04-21 10:43:13 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=b563ff5d4f812df198ade6991834782a5d35af08

commit b563ff5d4f812df198ade6991834782a5d35af08
Author:     Michael Reifenberger <mr@FreeBSD.org>
AuthorDate: 2021-04-21 10:38:26 +0000
Commit:     Michael Reifenberger <mr@FreeBSD.org>
CommitDate: 2021-04-21 10:40:44 +0000

    Append Keyboard Layout specified option for using VNC.
    Part one: supporting QEMU Extended Keyboard Event Message

    PR:             246121
    Submitted by:   koinec@yahoo.co.jp
    Differential Revision: https://reviews.freebsd.org/D29430

 usr.sbin/bhyve/console.c |  4 +--
 usr.sbin/bhyve/console.h |  4 +--
 usr.sbin/bhyve/ps2kbd.c  | 54 ++++++++++++++++++++++++++----------
 usr.sbin/bhyve/rfb.c     | 72 +++++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 115 insertions(+), 19 deletions(-)