diff mbox

[v3] vnc: add configurable keyboard delay

Message ID 1464762150-25817-1-git-send-email-kraxel@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Gerd Hoffmann June 1, 2016, 6:22 a.m. UTC
Limits the rate kbd events from the vnc server are forwarded to the
guest, so input devices which are typically low-bandwidth can keep
up even on bulky input.

v2: update documentation too.
v3: spell fixes.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 qemu-options.hx |  8 ++++++++
 ui/vnc.c        | 13 +++++++++++--
 ui/vnc.h        |  1 +
 3 files changed, 20 insertions(+), 2 deletions(-)

Comments

Yang Hongyang June 2, 2016, 10:36 a.m. UTC | #1
On Wed, Jun 1, 2016 at 2:22 PM, Gerd Hoffmann <kraxel@redhat.com> wrote:

> Limits the rate kbd events from the vnc server are forwarded to the
> guest, so input devices which are typically low-bandwidth can keep
> up even on bulky input.
>
> v2: update documentation too.
> v3: spell fixes.
>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
>

Tested-by: Yang Hongyang <hongyang.yang@easystack.cn>


> ---
>  qemu-options.hx |  8 ++++++++
>  ui/vnc.c        | 13 +++++++++++--
>  ui/vnc.h        |  1 +
>  3 files changed, 20 insertions(+), 2 deletions(-)
>
> diff --git a/qemu-options.hx b/qemu-options.hx
> index 6106520..9f33361 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -1410,6 +1410,14 @@ everybody else.  'ignore' completely ignores the
> shared flag and
>  allows everybody connect unconditionally.  Doesn't conform to the rfb
>  spec but is traditional QEMU behavior.
>
> +@item key-delay-ms
> +
> +Set keyboard delay, for key down and key up events, in milliseconds.
> +Default is 1.  Keyboards are low-bandwidth devices, so this slowdown
> +can help the device and guest to keep up and not lose events in case
> +events are arriving in bulk.  Possible causes for the latter are flaky
> +network connections, or scripts for automated testing.
> +
>  @end table
>  ETEXI
>
> diff --git a/ui/vnc.c b/ui/vnc.c
> index d2ebf1f..ea3b3d4 100644
> --- a/ui/vnc.c
> +++ b/ui/vnc.c
> @@ -1629,6 +1629,7 @@ static void reset_keys(VncState *vs)
>      for(i = 0; i < 256; i++) {
>          if (vs->modifiers_state[i]) {
>              qemu_input_event_send_key_number(vs->vd->dcl.con, i, false);
> +            qemu_input_event_send_key_delay(vs->vd->key_delay_ms);
>              vs->modifiers_state[i] = 0;
>          }
>      }
> @@ -1638,9 +1639,9 @@ static void press_key(VncState *vs, int keysym)
>  {
>      int keycode = keysym2scancode(vs->vd->kbd_layout, keysym) &
> SCANCODE_KEYMASK;
>      qemu_input_event_send_key_number(vs->vd->dcl.con, keycode, true);
> -    qemu_input_event_send_key_delay(0);
> +    qemu_input_event_send_key_delay(vs->vd->key_delay_ms);
>      qemu_input_event_send_key_number(vs->vd->dcl.con, keycode, false);
> -    qemu_input_event_send_key_delay(0);
> +    qemu_input_event_send_key_delay(vs->vd->key_delay_ms);
>  }
>
>  static int current_led_state(VncState *vs)
> @@ -1792,6 +1793,7 @@ static void do_key_event(VncState *vs, int down, int
> keycode, int sym)
>
>      if (qemu_console_is_graphic(NULL)) {
>          qemu_input_event_send_key_number(vs->vd->dcl.con, keycode, down);
> +        qemu_input_event_send_key_delay(vs->vd->key_delay_ms);
>      } else {
>          bool numlock = vs->modifiers_state[0x45];
>          bool control = (vs->modifiers_state[0x1d] ||
> @@ -1913,6 +1915,7 @@ static void vnc_release_modifiers(VncState *vs)
>              continue;
>          }
>          qemu_input_event_send_key_number(vs->vd->dcl.con, keycode, false);
> +        qemu_input_event_send_key_delay(vs->vd->key_delay_ms);
>      }
>  }
>
> @@ -3249,6 +3252,9 @@ static QemuOptsList qemu_vnc_opts = {
>              .name = "lock-key-sync",
>              .type = QEMU_OPT_BOOL,
>          },{
> +            .name = "key-delay-ms",
> +            .type = QEMU_OPT_NUMBER,
> +        },{
>              .name = "sasl",
>              .type = QEMU_OPT_BOOL,
>          },{
> @@ -3486,6 +3492,7 @@ void vnc_display_open(const char *id, Error **errp)
>  #endif
>      int acl = 0;
>      int lock_key_sync = 1;
> +    int key_delay_ms;
>
>      if (!vs) {
>          error_setg(errp, "VNC display not active");
> @@ -3604,6 +3611,7 @@ void vnc_display_open(const char *id, Error **errp)
>
>      reverse = qemu_opt_get_bool(opts, "reverse", false);
>      lock_key_sync = qemu_opt_get_bool(opts, "lock-key-sync", true);
> +    key_delay_ms = qemu_opt_get_number(opts, "key-delay-ms", 1);
>      sasl = qemu_opt_get_bool(opts, "sasl", false);
>  #ifndef CONFIG_VNC_SASL
>      if (sasl) {
> @@ -3735,6 +3743,7 @@ void vnc_display_open(const char *id, Error **errp)
>      }
>  #endif
>      vs->lock_key_sync = lock_key_sync;
> +    vs->key_delay_ms = key_delay_ms;
>
>      device_id = qemu_opt_get(opts, "display");
>      if (device_id) {
> diff --git a/ui/vnc.h b/ui/vnc.h
> index 81a3261..6568bca 100644
> --- a/ui/vnc.h
> +++ b/ui/vnc.h
> @@ -155,6 +155,7 @@ struct VncDisplay
>      DisplayChangeListener dcl;
>      kbd_layout_t *kbd_layout;
>      int lock_key_sync;
> +    int key_delay_ms;
>      QemuMutex mutex;
>
>      QEMUCursor *cursor;
> --
> 1.8.3.1
>
>
>
diff mbox

Patch

diff --git a/qemu-options.hx b/qemu-options.hx
index 6106520..9f33361 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -1410,6 +1410,14 @@  everybody else.  'ignore' completely ignores the shared flag and
 allows everybody connect unconditionally.  Doesn't conform to the rfb
 spec but is traditional QEMU behavior.
 
+@item key-delay-ms
+
+Set keyboard delay, for key down and key up events, in milliseconds.
+Default is 1.  Keyboards are low-bandwidth devices, so this slowdown
+can help the device and guest to keep up and not lose events in case
+events are arriving in bulk.  Possible causes for the latter are flaky
+network connections, or scripts for automated testing.
+
 @end table
 ETEXI
 
diff --git a/ui/vnc.c b/ui/vnc.c
index d2ebf1f..ea3b3d4 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -1629,6 +1629,7 @@  static void reset_keys(VncState *vs)
     for(i = 0; i < 256; i++) {
         if (vs->modifiers_state[i]) {
             qemu_input_event_send_key_number(vs->vd->dcl.con, i, false);
+            qemu_input_event_send_key_delay(vs->vd->key_delay_ms);
             vs->modifiers_state[i] = 0;
         }
     }
@@ -1638,9 +1639,9 @@  static void press_key(VncState *vs, int keysym)
 {
     int keycode = keysym2scancode(vs->vd->kbd_layout, keysym) & SCANCODE_KEYMASK;
     qemu_input_event_send_key_number(vs->vd->dcl.con, keycode, true);
-    qemu_input_event_send_key_delay(0);
+    qemu_input_event_send_key_delay(vs->vd->key_delay_ms);
     qemu_input_event_send_key_number(vs->vd->dcl.con, keycode, false);
-    qemu_input_event_send_key_delay(0);
+    qemu_input_event_send_key_delay(vs->vd->key_delay_ms);
 }
 
 static int current_led_state(VncState *vs)
@@ -1792,6 +1793,7 @@  static void do_key_event(VncState *vs, int down, int keycode, int sym)
 
     if (qemu_console_is_graphic(NULL)) {
         qemu_input_event_send_key_number(vs->vd->dcl.con, keycode, down);
+        qemu_input_event_send_key_delay(vs->vd->key_delay_ms);
     } else {
         bool numlock = vs->modifiers_state[0x45];
         bool control = (vs->modifiers_state[0x1d] ||
@@ -1913,6 +1915,7 @@  static void vnc_release_modifiers(VncState *vs)
             continue;
         }
         qemu_input_event_send_key_number(vs->vd->dcl.con, keycode, false);
+        qemu_input_event_send_key_delay(vs->vd->key_delay_ms);
     }
 }
 
@@ -3249,6 +3252,9 @@  static QemuOptsList qemu_vnc_opts = {
             .name = "lock-key-sync",
             .type = QEMU_OPT_BOOL,
         },{
+            .name = "key-delay-ms",
+            .type = QEMU_OPT_NUMBER,
+        },{
             .name = "sasl",
             .type = QEMU_OPT_BOOL,
         },{
@@ -3486,6 +3492,7 @@  void vnc_display_open(const char *id, Error **errp)
 #endif
     int acl = 0;
     int lock_key_sync = 1;
+    int key_delay_ms;
 
     if (!vs) {
         error_setg(errp, "VNC display not active");
@@ -3604,6 +3611,7 @@  void vnc_display_open(const char *id, Error **errp)
 
     reverse = qemu_opt_get_bool(opts, "reverse", false);
     lock_key_sync = qemu_opt_get_bool(opts, "lock-key-sync", true);
+    key_delay_ms = qemu_opt_get_number(opts, "key-delay-ms", 1);
     sasl = qemu_opt_get_bool(opts, "sasl", false);
 #ifndef CONFIG_VNC_SASL
     if (sasl) {
@@ -3735,6 +3743,7 @@  void vnc_display_open(const char *id, Error **errp)
     }
 #endif
     vs->lock_key_sync = lock_key_sync;
+    vs->key_delay_ms = key_delay_ms;
 
     device_id = qemu_opt_get(opts, "display");
     if (device_id) {
diff --git a/ui/vnc.h b/ui/vnc.h
index 81a3261..6568bca 100644
--- a/ui/vnc.h
+++ b/ui/vnc.h
@@ -155,6 +155,7 @@  struct VncDisplay
     DisplayChangeListener dcl;
     kbd_layout_t *kbd_layout;
     int lock_key_sync;
+    int key_delay_ms;
     QemuMutex mutex;
 
     QEMUCursor *cursor;