From patchwork Mon Feb 25 10:24:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 159166 Delivered-To: patches@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp1859824jad; Mon, 25 Feb 2019 02:24:44 -0800 (PST) X-Received: by 2002:a7b:c38d:: with SMTP id s13mr9536611wmj.151.1551090284533; Mon, 25 Feb 2019 02:24:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551090284; cv=none; d=google.com; s=arc-20160816; b=d1TdqTofYDNFX4uqZZKNWBkz1oZ87tE0lEihDf+yHIyEaHqNE++DQdCVRQuxiVpvTK SjfNOipyYoA9T2OBfOJYa9/m7gkLCHStxGnV5iU+KyItBtOzrBuL/aFqkSJofAFycql3 s6tll6ttDChP4vBmibZw7PB4tZfqhKCbalXRXj53YqZYPU/efzhoKLZ025CJz3gdM1Id WY5kTdDqbQ7l6iB3lMMCUGKNlP3Mf/zVrdrmcts7neozDWoT9Xr6lUaV6yxKm/lmDvyd 8iS0cN/aJol2OMml3TsIv1PAfitJFBZ9hgq6SCHeFiRa2hN7h5CbN9LOx1MRmDXkSYkN jWLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=wbnpQMYk0xGvZOa47pDN5/IqA0K+yihWn/3R2zb8SJU=; b=RHEH58CcltpWNKUca7D1b1SW+8Py8ES26jAfIMvh0KUZIKbn+heOzwFnEPQwZz2UXv h7LF5/ux6KyOMwgDTxzu0P9qzmBW87BWyxb7Vz7a4QzZ5P2FrfbfSm1QPDHdqynVGNZy 4jI6VwPclaeS0VECvJ1DDtTqvucpKPVYygztOkVovBEXZ1gQGKap//FWGSk3kM9qwcbf 0VP68rT21yq67RE1BGVpT2gDI02o89pHUkhqByZXv715mBXHQ8R7exvT9VIA/W8z8D8Y 4YKi4CSllqoIpIQAKOF2YK7rCzpltzVi7+xUib7CX9xrZu8S6EEqZszm5ONi2+GgT5DK 1amQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ac6cQBZk; spf=pass (google.com: domain of peter.maydell@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=peter.maydell@linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id x4sor3664073wro.11.2019.02.25.02.24.44 for (Google Transport Security); Mon, 25 Feb 2019 02:24:44 -0800 (PST) Received-SPF: pass (google.com: domain of peter.maydell@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ac6cQBZk; spf=pass (google.com: domain of peter.maydell@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=peter.maydell@linaro.org 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=KdgCjx2Q9xfHQ5O67MqGUegtm7nwKq5lc+Tv5wjBtYfSpSTQEA+LqSGtacrfbETJEf bVCkH02y9Giaqt7kJiU0oq0PEljyqi68v50EZ8sOMrc5kgSMG7IEl+JOHwTvTMTt/srX ZA0noYUph3mEkwi4J8tvh/+jxW/aSgWaHROzMTJ0hIex/ufjrS4lDkgHRsAzR1Fs7Ma+ qgAcWUoKpide9mukqbqqygq6EhH1rTKy6VzNvAGxZvViUKa7buiu4djXVJJSbtBjp9tl ssWbi8JBBqsjLIUqcOUzPDvnr1z0oCJFKYIWewo8x2gAhHQNDquyj0QUXyod4YnLu3Ns Ln4A== X-Gm-Message-State: AHQUAubqqPRyUOrYuhupZwaHLwXtYvR19SgkX15CLCLz3ZOnb2Ws8lRz NWQzFCd0G3UjigNRPbPtzpmEDE7Z 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) Return-Path: 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) From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Roman Bolshakov , BALATON Zoltan , John Arbuckle , Berkus Decker , Gerd Hoffmann , Ben Hekster Subject: [PATCH v3 5/7] ui/cocoa: Don't call NSApp sendEvent directly from handleEvent 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 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(-) -- 2.17.2 (Apple Git-113) 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; -// 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); static void with_iothread_lock(CodeBlock block) { @@ -144,6 +145,21 @@ static void with_iothread_lock(CodeBlock block) } } +static bool bool_with_iothread_lock(BoolCodeBlock block) +{ + bool locked = qemu_mutex_iothread_locked(); + bool val; + + if (!locked) { + qemu_mutex_lock_iothread(); + } + val = block(); + if (!locked) { + qemu_mutex_unlock_iothread(); + } + return val; +} + // Mac to QKeyCode conversion const int mac_to_qkeycode_map[] = { [kVK_ANSI_A] = 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 } } -- (void) handleEvent:(NSEvent *)event +- (bool) handleEvent:(NSEvent *)event { - with_iothread_lock(^{ - [self handleEventLocked:event]; + return bool_with_iothread_lock(^{ + return [self handleEventLocked:event]; }); } -- (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 = 0; int keycode = 0; @@ -743,8 +760,7 @@ - (void) handleEventLocked:(NSEvent *)event if (keycode == Q_KEY_CODE_F) { switched_to_fullscreen = true; } - [NSApp sendEvent:event]; - return; + return false; } // 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; // 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] & NSEventModifierFlagCommand)) { - return; + return true; } if (qemu_console_is_graphic(NULL)) { @@ -875,7 +891,7 @@ - (void) handleEventLocked:(NSEvent *)event mouse_event = false; break; default: - [NSApp sendEvent:event]; + return false; } if (mouse_event) { @@ -911,10 +927,11 @@ - (void) handleEventLocked:(NSEvent *)event qemu_input_queue_rel(dcl->con, INPUT_AXIS_Y, (int)[event deltaY]); } } else { - [NSApp sendEvent:event]; + return false; } qemu_input_event_sync(); } + return true; } - (void) grabMouse @@ -1753,7 +1770,9 @@ static void cocoa_refresh(DisplayChangeListener *dcl) event = [NSApp nextEventMatchingMask:NSEventMaskAny untilDate:distantPast inMode: NSDefaultRunLoopMode dequeue:YES]; if (event != nil) { - [cocoaView handleEvent:event]; + if (![cocoaView handleEvent:event]) { + [NSApp sendEvent:event]; + } } } while(event != nil); [pool release];