From patchwork Wed Jan 11 10:58:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 9509853 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 4C6AB6075C for ; Wed, 11 Jan 2017 10:58:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4857E284F3 for ; Wed, 11 Jan 2017 10:58:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3BB4528542; Wed, 11 Jan 2017 10:58:39 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 CCFDC284F3 for ; Wed, 11 Jan 2017 10:58:38 +0000 (UTC) Received: from localhost ([::1]:53238 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cRGc1-0001GU-CY for patchwork-qemu-devel@patchwork.kernel.org; Wed, 11 Jan 2017 05:58:37 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40828) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cRGbk-0001GP-TC for qemu-devel@nongnu.org; Wed, 11 Jan 2017 05:58:21 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cRGbh-0007Um-Qg for qemu-devel@nongnu.org; Wed, 11 Jan 2017 05:58:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46264) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cRGbh-0007UO-IQ for qemu-devel@nongnu.org; Wed, 11 Jan 2017 05:58:17 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 73E4031B305; Wed, 11 Jan 2017 10:58:17 +0000 (UTC) Received: from nilsson.home.kraxel.org (ovpn-116-51.ams2.redhat.com [10.36.116.51]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v0BAwGGx019158; Wed, 11 Jan 2017 05:58:16 -0500 Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id 7591A80FD4; Wed, 11 Jan 2017 11:58:14 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 11 Jan 2017 11:58:12 +0100 Message-Id: <1484132292-21458-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 11 Jan 2017 10:58:17 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] cocoa: stop using MOUSE_EVENT_* 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: Peter Maydell , Gerd Hoffmann Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP No need to go the indirect route with a bitfield and mapping the bits to INPUT_BUTTON_*. We can use a bool array and INPUT_BUTTON_* directly instead. Untested, not even compiled, due to lack of a osx^Wmacos machine. Test results are very welcome. Signed-off-by: Gerd Hoffmann --- ui/cocoa.m | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index 26d4a1c..599b899 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -66,7 +66,7 @@ typedef struct { NSWindow *normalWindow, *about_window; static DisplayChangeListener *dcl; -static int last_buttons; +static bool last_buttons[INPUT_BUTTON__MAX]; int gArgc; char **gArgv; @@ -511,7 +511,9 @@ QemuCocoaView *cocoaView; { COCOA_DEBUG("QemuCocoaView: handleEvent\n"); - int buttons = 0; + bool buttons[INPUT_BUTTON__MAX] = { + [ 0 ... (INPUT_BUTTON__MAX-1) ] = false; + }; int keycode; bool mouse_event = false; NSPoint p = [event locationInWindow]; @@ -638,34 +640,34 @@ QemuCocoaView *cocoaView; break; case NSLeftMouseDown: if ([event modifierFlags] & NSCommandKeyMask) { - buttons |= MOUSE_EVENT_RBUTTON; + buttons[INPUT_BUTTON_RIGHT] = true; } else { - buttons |= MOUSE_EVENT_LBUTTON; + buttons[INPUT_BUTTON_LEFT] = true; } mouse_event = true; break; case NSRightMouseDown: - buttons |= MOUSE_EVENT_RBUTTON; + buttons[INPUT_BUTTON_RIGHT] = true; mouse_event = true; break; case NSOtherMouseDown: - buttons |= MOUSE_EVENT_MBUTTON; + buttons[INPUT_BUTTON_MIDDLE] = true; mouse_event = true; break; case NSLeftMouseDragged: if ([event modifierFlags] & NSCommandKeyMask) { - buttons |= MOUSE_EVENT_RBUTTON; + buttons[INPUT_BUTTON_RIGHT] = true; } else { - buttons |= MOUSE_EVENT_LBUTTON; + buttons[INPUT_BUTTON_LEFT] = true; } mouse_event = true; break; case NSRightMouseDragged: - buttons |= MOUSE_EVENT_RBUTTON; + buttons[INPUT_BUTTON_RIGHT] = true; mouse_event = true; break; case NSOtherMouseDragged: - buttons |= MOUSE_EVENT_MBUTTON; + buttons[INPUT_BUTTON_MIDDLE] = true; mouse_event = true; break; case NSLeftMouseUp: @@ -684,8 +686,11 @@ QemuCocoaView *cocoaView; break; case NSScrollWheel: if (isMouseGrabbed) { - buttons |= ([event deltaY] < 0) ? - MOUSE_EVENT_WHEELUP : MOUSE_EVENT_WHEELDN; + if ([event deltaY] < 0) { + buttons[INPUT_BUTTON_WHEEL_UP] = true; + } else { + buttons[INPUT_BUTTON_WHEEL_DOWN] = true; + } } mouse_event = true; break; @@ -703,15 +708,14 @@ QemuCocoaView *cocoaView; */ if ((isMouseGrabbed || [[self window] isKeyWindow]) && (last_buttons != buttons)) { - static uint32_t bmap[INPUT_BUTTON__MAX] = { - [INPUT_BUTTON_LEFT] = MOUSE_EVENT_LBUTTON, - [INPUT_BUTTON_MIDDLE] = MOUSE_EVENT_MBUTTON, - [INPUT_BUTTON_RIGHT] = MOUSE_EVENT_RBUTTON, - [INPUT_BUTTON_WHEEL_UP] = MOUSE_EVENT_WHEELUP, - [INPUT_BUTTON_WHEEL_DOWN] = MOUSE_EVENT_WHEELDN, - }; - qemu_input_update_buttons(dcl->con, bmap, last_buttons, buttons); - last_buttons = buttons; + InputButton btn; + + for (btn = 0; btn < INPUT_BUTTON__MAX; btn++) { + if (last_button[btn] != button[btn]) { + qemu_input_queue_btn(dcl->con, btn, button[btn]); + last_button[btn] = button[btn]; + } + } } if (isMouseGrabbed) { if (isAbsoluteEnabled) {