Skip to contentSkip to conversation

Support to change VNC keyboard layout dynamically

RFC PATCH Superseded [email protected] 2 participants 6 messages Nov 29, 2014 – Dec 2, 2014

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Support to change VNC keyboard layout dynamically

From: Gonglei <[email protected]>

A bonus of this feature is that supporting different people (in different countries) using defferent keyboard to connect the same guest but not need to configure command line or libivrt xml file then restart guest.

Using the existing qmp command:

    -> { "execute": "change",
                 "arguments": { "device": "vnc", "target": "keymap",
                                "arg": "de" } }
    <- { "return": {} }

I knew sdl and curses are using keyboard layout, but I don't know whether they both need to support this feature and add some new qmp command for them?

If you have some ideas, please let me know. Thanks!

NOTE:
The patch series based on Gerd's vnc-next tree:
https://www.kraxel.org/cgit/qemu/log/?h=rebase/ui-vnc-next

Cc Gerd Hoffmann <[email protected]>

Gonglei (2):
vnc: introduce vnc_display_kbd_layout function
vnc: add change keyboard layout interface

 include/ui/console.h |  5 +++++
 qapi-schema.json     |  8 +++++---
 qmp.c                | 17 +++++++++++++++++
 ui/vnc.c             | 21 +++++++++++++++++++++
 4 files changed, 48 insertions(+), 3 deletions(-)
Signature · 1 line
1.7.12.4
#1 lore raw

RFC PATCH 1/2 vnc: introduce vnc_display_kbd_layout function

From: Gonglei <[email protected]>

In order to support changing vnc keyboard layout dynamically.

---
 include/ui/console.h |  5 +++++
 ui/vnc.c             | 21 +++++++++++++++++++++
 2 files changed, 26 insertions(+)
include/ui/console.h +5 -0
index 887ed91..4645dc3 100644
@@ -333,6 +333,7 @@ void vnc_display_add_client(const char *id, int csock, bool skipauth);
 char *vnc_display_local_addr(const char *id);
 #ifdef CONFIG_VNC
 int vnc_display_password(const char *id, const char *password);
+int vnc_display_kbd_layout(const char *id, const char *kbd_layout);
 int vnc_display_pw_expire(const char *id, time_t expires);
 QemuOpts *vnc_parse_func(const char *str);
 int vnc_init_func(QemuOpts *opts, void *opaque);
@@ -341,6 +342,10 @@ static inline int vnc_display_password(const char *id, const char *password)
 {
     return -ENODEV;
 }
+int vnc_display_kbd_layout(const char *id, const char *kbd_layout)
+{
+    return -ENODEV;
+}
 static inline int vnc_display_pw_expire(const char *id, time_t expires)
 {
     return -ENODEV;
ui/vnc.c +21 -0
index 8d189e7..5a2c60d 100644
@@ -3090,6 +3090,27 @@ int vnc_display_password(const char *id, const char *password)
     return 0;
 }
 
