From patchwork Thu Oct 5 18:43:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Programmingkid X-Patchwork-Id: 9987785 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4631D60247 for ; Thu, 5 Oct 2017 18:45:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 39F4528D15 for ; Thu, 5 Oct 2017 18:45:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2D89D28D11; Thu, 5 Oct 2017 18:45:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9E4C228D11 for ; Thu, 5 Oct 2017 18:45:50 +0000 (UTC) Received: from localhost ([::1]:41566 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e0B9Z-0007xJ-LS for patchwork-qemu-devel@patchwork.kernel.org; Thu, 05 Oct 2017 14:45:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46394) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e0B7O-0006v3-Pd for qemu-devel@nongnu.org; Thu, 05 Oct 2017 14:43:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e0B7J-0005Ve-OR for qemu-devel@nongnu.org; Thu, 05 Oct 2017 14:43:34 -0400 Received: from mail-it0-x241.google.com ([2607:f8b0:4001:c0b::241]:54479) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e0B7J-0005VO-JM for qemu-devel@nongnu.org; Thu, 05 Oct 2017 14:43:29 -0400 Received: by mail-it0-x241.google.com with SMTP id 72so1968268itk.3 for ; Thu, 05 Oct 2017 11:43:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=urW2KrXIuHoWc2T+HYUP6qKobJs1px988hZ9YPSHSIs=; b=ggl8rcI5AhoFyE26uOrJx6rJJlK2gTG1g62KYFaqZP0qdTCD42DNeKzcwdgXbPl8s2 FMSDdwFHaJsYyiJlDQ2ygYdWl2GBYpE2pBIfzD14zaJile4CjTRo7HCGOe74VUAEHkiM M1BmX3jJp8mXGSn9P55YXYdqOIGLbgzkxapncqRkXUMm9JAqiEtJR574jxgzSX2THfnP YuzkhMkMX60qrG5wUHK7gj/daZVx2qQbBXXp04eVmOrNHG9IiZrm08SjDUi+m0ro30Tj S6quT7ygZFfWJ4Qw4lzeu5/f4yzleU4VB0e/YDBDhKgiDHNEnN5SO1d84kJbJbrYmX6y eiTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=urW2KrXIuHoWc2T+HYUP6qKobJs1px988hZ9YPSHSIs=; b=K0poeAHZLljWSIgGEnaJPAPnk3TzdwV+4ZUACZrHgVylLQu6esIRBaUWi2pdfFpntM bWAqiQcNcAuZlcQPeym4oILMQz3YPhK3U2zMU9WkWHpHbWN9+JoIWI5hHDJGLx/A89Wb X/Ev/Crk9dmCHt+WDB1eBXADMkH9DJzjOy93BRvVGsuQh+7Dh8KKRLXphAbP+5ZJkZhw fY2D06l6rHtC+LtsVF48wE5fo8X1V2gY7DkogeDMa3Crk3UrgfGzBcbsY2jwbTWUOQI/ SUnbYe1yNujGTKzyGAHSwbXNTQrRFz3G8dq5ee5KgcNgK2bH97QTabAWc0f0krjM/oay bVOg== X-Gm-Message-State: AMCzsaXCxXIxL+KrBz17T+FfTcXkKcsMDM2ccZEmYDKicnFdIJe+Y8Yz E1yG7Cq5KzHlavSRkJPNkHg= X-Google-Smtp-Source: AOwi7QAliw7XWQo9gWKhi54JsjMj/Ry3UYQpjr0QsQBdPUxF0QNbH1h24CDx/e8uHc8/2/FP5gW3Aw== X-Received: by 10.36.115.148 with SMTP id y142mr76499itb.147.1507229008777; Thu, 05 Oct 2017 11:43:28 -0700 (PDT) Received: from localhost.localdomain (d199-74-164-53.col.wideopenwest.com. [74.199.53.164]) by smtp.gmail.com with ESMTPSA id k188sm17956itd.34.2017.10.05.11.43.27 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 05 Oct 2017 11:43:28 -0700 (PDT) From: John Arbuckle To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Thu, 5 Oct 2017 14:43:09 -0400 Message-Id: <20171005184309.14521-1-programmingkidx@gmail.com> X-Mailer: git-send-email 2.13.5 (Apple Git-94) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c0b::241 Subject: [Qemu-devel] [PATCH] Make scrolling work again X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Arbuckle Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Make scrolling in the monitor work. Signed-off-by: John Arbuckle --- 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: