From patchwork Wed Nov 1 15:46:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Programmingkid X-Patchwork-Id: 10036707 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 66369603B5 for ; Wed, 1 Nov 2017 16:05:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 272DB28C8B for ; Wed, 1 Nov 2017 16:05:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1BDA828C98; Wed, 1 Nov 2017 16:05:59 +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 9B81728C8B for ; Wed, 1 Nov 2017 16:05:58 +0000 (UTC) Received: from localhost ([::1]:56560 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9vWf-0000jY-CQ for patchwork-qemu-devel@patchwork.kernel.org; Wed, 01 Nov 2017 12:05:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33420) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9vE6-0001XZ-7y for qemu-devel@nongnu.org; Wed, 01 Nov 2017 11:46:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9vE1-0000Sc-5D for qemu-devel@nongnu.org; Wed, 01 Nov 2017 11:46:46 -0400 Received: from mail-io0-x241.google.com ([2607:f8b0:4001:c06::241]:55131) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e9vE1-0000Rj-0D for qemu-devel@nongnu.org; Wed, 01 Nov 2017 11:46:41 -0400 Received: by mail-io0-x241.google.com with SMTP id e89so6951462ioi.11 for ; Wed, 01 Nov 2017 08:46:40 -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=L5eP8Yo5sAyw4Ep6cdfT3qyAv00CjpSWTs7gs5PIgCM=; b=Y16BOSpwRkUm6CA51JmOuWot38uI5/wW++LrR7ZR9ycK7pymiArRyT0yUkCzwDh4hR NbYvMdAbADT/62Aav0si5HQf2lCL2YVYTClLy1qa30JAGS5E1C3BNouQYH8dJLceZt2U DfsaPhzUlqHhDe/Vr+VzganMK1bDJ8psDS2qBD6+IYJaN82HlFUukuAteagWqyWniKQo m6exbXqIATwz0BfPxmrId6jPxbKRa89QVcNuZJaXyQD6xC8WbOmt0TzYS7ZHsi/q+Rei 8zvliitatOGUlbY5GIaqQ4LNKcRAERNpGDbks8v8v/C1QvCa9bybUwRtnt2CORjs7MP0 nyCA== 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=L5eP8Yo5sAyw4Ep6cdfT3qyAv00CjpSWTs7gs5PIgCM=; b=SAtxj1G7CaiAaq/SSNqpTY0xUHy2rx9URn+VZuBFIg1H4mQ9Sd07WZ8u9zHUgixpAK GCHbbghTTO2mlcb/SqNnTQW+5gdJB4m/k5tBuIq6pzCLYQLUVOEmAPdERA0cXu8MF5qT Zr2/Q7rGTr3VtsNRSq583NK/BCNNXqb8kel0VqaiUz6wrY/SIv3mJlvHi9BdChBt2mhJ J8NHKxbKfxiWR8aolBbWbRnNT/a7UBC8N2yFA+vzS0Y6e00TniIe/+oeLN7UNjUon6DM XSv8A+qJnuH1EsXPvg7wOa7qGOdvkEuVuYLQ6H/Gjn1QXSCFBFxTMmCIBjXGwLJ8CVpw Knkg== X-Gm-Message-State: AMCzsaXU5CAh6atTDMRzdBRFu6KY/N8gLLpe6wQR+geH290o5M5kXfJC a/B2kRnBbUWllo70545yokw= X-Google-Smtp-Source: ABhQp+RYglAK2fn+gG5f3dPvdvrbqhMmQVStn1TvbFc1uaHWAgE1WUadY2cPDxsHVPUYwAUL2EXKyA== X-Received: by 10.36.200.139 with SMTP id w133mr1085754itf.26.1509551200215; Wed, 01 Nov 2017 08:46:40 -0700 (PDT) Received: from localhost.localdomain (d14-69-20-184.try.wideopenwest.com. [69.14.184.20]) by smtp.gmail.com with ESMTPSA id 5sm364509ion.46.2017.11.01.08.46.39 (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 01 Nov 2017 08:46:39 -0700 (PDT) From: John Arbuckle To: peter.maydell@linaro.org, qemu-devel@nongnu.org Date: Wed, 1 Nov 2017 11:46:07 -0400 Message-Id: <20171101154607.1582-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:c06::241 Subject: [Qemu-devel] [PATCH v2] 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 | 96 +++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 64 insertions(+), 32 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index 93e56d0518..744fa31a56 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,68 @@ - (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 = 1; + } + + /* translates Macintosh keycodes to QEMU's keysym */ + + int without_control_translation[] = { + [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, + }; + + int with_control_translation[] = { + [0 ... 0xff] = 0, // invalid key + + [kVK_UpArrow] = QEMU_KEY_CTRL_UP, + [kVK_DownArrow] = QEMU_KEY_CTRL_DOWN, + [kVK_RightArrow] = QEMU_KEY_CTRL_RIGHT, + [kVK_LeftArrow] = QEMU_KEY_CTRL_LEFT, + [kVK_Home] = QEMU_KEY_CTRL_HOME, + [kVK_End] = QEMU_KEY_CTRL_END, + [kVK_PageUp] = QEMU_KEY_CTRL_PAGEUP, + [kVK_PageDown] = QEMU_KEY_CTRL_PAGEDOWN, + }; + + if (control_key != 0) { /* If the control key is being used */ + if ([event keyCode] < ARRAY_SIZE(with_control_translation)) { + keysym = with_control_translation[[event keyCode]]; + } + } else { + if ([event keyCode] < ARRAY_SIZE(without_control_translation)) { + keysym = without_control_translation[[event keyCode]]; + } + } + + // 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 +704,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: