From nobody Fri May 3 22:02:41 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 1512936181318625.5067500442959; Sun, 10 Dec 2017 12:03:01 -0800 (PST) Received: from localhost ([::1]:49580 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eO7oP-00053c-Ci for importer@patchew.org; Sun, 10 Dec 2017 15:02:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40534) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eO7lR-0002s0-SY for qemu-devel@nongnu.org; Sun, 10 Dec 2017 14:59:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eO7lN-00080h-HZ for qemu-devel@nongnu.org; Sun, 10 Dec 2017 14:59:53 -0500 Received: from mail-it0-x242.google.com ([2607:f8b0:4001:c0b::242]:42257) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eO7lN-00080M-Ax for qemu-devel@nongnu.org; Sun, 10 Dec 2017 14:59:49 -0500 Received: by mail-it0-x242.google.com with SMTP id p139so11352129itb.1 for ; Sun, 10 Dec 2017 11:59:49 -0800 (PST) Received: from localhost.localdomain (d14-69-20-184.try.wideopenwest.com. [69.14.184.20]) by smtp.gmail.com with ESMTPSA id l12sm38823iog.69.2017.12.10.11.59.47 (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 10 Dec 2017 11:59:47 -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=M3ujG7Wr0dRiPfm3h4u1q+OgkeMUZRVtB3HySCYJHmI=; b=RjHnc+Eij0sXydhl76S5P91/CGr2RdAVIrc8TGM1Z/C5jkyEStlBZvoY/ftNtpM8sI VEi4hB++hN2oQ9HLLGDmtefSKEhnHwqppMuzXqCiVl2qaauoKxN42eG9x7t67PjHKoSi NK+26X4gXyMNnNOdIjTpj/mo152HGZ5qbernmWzruXldmlay3jAhz/5PGQB/CkGaAKhW 6gB9+MCf/oNBhDXHglZQN4T1f86OZ6NQe4Pz6MpuPiiFo2iI9sEBN5eVWsxHFz6tmsr5 276jPr9khdfQZbSI40b64Ut35cWLGmhUJrOKZMJmlnYUbHcwq1l99qxnmu9rkeZR5m7D LQPw== 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=M3ujG7Wr0dRiPfm3h4u1q+OgkeMUZRVtB3HySCYJHmI=; b=klAzWIMpanpe3Uq5zPOQ0GbNX0rPOWmF9PPcIXFc7hKN3WyZyaBolZyAfwUTAFF2fS 9If0rZhxYKC2fErBw6qTDN9+4Q8XYlThl7jMNMwrLbfj0aOvA77cgAj1rGt09wig9CzB Lc6fF2rwxG6fx1FPrbBNFxninrLjVNYRWGGF2pD0l0rWs0DPSpOxF/6wx33hhzsRkHEz PZ9+8KRPwtUw76DeSyZBkQTxe0Y5pdwHLPaat4qjEgkNhGqb+/X0/QRE9jIq+Ktvcr9B sjFAN5BW0WmWDeva1lrqqyj52LEsO8OrVfd2FYEwjIc4pHQv6dOsRcP8a5vqEkkJJgAf OcGw== X-Gm-Message-State: AKGB3mKq3JKcZeKRR4zD7mkllLXC+xbbrVggF23p4Zo1kkOyNfCQtXp6 Iv/O5FRjrchjFWctEC6CQx8= X-Google-Smtp-Source: AGs4zMYKdsatuUfMk4BdxI0ZDCjJdrXHqJACwPzP0mUcXd6mIEItINUC4IWmqDanAm1DCfw3Ztupcg== X-Received: by 10.36.46.1 with SMTP id i1mr13869963ita.62.1512935988534; Sun, 10 Dec 2017 11:59:48 -0800 (PST) From: John Arbuckle To: Peter Maydell , Gerd Hoffmann , qemu-devel@nongnu.org Date: Sun, 10 Dec 2017 14:59:31 -0500 Message-Id: <20171210195931.26042-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::242 Subject: [Qemu-devel] [PATCH] 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 --- qemu-options.hx | 2 ++ ui/cocoa.m | 20 ++++++++++++-- vl.c | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++= +++- 3 files changed, 104 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..58a606e8a3 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,85 @@ 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", + +#if 0 /* remove this once these function keys are defined */ + [Q_KEY_CODE_F16] =3D "f16", + [Q_KEY_CODE_F17] =3D "f17", + [Q_KEY_CODE_F18] =3D "f18", + [Q_KEY_CODE_F19] =3D "f19", + [Q_KEY_CODE_F20] =3D "f20", + [Q_KEY_CODE_F21] =3D "f21", + [Q_KEY_CODE_F22] =3D "f22", + [Q_KEY_CODE_F23] =3D "f23", + [Q_KEY_CODE_F24] =3D "f24", + [Q_KEY_CODE_FUNCTION] =3D "fn", +#endif + }; + + int key_value =3D -1; + + /* see if the user's key is recognized */ + for (int 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 (int 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 +4284,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)