From patchwork Mon Jul 11 22:20:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Programmingkid X-Patchwork-Id: 647134 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rpKLv3srDz9sDk for ; Tue, 12 Jul 2016 08:21:27 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=wet/zapm; dkim-atps=neutral Received: from localhost ([::1]:36249 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMjZs-0001gp-LI for incoming@patchwork.ozlabs.org; Mon, 11 Jul 2016 18:21:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55412) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMjZD-0000ba-Ly for qemu-devel@nongnu.org; Mon, 11 Jul 2016 18:20:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bMjZ8-0004oi-JD for qemu-devel@nongnu.org; Mon, 11 Jul 2016 18:20:42 -0400 Received: from mail-io0-x243.google.com ([2607:f8b0:4001:c06::243]:34413) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bMjZ8-0004oX-BU for qemu-devel@nongnu.org; Mon, 11 Jul 2016 18:20:38 -0400 Received: by mail-io0-x243.google.com with SMTP id g86so46246ioj.1 for ; Mon, 11 Jul 2016 15:20:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:content-transfer-encoding:subject:date:message-id:cc:to :mime-version; bh=EWPFrM1VSilV6G29aip5AcB9S3ehDlu4cpEsI4JdvWA=; b=wet/zapmlMSHHOhBGE1hs7KSOluqmIhF0B8yvazUw7ulh7pttl4iyPJJfGKNdqNS5G hETBGzvJagbBb+1mQH4KO2RR7p6Ocov+lo+08QdtBrtV8KlqqBn6FrkmeQLges2W8SCS hNyh/3NJmNV7so0/dgOM+k64ix1cyf7zNW1NX+BCdBg3vEtvYRI0VfvUrL1xJG4avTMg NIBIw5WEYgRZ02ulb7M50kV9CVEZ7q5oeol+AmxE8opjF0FyyLvzULEccrP/y3i5n+kx OeRZk1Zcc58JcFnfS3DKu4uNs4J8Lj1oEz21wMDtCV4iiaTsEpsqyHn5l6PO3ib45QXb YVSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:content-transfer-encoding:subject:date :message-id:cc:to:mime-version; bh=EWPFrM1VSilV6G29aip5AcB9S3ehDlu4cpEsI4JdvWA=; b=XEBIc3Ei1aKFIXRwiY+CLgfXnRawR/BWkwQqVM537/TyZIIuirTvbtDKvr/+S1G1OA W+QLgFLaAa+XXIniqbAPrmpjdS+TgdHF2k3KH6gN8aIHXejc1IDCPcu5zmDcjL026auG CFKsuq7VYS0v5hRrh8jIDH++R7MPziY5kFb+DLddxLOZeBiMq2fPdUu8McMhimpu+6bz taH8HwoE40RGEM5nth+sj9jXHn9xtjinvoxR4qwQw78MPRjQsVGZHisM+rSEGUjjMvlR vPh7WFpilxQaho5HcGqNVEkmqbsghBabnjkh8uDOTDXvieuMl00B810Q7cvVrw9SL11r RFGA== X-Gm-Message-State: ALyK8tJrAD0tg6ic7BAQlIl/LKkoGZIjD3VLPCxo+3W3zfbd4o5j5cmOh0x4gbXAASEKhA== X-Received: by 10.107.200.212 with SMTP id y203mr8655903iof.187.1468275637843; Mon, 11 Jul 2016 15:20:37 -0700 (PDT) Received: from [192.168.0.8] (d199-74-164-53.col.wideopenwest.com. [74.199.53.164]) by smtp.gmail.com with ESMTPSA id f9sm7033697ioi.2.2016.07.11.15.20.36 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 11 Jul 2016 15:20:36 -0700 (PDT) From: Programmingkid Date: Mon, 11 Jul 2016 18:20:35 -0400 Message-Id: To: qemu-devel qemu-devel Mime-Version: 1.0 (Apple Message framework v1084) X-Mailer: Apple Mail (2.1084) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4001:c06::243 Subject: [Qemu-devel] [PATCH] Add support for a Send Key menu. 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: Peter Maydell Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Add a menu called "Send Key". It is populated with options the user supplies at runtime. The option works like this: -sendkeymenu :<key values>. The title can be anything you want. The values are the hexadecimal values for the keycodes. The title is added to the menu as an menu item. The keycodes are sent to QEMU. Example: -sendkeymenu Command-Option-Esc:0x37,0x3a,0x35:Command-Power:0x37,0x7f7f Two menu items would be added to the "Send Key" menu with this example. This feature could be used to send Control-Alt-Delete to a Windows guest. It can also be used to send Command-Power keys to a Mac OS 9 guest to display Macsbugs. The user can decide what menu items to place in this menu. If the user doesn't use this feature the "Send Key" menu is not displayed. Signed-off-by: John Arbuckle <programmingkidx@gmail.com> --- ui/cocoa.m | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) diff --git a/ui/cocoa.m b/ui/cocoa.m index 36c6bf0..9fa9cc5 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -824,6 +824,7 @@ QemuCocoaView *cocoaView; - (void)changeDeviceMedia:(id)sender; - (BOOL)verifyQuit; - (void)openDocumentation:(NSString *)filename; +- (IBAction)do_send_key_menu_item:(id)sender; @end @implementation QemuCocoaAppController @@ -1138,8 +1139,110 @@ QemuCocoaView *cocoaView; } } +/* The action method to the items in the Send Keys menu */ +- (IBAction)do_send_key_menu_item:(id)sender { + NSString *keys = [sender representedObject]; + NSArray *key_array = [keys componentsSeparatedByString: @","]; + #define array_size 0xff + int keydown_array[array_size] = {0}; + int index, keycode; + NSString *hex_string; + + for (index = 0; index < [key_array count]; index++) { + hex_string = [key_array objectAtIndex: index]; + sscanf([hex_string cStringUsingEncoding: NSASCIIStringEncoding], "%x", + &keycode); + keycode = cocoa_keycode_to_qemu(keycode); + qemu_input_event_send_key_qcode(dcl->con, keycode, true); + keydown_array[keycode] = 1; + } + + /* Send keyup event for all keys that were sent */ + for (index = 0; index < array_size; index++) { + if (keydown_array[index] != 0) { + qemu_input_event_send_key_qcode(dcl->con, index, false); + } + } +} + @end +/* Determines if '-sendkeymenu' is in the arguments sent to QEMU */ +static int send_key_support(void) { + int index; + for (index = 0; index < gArgc; index++) { + if (strcmp("-sendkeymenu", gArgv[index]) == 0) { + return true; + } + } + return false; +} + +/* Remove one of the options from the global variable gArgv */ +static void remove_option(int index) +{ + if (index < 0) { + printf("Error: remove_option(): index less than zero: %d\n", index); + return; + } else if (index >= gArgc) { + printf("Error: remove_option(): index too big: %d\n", index); + return; + } + gArgc--; + /* copy everything from index + 1 to the end */ + for (; index < gArgc; index++) { + gArgv[index] = gArgv[index+1]; + } +} + +/* Creates the Send Key menu and populates it */ +static void create_send_key_menu(void) { + NSMenu *menu; + menu = [[NSMenu alloc] initWithTitle:@"Send Key"]; + + /* Find the index of the sendkeymenu and its items */ + int send_key_index = -1; + int index; + for (index = 0; index < gArgc; index++) { + if (strcmp("-sendkeymenu", gArgv[index]) == 0) { + send_key_index = index; + break; + } + } + + /* if failed to find the -sendkeymenu argument */ + if (send_key_index == -1) { + printf("Failed to find 'sendkeymenu' arguments\n"); + exit(EXIT_FAILURE); + } + + NSMenuItem *menu_item; + char *token; + token = strtok(gArgv[send_key_index+1], ":"); + + /* loop thru each set of keys */ + while (token) { + menu_item = [[[NSMenuItem alloc] initWithTitle: [NSString stringWithCString: token encoding:NSASCIIStringEncoding] + action: @selector(do_send_key_menu_item:) + keyEquivalent: @""] autorelease]; + [menu addItem: menu_item]; + token = strtok(NULL, ":"); + + [menu_item setRepresentedObject: [NSString stringWithCString: token encoding: NSASCIIStringEncoding]]; + token = strtok(NULL, ":"); + } + + /* Add the menu to QEMU's menubar */ + menu_item = [[[NSMenuItem alloc] initWithTitle: @"Send Key" + action:nil + keyEquivalent:@""] autorelease]; + [menu_item setSubmenu:menu]; + [[NSApp mainMenu] addItem:menu_item]; + + /* Remove the -sendkeymenu and related options from the global variable */ + remove_option(send_key_index); + remove_option(send_key_index); +} int main (int argc, const char * argv[]) { @@ -1212,6 +1315,11 @@ int main (int argc, const char * argv[]) { [menuItem setSubmenu:menu]; [[NSApp mainMenu] addItem:menuItem]; + // Send Key menu + if (send_key_support()) { + create_send_key_menu(); + } + // View menu menu = [[NSMenu alloc] initWithTitle:@"View"]; [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Enter Fullscreen" action:@selector(doToggleFullScreen:) keyEquivalent:@"f"] autorelease]]; // Fullscreen