+int vnc_display_kbd_layout(const char *id, const char *kbd_layout)
+{
+    VncDisplay *vs = vnc_display_find(id);
+    kbd_layout_t *k = NULL;
+
+    if (!vs) {
+        return -EINVAL;
+    }
+
+    k = init_keyboard_layout(name2keysym, kbd_layout);
+    if (!k) {
+        return -EINVAL;
+    }
+
+    trace_vnc_key_map_init(kbd_layout);
+    g_free(vs->kbd_layout);
+    vs->kbd_layout = k;
+
+    return 0;
+}
+
 int vnc_display_pw_expire(const char *id, time_t expires)
 {
     VncDisplay *vs = vnc_display_find(id);
Signature · 1 line
1.7.12.4
#2 lore raw

RFC PATCH 2/2 vnc: add change keyboard layout interface

In reply to [email protected]

From: Gonglei <[email protected]>

Example QMP command of Change VNC keyboard layout:

-> { "execute": "change",

             "arguments": { "device": "vnc", "target": "keymap",
                            "arg": "de" } }

<- { "return": {} }

---
 qapi-schema.json |  8 +++++---
 qmp.c            | 17 +++++++++++++++++
 2 files changed, 22 insertions(+), 3 deletions(-)
qapi-schema.json +5 -3
index 9ffdcf8..8c02a9f 100644
@@ -1552,13 +1552,15 @@
 #
 # @target: If @device is a block device, then this is the new filename.
 #          If @device is 'vnc', then if the value 'password' selects the vnc
-#          change password command.   Otherwise, this specifies a new server URI
+#          change password command, if the value 'keymap'selects the vnc change
+#          keyboard layout command. Otherwise, this specifies a new server URI
 #          address to listen to for VNC connections.
 #
 # @arg:    If @device is a block device, then this is an optional format to open
 #          the device with.
-#          If @device is 'vnc' and @target is 'password', this is the new VNC
-#          password to set.  If this argument is an empty string, then no future
+#          If @device is 'vnc' and if @target is 'password', this is the new VNC
+#          password to set; if @target is 'keymap', this is the new VNC keyboard
+#          layout to set. If this argument is an empty string, then no future
 #          logins will be allowed.
 #
 # Returns: Nothing on success.
qmp.c +17 -0
index 3fda973..044cd34 100644
@@ -366,6 +366,13 @@ void qmp_change_vnc_password(const char *password, Error **errp)
     }
 }
 
+static void qmp_change_vnc_kbd_layout(const char *kbd_layout, Error **errp)
+{
+    if (vnc_display_kbd_layout(NULL, kbd_layout) < 0) {
+        error_setg(errp, "keyboard layout '%s' set failed", kbd_layout);
+    }
+}
+
 static void qmp_change_vnc_listen(const char *target, Error **errp)
 {
     QemuOptsList *olist = qemu_find_opts("vnc");
@@ -393,6 +400,12 @@ static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,
         } else {
             qmp_change_vnc_password(arg, errp);
         }
+    } else if (strcmp(target, "keymap") == 0) {
+        if (!has_arg) {
+            error_set(errp, QERR_MISSING_PARAMETER, "keymap");
+        } else {
+            qmp_change_vnc_kbd_layout(arg, errp);
+        }
     } else {
         qmp_change_vnc_listen(target, errp);
     }
@@ -402,6 +415,10 @@ void qmp_change_vnc_password(const char *password, Error **errp)
 {
     error_set(errp, QERR_FEATURE_DISABLED, "vnc");
 }
