From: John Arbuckle <programmingkidx@gmail.com>
To: peter.maydell@linaro.org, qemu-devel@nongnu.org
Cc: John Arbuckle <programmingkidx@gmail.com>
Subject: [Qemu-devel] [PATCH] Make scrolling work again
Date: Thu, 5 Oct 2017 14:43:09 -0400 [thread overview]
Message-ID: <20171005184309.14521-1-programmingkidx@gmail.com> (raw)
Make scrolling in the monitor work.
Signed-off-by: John Arbuckle <programmingkidx@gmail.com>
---
ui/cocoa.m | 88 +++++++++++++++++++++++++++++++++++++++-----------------------
1 file changed, 56 insertions(+), 32 deletions(-)
diff --git a/ui/cocoa.m b/ui/cocoa.m
index 93e56d0518..5545c42b9c 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -281,6 +281,7 @@ - (void) switchSurface:(DisplaySurface *)surface;
- (void) grabMouse;
- (void) ungrabMouse;
- (void) toggleFullScreen:(id)sender;
+- (void) handleMonitorInput:(NSEvent *)event;
- (void) handleEvent:(NSEvent *)event;
- (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled;
/* The state surrounding mouse grabbing is potentially confusing.
@@ -554,6 +555,60 @@ - (void) toggleStatefulModifier: (int)keycode {
qemu_input_event_send_key_qcode(dcl->con, keycode, false);
}
+// Does the work of sending input to the monitor
+- (void) handleMonitorInput:(NSEvent *)event
+{
+ int keysym = 0;
+ int control_key = 0;
+
+ // if the control key is down
+ if ([event modifierFlags] & NSEventModifierFlagControl) {
+ control_key = 4; // shifts by one nibble (hex digit)
+ }
+
+ /* translates Macintosh keycodes to QEMU's keysym */
+ int translation_matrix[] = {
+ [0 ... 0xff] = 0, // invalid key
+
+ [kVK_UpArrow] = QEMU_KEY_UP,
+ [kVK_DownArrow] = QEMU_KEY_DOWN,
+ [kVK_RightArrow] = QEMU_KEY_RIGHT,
+ [kVK_LeftArrow] = QEMU_KEY_LEFT,
+ [kVK_Home] = QEMU_KEY_HOME,
+ [kVK_End] = QEMU_KEY_END,
+ [kVK_PageUp] = QEMU_KEY_PAGEUP,
+ [kVK_PageDown] = QEMU_KEY_PAGEDOWN,
+ [kVK_ForwardDelete] = QEMU_KEY_DELETE,
+ [kVK_Delete] = QEMU_KEY_BACKSPACE,
+
+ /*
+ * Shift value by one hex digit.
+ * Since no key has a 3 digit hex value there is no chance
+ * for overlap.
+ */
+ [kVK_UpArrow << 4] = QEMU_KEY_CTRL_UP,
+ [kVK_DownArrow << 4] = QEMU_KEY_CTRL_DOWN,
+ [kVK_RightArrow << 4] = QEMU_KEY_CTRL_RIGHT,
+ [kVK_LeftArrow << 4] = QEMU_KEY_CTRL_LEFT,
+ [kVK_Home << 4] = QEMU_KEY_CTRL_HOME,
+ [kVK_End << 4] = QEMU_KEY_CTRL_END,
+ [kVK_PageUp << 4] = QEMU_KEY_CTRL_PAGEUP,
+ [kVK_PageDown << 4] = QEMU_KEY_CTRL_PAGEDOWN,
+ };
+
+ keysym = translation_matrix[[event keyCode] << control_key];
+
+ // if not a key that needs translating
+ if (keysym == 0) {
+ NSString *ks = [event characters];
+ if ([ks length] > 0)
+ keysym = [ks characterAtIndex:0];
+ }
+
+ if(keysym)
+ kbd_put_keysym(keysym);
+}
+
- (void) handleEvent:(NSEvent *)event
{
COCOA_DEBUG("QemuCocoaView: handleEvent\n");
@@ -641,38 +696,7 @@ - (void) handleEvent:(NSEvent *)event
// handlekeys for Monitor
} else {
- int keysym = 0;
- switch([event keyCode]) {
- case 115:
- keysym = QEMU_KEY_HOME;
- break;
- case 117:
- keysym = QEMU_KEY_DELETE;
- break;
- case 119:
- keysym = QEMU_KEY_END;
- break;
- case 123:
- keysym = QEMU_KEY_LEFT;
- break;
- case 124:
- keysym = QEMU_KEY_RIGHT;
- break;
- case 125:
- keysym = QEMU_KEY_DOWN;
- break;
- case 126:
- keysym = QEMU_KEY_UP;
- break;
- default:
- {
- NSString *ks = [event characters];
- if ([ks length] > 0)
- keysym = [ks characterAtIndex:0];
- }
- }
- if (keysym)
- kbd_put_keysym(keysym);
+ [self handleMonitorInput: event];
}
break;
case NSEventTypeKeyUp:
--
2.13.5 (Apple Git-94)
next reply other threads:[~2017-10-05 18:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-05 18:43 John Arbuckle [this message]
2017-10-31 16:23 ` [Qemu-devel] [PATCH] Make scrolling work again Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171005184309.14521-1-programmingkidx@gmail.com \
--to=programmingkidx@gmail.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).