From patchwork Sun Dec 8 17:30:34 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 22142 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C871523FDD for ; Sun, 8 Dec 2013 17:30:38 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id e14sf10669882iej.0 for ; Sun, 08 Dec 2013 09:30:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=i7pzpe2SD8Ek+9ah3MdN7ROl+obJshpLV8jLLSHC1Z8=; b=AiWsthnh91s1ylbK5vTVeqLVwwjMesX9iLIWS3yV/s1K2OHaaqpmuD0GhyNQZ0UIuI X/kHZcJzB1kuOvCwKWyHq1Dz/M3qZRpG4UkGKEkcrh6UbrLHx3JIA6I9wRNI88r66dSW /MQxhT15R78TT1eRAyFr4KXCfEa2dUBJOceKG3OcEjyBB9GMa/U5RkGBDqckt0Rf8ONl cyFCL+ozMf9velKH080yEQp2pwzoxtHUStsAQTzWjuJdwsoUZqBZYKgndwDUEqNzoOXn KhH+vN5PFpz6Kra1xQwOFjRxAlAWrgTuTUXzU5HjQeL1WpbaHHhZf5xuE7ybOzB9PTRl PEpg== X-Gm-Message-State: ALoCoQnkU5Nq78QjDv6b675YaEon+795QAQa7jM/CTVpYULSw4IdEGQwDmqeWVHzWdjVsfxeszf6 X-Received: by 10.50.61.242 with SMTP id t18mr4920172igr.3.1386523837731; Sun, 08 Dec 2013 09:30:37 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.38.36 with SMTP id d4ls1818979qek.7.gmail; Sun, 08 Dec 2013 09:30:37 -0800 (PST) X-Received: by 10.220.194.133 with SMTP id dy5mr9179560vcb.3.1386523837583; Sun, 08 Dec 2013 09:30:37 -0800 (PST) Received: from mail-ve0-f169.google.com (mail-ve0-f169.google.com [209.85.128.169]) by mx.google.com with ESMTPS id a15si2632657vew.83.2013.12.08.09.30.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 08 Dec 2013 09:30:37 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.169; Received: by mail-ve0-f169.google.com with SMTP id c14so2896670vea.28 for ; Sun, 08 Dec 2013 09:30:37 -0800 (PST) X-Received: by 10.220.186.202 with SMTP id ct10mr9290478vcb.14.1386523837041; Sun, 08 Dec 2013 09:30:37 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.174.196 with SMTP id u4csp53585vcz; Sun, 8 Dec 2013 09:30:36 -0800 (PST) X-Received: by 10.180.9.74 with SMTP id x10mr10659008wia.56.1386523836053; Sun, 08 Dec 2013 09:30:36 -0800 (PST) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id kb10si2941916wjc.152.2013.12.08.09.30.35 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 08 Dec 2013 09:30:35 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1VpiBe-0008FT-2E; Sun, 08 Dec 2013 17:30:34 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, John Arbuckle , =?UTF-8?q?Andreas=20F=C3=A4rber?= , qemu-ppc@nongnu.org Subject: [PATCH] ui/cocoa: Pass command key through to guest when VM has mousegrab Date: Sun, 8 Dec 2013 17:30:34 +0000 Message-Id: <1386523834-31682-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.169 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The guest might want to be able to use the command key for its won purposes (as command if it is MacOS X, or for the Windows key if it is a PC guest, for instance). In line with other UI frontends, pass it through if the guest has mousegrab, and only use it for host UI menu accelerators if not grabbed. Thanks to John Arbuckle for reporting this problem, helping us work through what the best solution would be and providing a patch which was the initial inspiration for this one. Reported-by: John Arbuckle Signed-off-by: Peter Maydell --- John -- my apologies for having let this issue (and your patch http://patchwork.ozlabs.org/patch/267627/ ) lie around unaddressed/unreviewed for such a long time. I finally got some time to look at the problem, and I think this patch should fix the problem of Mac guests not getting the command key (and also of Windows guests not getting Windows keys, since they're the same scancode). Tested with an x86/Linux guest and "showkeys" to confirm that when mousegrab is enabled the command keys are passed through. ui/cocoa.m | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index be49179..d38cf22 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -129,8 +129,8 @@ int keymap[] = 14, // 51 0x33 0x0e BKSP QZ_BACKSPACE 0, // 52 0x34 Undefined 1, // 53 0x35 0x01 ESC QZ_ESCAPE - 0, // 54 0x36 QZ_RMETA - 0, // 55 0x37 QZ_LMETA + 220, // 54 0x36 0xdc E0,5C R GUI QZ_RMETA + 219, // 55 0x37 0xdb E0,5B L GUI QZ_LMETA 42, // 56 0x38 0x2a L SHFT QZ_LSHIFT 58, // 57 0x39 0x3a CAPS QZ_CAPSLOCK 56, // 58 0x3A 0x38 L ALT QZ_LALT @@ -206,8 +206,6 @@ int keymap[] = /* Aditional 104 Key XP-Keyboard Scancodes from http://www.computer-engineering.org/ps2keyboard/scancodes1.html */ /* - 219 // 0xdb e0,5b L GUI - 220 // 0xdc e0,5c R GUI 221 // 0xdd e0,5d APPS // E0,2A,E0,37 PRNT SCRN // E1,1D,45,E1,9D,C5 PAUSE @@ -494,6 +492,12 @@ QemuCocoaView *cocoaView; switch ([event type]) { case NSFlagsChanged: keycode = cocoa_keycode_to_qemu([event keyCode]); + + if ((keycode == 219 || keycode == 220) && !isMouseGrabed) { + /* Don't pass command key changes to guest unless mouse is grabbed */ + keycode = 0; + } + if (keycode) { if (keycode == 58 || keycode == 69) { // emulate caps lock and num lock keydown and keyup kbd_put_keycode(keycode); @@ -517,15 +521,15 @@ QemuCocoaView *cocoaView; } break; case NSKeyDown: + keycode = cocoa_keycode_to_qemu([event keyCode]); - // forward command Key Combos - if ([event modifierFlags] & NSCommandKeyMask) { + // forward command key combos to the host UI unless the mouse is grabbed + if (!isMouseGrabed && ([event modifierFlags] & NSCommandKeyMask)) { [NSApp sendEvent:event]; return; } // default - keycode = cocoa_keycode_to_qemu([event keyCode]); // handle control + alt Key Combos (ctrl+alt is reserved for QEMU) if (([event modifierFlags] & NSControlKeyMask) && ([event modifierFlags] & NSAlternateKeyMask)) { @@ -581,6 +585,13 @@ QemuCocoaView *cocoaView; break; case NSKeyUp: keycode = cocoa_keycode_to_qemu([event keyCode]); + + // don't pass the guest a spurious key-up if we treated this + // command-key combo as a host UI action + if (!isMouseGrabed && ([event modifierFlags] & NSCommandKeyMask)) { + return; + } + if (qemu_console_is_graphic(NULL)) { if (keycode & 0x80) kbd_put_keycode(0xe0);