+static void qmp_change_vnc_kbd_layout(const char *kbd_layout, Error **errp)
+{
+    error_set(errp, QERR_FEATURE_DISABLED, "vnc");
+}
 static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,
                            Error **errp)
 {
Signature · 1 line
1.7.12.4
#3 lore raw

Re: [Qemu-devel] [RFC PATCH 2/2] vnc: add change keyboard layout interface

Quoted 8 lines · On 11/29/2014 03:39 AM, [email protected] wrote:

From: Gonglei <[email protected]>

Example QMP command of Change VNC keyboard layout:

-> { "execute": "change",

             "arguments": { "device": "vnc", "target": "keymap",
                            "arg": "de" } }

<- { "return": {} }

As I said in the cover letter, we should NOT be adding stuff to the broken 'change' command, but should instead add a new command.

Quoted 12 lines
---
 qapi-schema.json |  8 +++++---
 qmp.c            | 17 +++++++++++++++++
 2 files changed, 22 insertions(+), 3 deletions(-)
qapi-schema.json +0 -0
index 9ffdcf8..8c02a9f 100644

qapi-schema.json line 1555

Quoted 5 lines
qapi-schema.json +1 -1
@@ -1552,13 +1552,15 @@
 #
 # @target: If @device is a block device, then this is the new filename.
 #          If @device is 'vnc', then if the value 'password' selects the vnc
-#          change password command.   Otherwise, this specifies a new server URI
+#          change password command, if the value 'keymap'selects the vnc change

s/'keymap'selects/'keymap' selects/

qapi-schema.json line 1564

Quoted 11 lines
qapi-schema.json +4 -2
+#          keyboard layout command. Otherwise, this specifies a new server URI
 #          address to listen to for VNC connections.
 #
 # @arg:    If @device is a block device, then this is an optional format to open
 #          the device with.
-#          If @device is 'vnc' and @target is 'password', this is the new VNC
-#          password to set.  If this argument is an empty string, then no future
+#          If @device is 'vnc' and if @target is 'password', this is the new VNC
+#          password to set; if @target is 'keymap', this is the new VNC keyboard
+#          layout to set. If this argument is an empty string, then no future
 #          logins will be allowed.

Not discoverable. As proposed, libvirt has no way of knowing if qemu is new enough to support this horrible hack. A new command has multiple
benefits: it would be discoverable ('query-commands') and type-safe (none of this horrid overloading of special text values).

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
author
#4 lore raw

Re: [Qemu-devel] [RFC PATCH 2/2] vnc: add change keyboard layout interface

Quoted 5 lines · Eric Blake
Quoted 4 lines · On 11/29/2014 03:39 AM, [email protected] wrote:

From: Gonglei <[email protected]>

Example QMP command of Change VNC keyboard layout:

Quoted 8 lines
Quoted 4 lines

-> { "execute": "change",

             "arguments": { "device": "vnc", "target": "keymap",
                            "arg": "de" } }

<- { "return": {} }

As I said in the cover letter, we should NOT be adding stuff to the broken 'change' command, but should instead add a new command.

OK.

Quoted 20 lines
Quoted 12 lines
---
 qapi-schema.json |  8 +++++---
 qmp.c            | 17 +++++++++++++++++
 2 files changed, 22 insertions(+), 3 deletions(-)
qapi-schema.json +0 -0
index 9ffdcf8..8c02a9f 100644

qapi-schema.json line 1555

Quoted 5 lines
qapi-schema.json +1 -1
@@ -1552,13 +1552,15 @@
 #
 # @target: If @device is a block device, then this is the new filename.
 #          If @device is 'vnc', then if the value 'password' selects the vnc
-#          change password command.   Otherwise, this specifies a new server URI
+#          change password command, if the value 'keymap'selects the vnc change

s/'keymap'selects/'keymap' selects/

Quoted 17 lines

qapi-schema.json line 1564

Quoted 11 lines
qapi-schema.json +4 -2
+#          keyboard layout command. Otherwise, this specifies a new server URI
 #          address to listen to for VNC connections.
 #
 # @arg:    If @device is a block device, then this is an optional format to open
 #          the device with.
-#          If @device is 'vnc' and @target is 'password', this is the new VNC
-#          password to set.  If this argument is an empty string, then no future
+#          If @device is 'vnc' and if @target is 'password', this is the new VNC
+#          password to set; if @target is 'keymap', this is the new VNC keyboard
+#          layout to set. If this argument is an empty string, then no future
 #          logins will be allowed.

Not discoverable. As proposed, libvirt has no way of knowing if qemu is new enough to support this horrible hack. A new command has multiple
benefits: it would be discoverable ('query-commands') and type-safe (none of this horrid overloading of special text values).

Great! Thank you so much for your comments, Eric.
I will add a new QMP command for this.

Regards,
-Gonglei

#5 lore raw
In reply to [email protected]
Quoted 4 lines · On 11/29/2014 03:39 AM, [email protected] wrote:

From: Gonglei <[email protected]>

A bonus of this feature is that supporting different people (in different countries) using defferent keyboard

s/defferent/different/

Quoted 9 lines

to connect the same guest but not need to configure command line or libivrt xml file then restart guest.

Using the existing qmp command:

    -> { "execute": "change",
                 "arguments": { "device": "vnc", "target": "keymap",
                                "arg": "de" } }
    <- { "return": {} }

Please add a new QMP command. The existing 'change' command is not type-safe and therefore difficult to introspect; we should not be adding more band-aids to it.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org