From nobody Sun May 19 12:00:44 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 151433736210471.57215142904693; Tue, 26 Dec 2017 17:16:02 -0800 (PST) Received: from localhost ([::1]:37402 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eU0Jv-0006Hr-QW for importer@patchew.org; Tue, 26 Dec 2017 20:15:47 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53695) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eU0Ix-0005qH-JG for qemu-devel@nongnu.org; Tue, 26 Dec 2017 20:14:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eU0Iu-0007V3-CD for qemu-devel@nongnu.org; Tue, 26 Dec 2017 20:14:47 -0500 Received: from mail-it0-x242.google.com ([2607:f8b0:4001:c0b::242]:33534) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eU0Iu-0007UL-5N for qemu-devel@nongnu.org; Tue, 26 Dec 2017 20:14:44 -0500 Received: by mail-it0-x242.google.com with SMTP id o130so26500617itg.0 for ; Tue, 26 Dec 2017 17:14:44 -0800 (PST) Received: from localhost.localdomain (d14-69-20-184.try.wideopenwest.com. [69.14.184.20]) by smtp.gmail.com with ESMTPSA id c196sm16994997ioc.55.2017.12.26.17.14.42 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 26 Dec 2017 17:14:42 -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=CyKoW9ePNA0LCpmVB0TMmBBY7FiW9xvM6FsbXif7Rps=; b=a+Rv9lbAeyQStX1zL/Yf8kARLgQn0R0PGQ2V5OlF2cwxisuuAbYivkPqZLPES4R8bL VEos8z4Fe/rTpCFGI04cOursfYxieu1cBB9vb3d6px/uuOlMmaGIWozseDusEgeDPpRF iQ/IwaHs5n6WSKlaiYoP9SAG96HI73gnRk1wo6Vzta+mUI9UMskO16WudvSqbl6x/FZ+ 33kOtZA+NcVCkM+rzijFVQadP8GydSf+1NR5tWHZdqpiQJ8xhQxGZYDvnPczR7qIs+Lk 5QX23uX86/Gvad6G3nanUAcUzx9ZQ1EumfRBgkn/o8jdjXDRgbuijH4zwV2ctvLGk94J T1Gg== 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=CyKoW9ePNA0LCpmVB0TMmBBY7FiW9xvM6FsbXif7Rps=; b=taf5Lq80KEUHJxLpzxDqm++G7P0HL6wQc/nJrH2uJTH91cHF3VwKKEKatRgWEc0CnV SAGnbcEOM19eORUuv/6vdqhR1vXEtny6OI9ALpyyicV7PABXG+SqjwasbSQ6xzaQj4Cn Dn6YrsRbNxaZCcx56hTUM7QPiYjntTmWAkrQAAJcs+M3aqQZIjtIkad3fgpBdWVh+57j XW2icCSqys3CjuM83W1hCnvMyhy9k6qLMJF2l4B1+sItTzmjZg7lyCh78APUS21g4qlt Qj69Xk1TNkuSh+YEn6HFOsuqLrPdJiY29meR6WqMDV78WK9iOfpre9GHcowkq6JadrMH ozeg== X-Gm-Message-State: AKGB3mLeLuwV9gclV0uWeE1Y+Tprj+OAWCgJP8ghupi+pWjwlfe406/V oS8aGf3W+xHddbkpQXJep50= X-Google-Smtp-Source: ACJfBotz8rfUkzKgtlYJrJDEq5o5/QGjoMqrC3JRIHgN0heKv9q1Dd8msyUUUZ9ZBpsU987A3gPdAg== X-Received: by 10.36.221.216 with SMTP id t207mr34560899itf.112.1514337283498; Tue, 26 Dec 2017 17:14:43 -0800 (PST) From: John Arbuckle To: peter.maydell@linaro.org, kraxel@redhat.com, qemu-devel@nongnu.org, berrange@redhat.com Date: Tue, 26 Dec 2017 20:14:28 -0500 Message-Id: <20171227011428.40996-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 v4] 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(s) as the ungrab key(s). The list of keys that can be used is found in the file qapi/ui.json under QKeyC= ode. The max number of keys that can be used is three. The original ungrab keys still remain usable because there is a real risk of the user forgetting=20 the keys he or she specified as the ungrab keys. They remain as a plan B if plan A is forgotten. Syntax: -ungrab Example usage: -ungrab home -ungrab shift-ctrl -ungrab ctrl-x -ungrab pgup-pgdn -ungrab kp_5-kp_6 -ungrab kp_4-kp_5-kp_6 Signed-off-by: John Arbuckle --- v4 changes: - Removed initialization code for key_value_array. - Added void keyword to console_ungrab_key_sequence(), and console_ungrab_key_string() functions. v3 changes: - Added the ability for any "sendkey supported" key to be used. - Added ability for one to three key sequences to be used. v2 changes: - Removed the "int i" code from the for loops.=20 include/ui/console.h | 6 ++++++ qemu-options.hx | 2 ++ ui/cocoa.m | 48 +++++++++++++++++++++++++++++++++++++++-- ui/console.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++= ++++ vl.c | 3 +++ 5 files changed, 117 insertions(+), 2 deletions(-) diff --git a/include/ui/console.h b/include/ui/console.h index 580dfc57ee..37dc150268 100644 --- a/include/ui/console.h +++ b/include/ui/console.h @@ -534,4 +534,10 @@ static inline void early_gtk_display_init(int opengl) /* egl-headless.c */ void egl_headless_init(void); =20 +/* console.c */ +void set_ungrab_seq(const char *new_seq); +int *console_ungrab_key_sequence(void); +const char *console_ungrab_key_string(void); +int console_ungrab_sequence_length(void); + #endif diff --git a/qemu-options.hx b/qemu-options.hx index 94647e21e3..51666e6f74 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4264,6 +4264,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..412a5fc02d 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -303,6 +303,7 @@ - (float) cdx; - (float) cdy; - (QEMUScreen) gscreen; - (void) raiseAllKeys; +- (bool) user_ungrab_seq; @end =20 QemuCocoaView *cocoaView; @@ -674,9 +675,24 @@ - (void) handleEvent:(NSEvent *)event } } =20 + /* + * This code has to be here because the user might use a modif= ier + * key like shift as an ungrab key. + */ + if ([self user_ungrab_seq] =3D=3D true) { + [self ungrabMouse]; + return; + } break; case NSEventTypeKeyDown: keycode =3D cocoa_keycode_to_qemu([event keyCode]); + [self toggleModifier: keycode]; + + // If the user is issuing the custom ungrab key sequence + if ([self user_ungrab_seq] =3D=3D true) { + [self ungrabMouse]; + return; + } =20 // forward command key combos to the host UI unless the mouse = is grabbed if (!isMouseGrabbed && ([event modifierFlags] & NSEventModifie= rFlagCommand)) { @@ -714,6 +730,7 @@ - (void) handleEvent:(NSEvent *)event break; case NSEventTypeKeyUp: keycode =3D cocoa_keycode_to_qemu([event keyCode]); + [self toggleModifier: keycode]; =20 // don't pass the guest a spurious key-up if we treated this // command-key combo as a host UI action @@ -842,10 +859,18 @@ - (void) grabMouse COCOA_DEBUG("QemuCocoaView: grabMouse\n"); =20 if (!isFullscreen) { + NSString * message_string; + if (console_ungrab_sequence_length() =3D=3D 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", console_ungrab_key_string()]; + } + + 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) { @@ -898,6 +923,25 @@ - (void) raiseAllKeys } } } + +/* Determines if the user specified ungrab sequence is being used */ +- (bool) user_ungrab_seq +{ + int *ungrab_seq, index, length; + bool return_value =3D true; + + ungrab_seq =3D console_ungrab_key_sequence(); + length =3D console_ungrab_sequence_length(); + + for (index =3D 0; index < length; index++) { + if (modifiers_state[ungrab_seq[index]] =3D=3D NO) { + return_value =3D false; + break; + } + } + return return_value; +} + @end =20 =20 diff --git a/ui/console.c b/ui/console.c index c4c95abed7..895bc3fb17 100644 --- a/ui/console.c +++ b/ui/console.c @@ -63,6 +63,18 @@ typedef struct QEMUFIFO { int count, wptr, rptr; } QEMUFIFO; =20 +/* max number of user specified keys that can be used as the ungrab keys*/ +static const int max_keys =3D 3; + +/* stores the ungrab keys' values */ +static int key_value_array[max_keys + 1]; + +/* stores the length the user's ungrab sequence */ +int ungrab_seq_length; + +/* stores the string that is returned by console_ungrab_key_string */ +static char *ungrab_key_string; + static int qemu_fifo_write(QEMUFIFO *f, const uint8_t *buf, int len1) { int l, len; @@ -2239,4 +2251,52 @@ static void register_types(void) type_register_static(&qemu_console_info); } =20 +/* Sets the mouse ungrab key sequence to what the user wants */ +void set_ungrab_seq(const char *new_seq) +{ + char *buffer1 =3D (char *) malloc(strlen(new_seq) * sizeof(char)); + char *buffer2 =3D (char *) malloc(strlen(new_seq) * sizeof(char)); + int count =3D 0; + int key_value; + char *token; + const char *separator =3D "-"; /* What the user places between keys */ + + sprintf(buffer1, "%s", new_seq); /* edited by strtok */ + sprintf(buffer2, "%s", new_seq); /* used for ungrab_key_string */ + ungrab_key_string =3D buffer2; + + token =3D strtok(buffer1, separator); + while (token !=3D NULL && count < max_keys) { + /* Translate the names into Q_KEY_CODE values */ + key_value =3D index_from_key(token, strlen(token)); + if (key_value =3D=3D Q_KEY_CODE__MAX) { + printf("-ungrab: unknown key: %s\n", token); + exit(EXIT_FAILURE); + } + key_value_array[count] =3D key_value; + + count++; + token =3D strtok(NULL, separator); + } + ungrab_seq_length =3D count; +} + +/* Returns the user specified ungrab key sequence */ +int *console_ungrab_key_sequence(void) +{ + return key_value_array; +} + +/* Returns the name of the user specified ungrab keys */ +const char *console_ungrab_key_string(void) +{ + return ungrab_key_string; +} + +/* indicates how many keys the user ungrab sequence is */ +int console_ungrab_sequence_length(void) +{ + return ungrab_seq_length; +} + type_init(register_types); diff --git a/vl.c b/vl.c index d3a5c5d021..86203344eb 100644 --- a/vl.c +++ b/vl.c @@ -4155,6 +4155,9 @@ int main(int argc, char **argv, char **envp) exit(1); } break; + case QEMU_OPTION_ungrab: + set_ungrab_seq(optarg); + break; default: os_parse_cmd_args(popt->index, optarg); } --=20 2.14.3 (Apple Git-98)