[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH] Make scrolling work again
From: |
John Arbuckle |
Subject: |
[Qemu-devel] [PATCH] Make scrolling work again |
Date: |
Thu, 5 Oct 2017 14:43:09 -0400 |
Make scrolling in the monitor work.
Signed-off-by: John Arbuckle <address@hidden>
---
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)
- [Qemu-devel] [PATCH] Make scrolling work again,
John Arbuckle <=