qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] ui/vnc: make sure necessary shift-states are in effect when sending keys
@ 2015-01-25 18:52 Nathan Baum
  2015-01-25 20:14 ` [Qemu-devel] [PATCH v2] " Nathan Baum
  0 siblings, 1 reply; 2+ messages in thread
From: Nathan Baum @ 2015-01-25 18:52 UTC (permalink / raw)
  To: qemu-devel; +Cc: Nathan Baum

If the keymap specifies the shift modifier for a keysym and that modifier
isn't in effect, send a fake press/release for shift around the key event.

Specifically, this resolves the issue of # producing a 3 when I press the
# on my UK keyboard with a VM with a US keyboard. (FYI the UK # key is
where the US @ key goes.)

I think this is a legit change because the RFB protocol specification says
that servers are expected to do this. It specifically highlights # as an
example of where you'd need to do this!

I wasn't sure whether to do this for all the modifiers - my use case
doesn't call for it - so I didn't.

Signed-off-by: Nathan Baum <n@p12a.org.uk>
---
 ui/vnc.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/ui/vnc.c b/ui/vnc.c
index a742c90..200cdd7 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -1893,7 +1893,22 @@ 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);
+        int scancode = keysym2scancode(vs->vd->kbd_layout, sym);
+        if (scancode == (scancode & SCANCODE_KEYMASK)) {
+            qemu_input_event_send_key_number(vs->vd->dcl.con, keycode, down);
+        } else {
+            if (scancode & SCANCODE_SHIFT && !(vs->modifiers_state[0x2a] ||
+                                               vs->modifiers_state[0x36]) {
+                qemu_input_event_send_key_number(vs->vd->dcl.con, 0x2a, true);
+                qemu_input_event_send_key_delay(0);
+            }
+            qemu_input_event_send_key_number(vs->vd->dcl.con, keycode, down);
+            if (scancode & SCANCODE_SHIFT && !(vs->modifiers_state[0x2a] ||
+                                               vs->modifiers_state[0x36]) {
+              qemu_input_event_send_key_delay(0);
+              qemu_input_event_send_key_number(vs->vd->dcl.con, 0x2a, false);
+            }
+        }
     } else {
         bool numlock = vs->modifiers_state[0x45];
         bool control = (vs->modifiers_state[0x1d] ||
-- 
2.2.1

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

* [Qemu-devel] [PATCH v2] ui/vnc: make sure necessary shift-states are in effect when sending keys
  2015-01-25 18:52 [Qemu-devel] [PATCH] ui/vnc: make sure necessary shift-states are in effect when sending keys Nathan Baum
@ 2015-01-25 20:14 ` Nathan Baum
  0 siblings, 0 replies; 2+ messages in thread
From: Nathan Baum @ 2015-01-25 20:14 UTC (permalink / raw)
  To: qemu-devel; +Cc: Nathan Baum

v2: Replaced some parentheses I lost when preparing the patch for submission.

If the keymap specifies the shift modifier for a keysym and that modifier
isn't in effect, send a fake press/release for shift around the key event.

Specifically, this resolves the issue of # producing a 3 when I press the
# on my UK keyboard with a VM with a US keyboard. (FYI the UK # key is
where the US @ key goes.)

I think this is a legit change because the RFB protocol specification says
that servers are expected to do this. It specifically highlights # as an
example of where you'd need to do this!

I wasn't sure whether to do this for all the modifiers - my use case
doesn't call for it - so I didn't.

Signed-off-by: Nathan Baum <n@p12a.org.uk>
---
 ui/vnc.c | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/ui/vnc.c b/ui/vnc.c
index a742c90..acfb24e 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -1893,7 +1893,22 @@ 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);
+        int scancode = keysym2scancode(vs->vd->kbd_layout, sym);
+        if (scancode == (scancode & SCANCODE_KEYMASK)) {
+            qemu_input_event_send_key_number(vs->vd->dcl.con, keycode, down);
+        } else {
+            if (scancode & SCANCODE_SHIFT && !(vs->modifiers_state[0x2a] ||
+                                               vs->modifiers_state[0x36])) {
+                qemu_input_event_send_key_number(vs->vd->dcl.con, 0x2a, true);
+                qemu_input_event_send_key_delay(0);
+            }
+            qemu_input_event_send_key_number(vs->vd->dcl.con, keycode, down);
+            if (scancode & SCANCODE_SHIFT && !(vs->modifiers_state[0x2a] ||
+                                               vs->modifiers_state[0x36])) {
+              qemu_input_event_send_key_delay(0);
+              qemu_input_event_send_key_number(vs->vd->dcl.con, 0x2a, false);
+            }
+        }
     } else {
         bool numlock = vs->modifiers_state[0x45];
         bool control = (vs->modifiers_state[0x1d] ||
-- 
2.2.1

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

end of thread, other threads:[~2015-01-25 20:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-25 18:52 [Qemu-devel] [PATCH] ui/vnc: make sure necessary shift-states are in effect when sending keys Nathan Baum
2015-01-25 20:14 ` [Qemu-devel] [PATCH v2] " Nathan Baum

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