From nobody Tue Feb 10 01:15:21 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551090582288761.34977210504; Mon, 25 Feb 2019 02:29:42 -0800 (PST) Received: from localhost ([127.0.0.1]:34803 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyDW1-0001EJ-6L for importer@patchew.org; Mon, 25 Feb 2019 05:29:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:33144) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gyDRa-0006Nw-Kp for qemu-devel@nongnu.org; Mon, 25 Feb 2019 05:25:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gyDRZ-0003GA-Gs for qemu-devel@nongnu.org; Mon, 25 Feb 2019 05:25:06 -0500 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:36371) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gyDRZ-00031H-5C for qemu-devel@nongnu.org; Mon, 25 Feb 2019 05:25:05 -0500 Received: by mail-wr1-x441.google.com with SMTP id o17so9272107wrw.3 for ; Mon, 25 Feb 2019 02:24:45 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id v10sm1764692wrn.26.2019.02.25.02.24.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Feb 2019 02:24:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wbnpQMYk0xGvZOa47pDN5/IqA0K+yihWn/3R2zb8SJU=; b=ac6cQBZktnwzMsfE2h18B4tYKoXeFdNQxkSnrrCnMovjgAy84u4RckloC6+RXPx3/q hHooS0+bi4iSnVmEufqFUDQGTbxOyi1S/Hk8636/AT/42/sALEubWjZGwU8iQact3ZER WXVgo5YjdBi3eGOVfU3f6ROY77PlNJErr7yISLN6hpPpO5NwqrLi9d1JKU58hueUBfnY I5TfnUx474mkEZ2YaJxa4eDelFa+ynCldduoDR50ww3ofxGH+2mEs2hUxO/qf9kV51KH sa0vPFDs53lbblVx3lssSZrRhaG+5QGgWIJKQEsxmGujzsK8BGgtSAdG9XqdpwjYePxj l/Wg== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=wbnpQMYk0xGvZOa47pDN5/IqA0K+yihWn/3R2zb8SJU=; b=aUTSZLICac/J6w5Kihkaottc53d/Jep09xMhWHjjGYDez/THnYttOk0dmvZQ3Ac7Xm suIx2MEr4gbi/X8EXH9N2+PzobB+9ionoWpBx+q1brnSwu/dNFewzTZIOH4s/VNFxiAU FgCB0jsvWIFCuZk5zVb+WgrEZNR5VaEqc5vBTzdKnLsVMx614H9zIOE1fNrYETuRrLfR JnyBozrD3999v4eJStFbnDWotktWllZxEQDJq9JVozeAFOjUJIDPxgAIVpYXFYs2rD14 ulunNhzp9a2GJStS/UY2uRaJzu1BlqFw5XQhCgs2jgpsenXseqw+gx8Pte0XvDkXWq8t BG7A== X-Gm-Message-State: AHQUAuZt0HZfSIvhX9rPAve0BuZC8KpGJJSEJtnPodrE+af3EpPjWO+g nD8kzKEMmqSBGL3an/KA3LMaoQSkyDo= X-Google-Smtp-Source: AHgI3IaRDmkzOP1+CVDkIv5psfsOmgeMqJxHgRHI9sD3zv96GPPKmldp5Bc3Lk+qns6zXfZVemvypA== X-Received: by 2002:adf:f543:: with SMTP id j3mr11513733wrp.220.1551090284111; Mon, 25 Feb 2019 02:24:44 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Date: Mon, 25 Feb 2019 10:24:31 +0000 Message-Id: <20190225102433.22401-6-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190225102433.22401-1-peter.maydell@linaro.org> References: <20190225102433.22401-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 Subject: [Qemu-devel] [PATCH v3 5/7] ui/cocoa: Don't call NSApp sendEvent directly from handleEvent 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: Roman Bolshakov , patches@linaro.org, John Arbuckle , Gerd Hoffmann , Ben Hekster , Berkus Decker Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Currently the handleEvent method will directly call the NSApp sendEvent method for any events that we want to let OSX deal with. When we rearrange the event handling code, the way that we say "let OSX have this event" is going to change. Prepare for that by refactoring so that handleEvent returns a flag indicating whether it consumed the event. Suggested-by: BALATON Zoltan Signed-off-by: Peter Maydell Reviewed-by: BALATON Zoltan Reviewed-by: Roman Bolshakov Tested-by: Roman Bolshakov Message-id: 20190214102816.3393-6-peter.maydell@linaro.org --- Changes since v2: remove stray whitespace --- ui/cocoa.m | 49 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index d1fc1a6aff..1b54d42aba 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -129,8 +129,9 @@ NSTextField *pauseLabel; NSArray * supportedImageFileTypes; =20 -// Utility function to run specified code block with iothread lock held +// Utility functions to run specified code block with iothread lock held typedef void (^CodeBlock)(void); +typedef bool (^BoolCodeBlock)(void); =20 static void with_iothread_lock(CodeBlock block) { @@ -144,6 +145,21 @@ static void with_iothread_lock(CodeBlock block) } } =20 +static bool bool_with_iothread_lock(BoolCodeBlock block) +{ + bool locked =3D qemu_mutex_iothread_locked(); + bool val; + + if (!locked) { + qemu_mutex_lock_iothread(); + } + val =3D block(); + if (!locked) { + qemu_mutex_unlock_iothread(); + } + return val; +} + // Mac to QKeyCode conversion const int mac_to_qkeycode_map[] =3D { [kVK_ANSI_A] =3D Q_KEY_CODE_A, @@ -320,8 +336,8 @@ - (void) grabMouse; - (void) ungrabMouse; - (void) toggleFullScreen:(id)sender; - (void) handleMonitorInput:(NSEvent *)event; -- (void) handleEvent:(NSEvent *)event; -- (void) handleEventLocked:(NSEvent *)event; +- (bool) handleEvent:(NSEvent *)event; +- (bool) handleEventLocked:(NSEvent *)event; - (void) setAbsoluteEnabled:(BOOL)tIsAbsoluteEnabled; /* The state surrounding mouse grabbing is potentially confusing. * isAbsoluteEnabled tracks qemu_input_is_absolute() [ie "is the emulated @@ -664,15 +680,16 @@ - (void) handleMonitorInput:(NSEvent *)event } } =20 -- (void) handleEvent:(NSEvent *)event +- (bool) handleEvent:(NSEvent *)event { - with_iothread_lock(^{ - [self handleEventLocked:event]; + return bool_with_iothread_lock(^{ + return [self handleEventLocked:event]; }); } =20 -- (void) handleEventLocked:(NSEvent *)event +- (bool) handleEventLocked:(NSEvent *)event { + /* Return true if we handled the event, false if it should be given to= OSX */ COCOA_DEBUG("QemuCocoaView: handleEvent\n"); int buttons =3D 0; int keycode =3D 0; @@ -743,8 +760,7 @@ - (void) handleEventLocked:(NSEvent *)event if (keycode =3D=3D Q_KEY_CODE_F) { switched_to_fullscreen =3D true; } - [NSApp sendEvent:event]; - return; + return false; } =20 // default @@ -759,12 +775,12 @@ - (void) handleEventLocked:(NSEvent *)event // enable graphic console case '1' ... '9': console_select(key - '0' - 1); /* ascii math */ - return; + return true; =20 // release the mouse grab case 'g': [self ungrabMouse]; - return; + return true; } } } @@ -781,7 +797,7 @@ - (void) handleEventLocked:(NSEvent *)event // don't pass the guest a spurious key-up if we treated this // command-key combo as a host UI action if (!isMouseGrabbed && ([event modifierFlags] & NSEventModifie= rFlagCommand)) { - return; + return true; } =20 if (qemu_console_is_graphic(NULL)) { @@ -875,7 +891,7 @@ - (void) handleEventLocked:(NSEvent *)event mouse_event =3D false; break; default: - [NSApp sendEvent:event]; + return false; } =20 if (mouse_event) { @@ -911,10 +927,11 @@ - (void) handleEventLocked:(NSEvent *)event qemu_input_queue_rel(dcl->con, INPUT_AXIS_Y, (int)[event d= eltaY]); } } else { - [NSApp sendEvent:event]; + return false; } qemu_input_event_sync(); } + return true; } =20 - (void) grabMouse @@ -1753,7 +1770,9 @@ static void cocoa_refresh(DisplayChangeListener *dcl) event =3D [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:di= stantPast inMode: NSDefaultRunLoopMode dequeue:YES]; if (event !=3D nil) { - [cocoaView handleEvent:event]; + if (![cocoaView handleEvent:event]) { + [NSApp sendEvent:event]; + } } } while(event !=3D nil); [pool release]; --=20 2.17.2 (Apple Git-113)