From nobody Thu Apr 18 02:31:04 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151326238757889.20706062372733; Thu, 14 Dec 2017 06:39:47 -0800 (PST) Received: from localhost ([::1]:41295 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePUfm-0004w0-Ry for importer@patchew.org; Thu, 14 Dec 2017 09:39:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45477) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ePUdd-0003Wv-EJ for qemu-devel@nongnu.org; Thu, 14 Dec 2017 09:37:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ePUdZ-00019m-Ct for qemu-devel@nongnu.org; Thu, 14 Dec 2017 09:37:29 -0500 Received: from mail-it0-x241.google.com ([2607:f8b0:4001:c0b::241]:40414) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ePUdZ-000199-6Q for qemu-devel@nongnu.org; Thu, 14 Dec 2017 09:37:25 -0500 Received: by mail-it0-x241.google.com with SMTP id f190so11520730ita.5 for ; Thu, 14 Dec 2017 06:37:25 -0800 (PST) Received: from localhost.localdomain (d14-69-20-184.try.wideopenwest.com. [69.14.184.20]) by smtp.gmail.com with ESMTPSA id v65sm2663834itb.30.2017.12.14.06.37.23 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 14 Dec 2017 06:37:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=N804S14Yc3kiyY3AGv+96wUZdchQEnx2Ot0B3LwFcNo=; b=nuTU58fFzzVcKx3J+DwSoerNKZpmihuPy/h+VECQn14NMb7B/nwTjsWk7i8orRI9zC j8c8hPEltmXia1afv3twQQZWwK+HecIHccX20gHw7cpWk14AKPf5o8p1BvsAsBWmksye DrQFujIvwUq3dhqR9NehX/3h8/NlbPs4mXoMe94LayE0WImsvnaMuDmDDLEfo3KQNw3/ awfaepfNOcTA9asBchSvVNh3NjWzpU7AmrKe+6cFxkPkQaYGAcAUb1fith0CVw+I7LGx sqiTuxk4CVEhPTqGuBVVM7WSZkZGmkptVkWg9N3FEHDj5EQKcP6biv2TTc3gnFGFdTXl 7tOg== 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=N804S14Yc3kiyY3AGv+96wUZdchQEnx2Ot0B3LwFcNo=; b=pG0Gt965yECPCgvhxxQnU/PQq2MTkfmVwJeJqmA70GGdFTFZTTnm7rWoyxjn3Ost4d 7fsvuSem3Oae65Kw/628nLFmneW1sq30Sj0qlLFNu7IA4ppyx347bNI27wZKUy9uvA3z mw5nbqDAP5ioOQWf5B3Ik0XZwkTgrBfy6s3U314ijyJLsd1UKN1gS+YBzsZhaYqhj/sr t8FzyxZ/lTa3b/eOub7GVZb9+1LOy/f/0eJp9jCOcyYA66SvuJjxqZR9TVNX59nDrEG/ 3wJ+FN6jycWLAVvZLD0NU6APRNZaZUZflhO5vFDhX65c++KD44y67rbZOV3yZMc4CJNg /7sw== X-Gm-Message-State: AKGB3mK1SYDYVSmnzpMopYYJ81M35V0hmxLrFZMckz4sMDOLcE/MQoZw V6RubRLvo5F6+YhDNH1NhpbtJQ== X-Google-Smtp-Source: ACJfBotpZzvuf/WO8SoQVjP2bm+7xVTe46q6UXNEoc5JpB8WqVSSfxEX7eNE2hvGUAU5oCQgAvgSpg== X-Received: by 10.36.22.147 with SMTP id a141mr3580583ita.30.1513262244225; Thu, 14 Dec 2017 06:37:24 -0800 (PST) From: John Arbuckle To: qemu-devel@nongnu.org, peter.maydell@linaro.org, kraxel@redhat.com Date: Thu, 14 Dec 2017 09:37:13 -0500 Message-Id: <20171214143713.3795-1-programmingkidx@gmail.com> X-Mailer: git-send-email 2.14.3 (Apple Git-98) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4001:c0b::241 Subject: [Qemu-devel] [PATCH v2] Add ability for user to specify mouse ungrab key 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Currently the ungrab keys for the Cocoa and GTK interface are Control-Alt-g. This combination may not be very fun for the user to have to enter, so we now enable the user to specify their own key as the ungrab key. Since the=20 function keys are the keys that don't tend to be used that often and are usually available, they will be the ones the user can pick to be the ungrab key. Signed-off-by: John Arbuckle --- v2 changes: - Removed the "int i" code from the for loops.=20 qemu-options.hx | 2 ++ ui/cocoa.m | 20 ++++++++++++++-- vl.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++= +++- 3 files changed, 92 insertions(+), 3 deletions(-) diff --git a/qemu-options.hx b/qemu-options.hx index f11c4ac960..0a727ea50a 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4472,6 +4472,8 @@ contents of @code{iv.b64} to the second secret =20 ETEXI =20 +DEF("ungrab", HAS_ARG, QEMU_OPTION_ungrab, \ + "-ungrab ", QEMU_ARCH_ALL) =20 HXCOMM This is the last statement. Insert new options before this line! STEXI diff --git a/ui/cocoa.m b/ui/cocoa.m index 330ccebf90..8dc603adf0 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -106,6 +106,9 @@ NSTextField *pauseLabel; NSArray * supportedImageFileTypes; =20 +int get_ungrab_key_value(void); +const char * get_ungrab_key_name(void); + // Mac to QKeyCode conversion const int mac_to_qkeycode_map[] =3D { [kVK_ANSI_A] =3D Q_KEY_CODE_A, @@ -678,6 +681,12 @@ - (void) handleEvent:(NSEvent *)event case NSEventTypeKeyDown: keycode =3D cocoa_keycode_to_qemu([event keyCode]); =20 + // if the user wants to release the mouse grab + if (keycode =3D=3D get_ungrab_key_value()) { + [self ungrabMouse]; + return; + } + // forward command key combos to the host UI unless the mouse = is grabbed if (!isMouseGrabbed && ([event modifierFlags] & NSEventModifie= rFlagCommand)) { [NSApp sendEvent:event]; @@ -842,10 +851,17 @@ - (void) grabMouse COCOA_DEBUG("QemuCocoaView: grabMouse\n"); =20 if (!isFullscreen) { + NSString * message_string; + if (get_ungrab_key_value() < 0) { + message_string =3D [NSString stringWithFormat: @"- (Press ctrl= + alt + g to release Mouse"]; + } else { + message_string =3D [NSString stringWithFormat: @"- (Press ctrl= + alt + g or %s to release Mouse", get_ungrab_key_name()]; + } + if (qemu_name) - [normalWindow setTitle:[NSString stringWithFormat:@"QEMU %s - = (Press ctrl + alt + g to release Mouse)", qemu_name]]; + [normalWindow setTitle:[NSString stringWithFormat: @"QEMU %s %= @", qemu_name, message_string]]; else - [normalWindow setTitle:@"QEMU - (Press ctrl + alt + g to relea= se Mouse)"]; + [normalWindow setTitle:[NSString stringWithFormat: @"QEMU %@",= message_string]]; } [self hideCursor]; if (!isAbsoluteEnabled) { diff --git a/vl.c b/vl.c index 1ad1c04637..c2d848fabc 100644 --- a/vl.c +++ b/vl.c @@ -185,7 +185,8 @@ bool boot_strict; uint8_t *boot_splash_filedata; size_t boot_splash_filedata_size; uint8_t qemu_extra_params_fw[2]; - +int ungrab_key_value =3D -1; +char *ungrab_key_name; int icount_align_option; =20 /* The bytes in qemu_uuid are in the order specified by RFC4122, _not_ in = the @@ -3088,6 +3089,73 @@ static void register_global_properties(MachineState = *ms) user_register_global_props(); } =20 +/* Sets the mouse ungrab key to what the user wants */ +static void set_ungrab_key(const char *new_key) +{ + const char *keys[] =3D { + [0 ... 0xff] =3D "", + [Q_KEY_CODE_F1] =3D "f1", + [Q_KEY_CODE_F2] =3D "f2", + [Q_KEY_CODE_F3] =3D "f3", + [Q_KEY_CODE_F4] =3D "f4", + [Q_KEY_CODE_F5] =3D "f5", + [Q_KEY_CODE_F6] =3D "f6", + [Q_KEY_CODE_F7] =3D "f7", + [Q_KEY_CODE_F8] =3D "f8", + [Q_KEY_CODE_F9] =3D "f9", + [Q_KEY_CODE_F10] =3D "f10", + [Q_KEY_CODE_F11] =3D "f11", + [Q_KEY_CODE_F12] =3D "f12", + [Q_KEY_CODE_PRINT] =3D "f13", + [Q_KEY_CODE_SCROLL_LOCK] =3D "f14", + [Q_KEY_CODE_PAUSE] =3D "f15", + }; + + int key_value =3D -1; + int i; + + /* see if the user's key is recognized */ + for (i =3D 0; i < ARRAY_SIZE(keys); i++) { + if (strcmp(keys[i], new_key) =3D=3D 0) { + key_value =3D i; + break; + } + } + + /* if the user's key isn't recognized print the usable keys */ + if (key_value =3D=3D -1) { + printf("Unrecognized key: %s\n", new_key); + printf("Usable ungrab keys: "); + for (i =3D 0; i < ARRAY_SIZE(keys); i++) { + if (strlen(keys[i]) > 0) { /* filters out undefined values */ + printf("%s ", keys[i]); + } + } + printf("\n\n"); + exit(1); + } + + ungrab_key_name =3D (char *) malloc(4 * sizeof(char)); + strncpy(ungrab_key_name, new_key, 3); + ungrab_key_value =3D key_value; +} + +int get_ungrab_key_value(void); + +/* Returns the user specified ungrab key's value or -1 if not specified */ +int get_ungrab_key_value(void) +{ + return ungrab_key_value; +} + +const char *get_ungrab_key_name(void); + +/* Returns the name of the user specified ungrab key */ +const char *get_ungrab_key_name(void) +{ + return ungrab_key_name; +} + int main(int argc, char **argv, char **envp) { int i; @@ -4204,6 +4272,9 @@ int main(int argc, char **argv, char **envp) exit(1); } break; + case QEMU_OPTION_ungrab: + set_ungrab_key(optarg); + break; default: os_parse_cmd_args(popt->index, optarg); } --=20 2.14.3 (Apple Git-98)