From nobody Mon Apr 29 15:35:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1647521844601579.2025978604803; Thu, 17 Mar 2022 05:57:24 -0700 (PDT) Received: from localhost ([::1]:46374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nUpgx-0003GB-Ie for importer@patchew.org; Thu, 17 Mar 2022 08:57:23 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40810) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nUpfU-0001KL-Sa for qemu-devel@nongnu.org; Thu, 17 Mar 2022 08:55:52 -0400 Received: from [2607:f8b0:4864:20::102c] (port=38635 helo=mail-pj1-x102c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nUpfT-0002Hp-6x for qemu-devel@nongnu.org; Thu, 17 Mar 2022 08:55:52 -0400 Received: by mail-pj1-x102c.google.com with SMTP id mm4-20020a17090b358400b001c68e836fa6so950322pjb.3 for ; Thu, 17 Mar 2022 05:55:50 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id d11-20020a056a0024cb00b004f725ecf900sm7169670pfv.97.2022.03.17.05.55.46 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 17 Mar 2022 05:55:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EV40ccb5NVkJ7QeeNSqB5ytxqShi3OnkSRljDHtQ9Yc=; b=Key3WV4oY0+qeo5pFocDcepkX/CqMAWEOXe8s9UPHWtp2XfYFq0gfBeZ5MOxYIJspM Px9NWJhRpmicqm192Nr1agpLD8NDw+N4pt/AJ63pcQkkHqB7YrXTcq5Ro4GpqXzgt2vT w+jD6IIv6MWiswDQxJdgmb2pbhGYcBj3iuULEruptB7S4PS2xUjzLIquZ6xJ9TGPzcEd 56jDp2mdfFgi/LS0wGnaSvbT2eNV8o4saqQqEz/4jRsUs8eURfpmJkeeWN4TTUh84P1V minNJKZOqIi23nMBxnE9qLqMp0RvhWLxBqZ3+QQpqG1Ub++j0QCsSdHDuvlKPeXvFvkl In4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EV40ccb5NVkJ7QeeNSqB5ytxqShi3OnkSRljDHtQ9Yc=; b=NYzaxQ/11Vcq5nMHgkw+kYLahyXkQEKDZcSsEj60MzYe7FzWrh364LyOcCBXfAnvi9 h9hJsYeUTR+12pqIeAbtA2m/OAWH5TUtbqDJ4ooGfnnwF6qSVtyJolGzQhsopwE/KgEI 8LRNsXK1in5qts1Jh6Ql+iWLxXPvFzzGfzTwjbWfCY+ThjBD26y00gK2D+NVKxyHqgwj +A3Di70wQdoPK+WL4nCXN+UTZzbMmTBp+O0CFuTYqpbb/yJ0WoicDZhD4+lcay/U5v4j +XPkUCUsA7Hbw+y+vLeF2in8lj/SWSUgClKrcuLbI0LVsZ0PnhBG3CTL6TmK0/s5/E/b /3SA== X-Gm-Message-State: AOAM533VrxE/Pf2iFzUCdKoDU1OBOjLUAWlIKQm2zT6ivOUJelqC/3J5 9e+a5sLPK7JcYTv5EtGqun4yb+18e9U= X-Google-Smtp-Source: ABdhPJzDRhkV4pUekD5o0t//kO+L2EVtU4TYIRfM1pZr0mTryXr2yPlzWcPlz0EGO7g1rlotKELdHw== X-Received: by 2002:a17:903:120c:b0:14f:3f4a:f832 with SMTP id l12-20020a170903120c00b0014f3f4af832mr4743832plh.157.1647521749554; Thu, 17 Mar 2022 05:55:49 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH-for-7.0 v4 1/2] ui/cocoa: Code movement Date: Thu, 17 Mar 2022 13:55:33 +0100 Message-Id: <20220317125534.38706-2-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220317125534.38706-1-philippe.mathieu.daude@gmail.com> References: <20220317125534.38706-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::102c (failed) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-pj1-x102c.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Emanuele Giuseppe Esposito , Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Akihiko Odaki , Paolo Bonzini , Kevin Wolf Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1647521845707100003 From: Philippe Mathieu-Daud=C3=A9 Pure code movement in preparation for the next commit. Reviewed-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- ui/cocoa.m | 86 +++++++++++++++++++++++++++--------------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index cb6e7c41dc..027c3053f7 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -75,6 +75,9 @@ typedef struct { int height; } QEMUScreen; =20 +@interface QemuCocoaPasteboardTypeOwner : NSObject +@end + static void cocoa_update(DisplayChangeListener *dcl, int x, int y, int w, int h); =20 @@ -109,6 +112,8 @@ static bool allow_events; =20 static NSInteger cbchangecount =3D -1; static QemuClipboardInfo *cbinfo; +static QemuClipboardPeer cbpeer; +static QemuCocoaPasteboardTypeOwner *cbowner; static QemuEvent cbevent; =20 // Utility functions to run specified code block with iothread lock held @@ -142,6 +147,44 @@ static bool bool_with_iothread_lock(BoolCodeBlock bloc= k) return val; } =20 +/* + * The startup process for the OSX/Cocoa UI is complicated, because + * OSX insists that the UI runs on the initial main thread, and so we + * need to start a second thread which runs the vl.c qemu_main(): + * + * Initial thread: 2nd thread: + * in main(): + * create qemu-main thread + * wait on display_init semaphore + * call qemu_main() + * ... + * in cocoa_display_init(): + * post the display_init semaphore + * wait on app_started semaphore + * create application, menus, etc + * enter OSX run loop + * in applicationDidFinishLaunching: + * post app_started semaphore + * tell main thread to fullscreen if n= eeded + * [...] + * run qemu main-loop + * + * We do this in two stages so that we don't do the creation of the + * GUI application menus and so on for command line options like --help + * where we want to just print text to stdout and exit immediately. + */ + +static void *call_qemu_main(void *opaque) +{ + int status; + + COCOA_DEBUG("Second thread: calling qemu_main()\n"); + status =3D qemu_main(gArgc, gArgv, *_NSGetEnviron()); + COCOA_DEBUG("Second thread: qemu_main() returned, exiting\n"); + [cbowner release]; + exit(status); +} + // Mac to QKeyCode conversion static const int mac_to_qkeycode_map[] =3D { [kVK_ANSI_A] =3D Q_KEY_CODE_A, @@ -1804,9 +1847,6 @@ static void addRemovableDevicesMenuItems(void) qapi_free_BlockInfoList(pointerToFree); } =20 -@interface QemuCocoaPasteboardTypeOwner : NSObject -@end - @implementation QemuCocoaPasteboardTypeOwner =20 - (void)pasteboard:(NSPasteboard *)sender provideDataForType:(NSPasteboard= Type)type @@ -1841,8 +1881,6 @@ static void addRemovableDevicesMenuItems(void) =20 @end =20 -static QemuCocoaPasteboardTypeOwner *cbowner; - static void cocoa_clipboard_notify(Notifier *notifier, void *data); static void cocoa_clipboard_request(QemuClipboardInfo *info, QemuClipboardType type); @@ -1903,44 +1941,6 @@ static void cocoa_clipboard_request(QemuClipboardInf= o *info, } } =20 -/* - * The startup process for the OSX/Cocoa UI is complicated, because - * OSX insists that the UI runs on the initial main thread, and so we - * need to start a second thread which runs the vl.c qemu_main(): - * - * Initial thread: 2nd thread: - * in main(): - * create qemu-main thread - * wait on display_init semaphore - * call qemu_main() - * ... - * in cocoa_display_init(): - * post the display_init semaphore - * wait on app_started semaphore - * create application, menus, etc - * enter OSX run loop - * in applicationDidFinishLaunching: - * post app_started semaphore - * tell main thread to fullscreen if n= eeded - * [...] - * run qemu main-loop - * - * We do this in two stages so that we don't do the creation of the - * GUI application menus and so on for command line options like --help - * where we want to just print text to stdout and exit immediately. - */ - -static void *call_qemu_main(void *opaque) -{ - int status; - - COCOA_DEBUG("Second thread: calling qemu_main()\n"); - status =3D qemu_main(gArgc, gArgv, *_NSGetEnviron()); - COCOA_DEBUG("Second thread: qemu_main() returned, exiting\n"); - [cbowner release]; - exit(status); -} - int main (int argc, char **argv) { QemuThread thread; =20 --=20 2.34.1 From nobody Mon Apr 29 15:35:53 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1647522136775497.27745119179497; Thu, 17 Mar 2022 06:02:16 -0700 (PDT) Received: from localhost ([::1]:51834 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nUplg-00071U-Ko for importer@patchew.org; Thu, 17 Mar 2022 09:02:16 -0400 Received: from eggs.gnu.org ([209.51.188.92]:40886) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nUpfe-0001Zx-21 for qemu-devel@nongnu.org; Thu, 17 Mar 2022 08:56:03 -0400 Received: from [2607:f8b0:4864:20::102c] (port=41760 helo=mail-pj1-x102c.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nUpfc-0002JY-53 for qemu-devel@nongnu.org; Thu, 17 Mar 2022 08:56:01 -0400 Received: by mail-pj1-x102c.google.com with SMTP id l4-20020a17090a49c400b001c6840df4a3so1612270pjm.0 for ; Thu, 17 Mar 2022 05:55:59 -0700 (PDT) Received: from localhost.localdomain ([185.126.107.38]) by smtp.gmail.com with ESMTPSA id s18-20020a639e12000000b00381bd8604ecsm4956889pgd.40.2022.03.17.05.55.55 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 17 Mar 2022 05:55:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=v1kajLTIBVh/LkzUN2J8GI2aKGy7zNFKJ2dw9r8dbWE=; b=H4cd6TRwsSw2qsCMsTkaFw8hs0l3ta6OgfcGWtSMgTkiwMw27aK2VShwnKbG3qZEfI G7quous/OBaC+PkS+cSwi7DU3ks0wqwPVodUQ6ikQziOJwgIO1hancQSlzwDnsoIdaoV J0ePf25R8PneNBnb/5P5jpDPs5j9APUQ4uibwpyfPy1MjTGDS4OYvwlFIvbSB22LX2Zo 59gjKB78pI5LEtMPFrMCGZPWLZj06h0Lh81lyq1+AHFmX41LLTUm/WZ/Eu4pFYPqgcrz PSQ4nqVEPkLsxfgRm2IyaW/J2+ufSGwc9LxLbjDWAe9ZJ/Lj/sMICQEiPAK3KhMz8MNB u8Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=v1kajLTIBVh/LkzUN2J8GI2aKGy7zNFKJ2dw9r8dbWE=; b=XrKcM9UhgncYaO92I3gm/W9LkduNJwwt8y/27UlgPETYie41V7EjRsVWjh5yAASawf ORW9NZufcole+eV63GVt3O3Wn2VDjeUQtD66IpTvQHN/GQ6/uGG32L+sVdy0KJnBt2fV cecEbOJOGwnK9j1LHn1cRjTIYP1upnMMBkaMO85xgbdzuzrkprRZgc4MeMtwJYkCF4G2 WKgI0HMZxE4i/8I9bFuBBnOcYbhAM2dbnsdcGJFmvEQdlo2tx2iGra1Ch5V+mEtbvdIQ X2y2RTrUssVfk0v9bEH2ocMdSJ7yZpHoyLRHRv2ZVck5EKZXy0sd27052cG4jtLiHP4C fEAQ== X-Gm-Message-State: AOAM531LXnWlKF7uwePuCV7C1M8VMxRaGuieYMzraVcxoO0VyU4c3Ak2 37BzYMDS3/r9MOEdnGHsypzm5IQUokw= X-Google-Smtp-Source: ABdhPJyU1dKVjJ5PwRkYB2zW9lzXHLfPnoIDmgRNaCbO6WzuQhrMhz/zOMApQjMy0fHNtlMK1cLSyQ== X-Received: by 2002:a17:902:7610:b0:151:6152:549c with SMTP id k16-20020a170902761000b001516152549cmr4623081pll.91.1647521758574; Thu, 17 Mar 2022 05:55:58 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Subject: [RFC PATCH-for-7.0 v4 2/2] ui/cocoa: run qemu_init in the main thread Date: Thu, 17 Mar 2022 13:55:34 +0100 Message-Id: <20220317125534.38706-3-philippe.mathieu.daude@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220317125534.38706-1-philippe.mathieu.daude@gmail.com> References: <20220317125534.38706-1-philippe.mathieu.daude@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::102c (failed) Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=philippe.mathieu.daude@gmail.com; helo=mail-pj1-x102c.google.com X-Spam_score_int: -6 X-Spam_score: -0.7 X-Spam_bar: / X-Spam_report: (-0.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Emanuele Giuseppe Esposito , Peter Maydell , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Akihiko Odaki , Paolo Bonzini , Kevin Wolf Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1647522139320100001 From: Paolo Bonzini Simplify the initialization dance by running qemu_init() in the main thread before the Cocoa event loop starts. The cocoa_display_init() code that is post-applicationDidFinishLaunching: moves to the application delegate itself, and the secondary thread only runs the rest of qemu_main(), namely qemu_main_loop() and qemu_cleanup(). This fixes a case where addRemovableDevicesMenuItems() calls qmp_query_block() while expecting the main thread to still hold the BQL. The newly-introduced assertions in the block layer complain about this. Signed-off-by: Paolo Bonzini Message-Id: <20220307151004.578069-1-pbonzini@redhat.com> [PMD: Fixed trivial build failures & rebased] Reviewed-by: Peter Maydell Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- softmmu/main.c | 12 +++-- ui/cocoa.m | 123 +++++++++++++++++++++---------------------------- 2 files changed, 60 insertions(+), 75 deletions(-) diff --git a/softmmu/main.c b/softmmu/main.c index 639c67ff48..0c4384e980 100644 --- a/softmmu/main.c +++ b/softmmu/main.c @@ -39,16 +39,18 @@ int main(int argc, char **argv) #endif #endif /* CONFIG_SDL */ =20 -#ifdef CONFIG_COCOA -#undef main -#define main qemu_main -#endif /* CONFIG_COCOA */ - +#ifndef CONFIG_COCOA int main(int argc, char **argv, char **envp) { + /* + * ui/cocoa.m relies on this being the exact content of main(), + * because it has to run everything after qemu_init in a secondary + * thread. + */ qemu_init(argc, argv, envp); qemu_main_loop(); qemu_cleanup(); =20 return 0; } +#endif /* CONFIG_COCOA */ diff --git a/ui/cocoa.m b/ui/cocoa.m index 027c3053f7..4483d5e648 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -100,14 +100,13 @@ static int last_buttons; static int cursor_hide =3D 1; static int left_command_key_enabled =3D 1; static bool swap_opt_cmd; +static bool full_screen; +static bool full_grab; +static bool have_cocoa_ui; =20 -static int gArgc; -static char **gArgv; static bool stretch_video; static NSTextField *pauseLabel; =20 -static QemuSemaphore display_init_sem; -static QemuSemaphore app_started_sem; static bool allow_events; =20 static NSInteger cbchangecount =3D -1; @@ -150,39 +149,28 @@ static bool bool_with_iothread_lock(BoolCodeBlock blo= ck) /* * The startup process for the OSX/Cocoa UI is complicated, because * OSX insists that the UI runs on the initial main thread, and so we - * need to start a second thread which runs the vl.c qemu_main(): + * need to start a second thread which runs qemu_main_loop(): * * Initial thread: 2nd thread: * in main(): - * create qemu-main thread - * wait on display_init semaphore - * call qemu_main() - * ... - * in cocoa_display_init(): - * post the display_init semaphore - * wait on app_started semaphore + * qemu_init() * create application, menus, etc * enter OSX run loop * in applicationDidFinishLaunching: - * post app_started semaphore - * tell main thread to fullscreen if n= eeded - * [...] - * run qemu main-loop - * - * We do this in two stages so that we don't do the creation of the - * GUI application menus and so on for command line options like --help - * where we want to just print text to stdout and exit immediately. + * fullscreen if needed + * create main loop thread + * call qemu_main_loop() */ =20 -static void *call_qemu_main(void *opaque) +static void *call_qemu_main_loop(void *opaque) { - int status; - - COCOA_DEBUG("Second thread: calling qemu_main()\n"); - status =3D qemu_main(gArgc, gArgv, *_NSGetEnviron()); - COCOA_DEBUG("Second thread: qemu_main() returned, exiting\n"); + COCOA_DEBUG("Second thread: calling qemu_main_loop()\n"); + qemu_mutex_lock_iothread(); + qemu_main_loop(); + COCOA_DEBUG("Second thread: qemu_main_loop() returned, exiting\n"); + qemu_cleanup(); [cbowner release]; - exit(status); + exit(0); } =20 // Mac to QKeyCode conversion @@ -627,9 +615,9 @@ static CGEventRef handleTapEvent(CGEventTapProxy proxy,= CGEventType type, CGEven * Don't try to tell QEMU about UI information in the application * startup phase -- we haven't yet registered dcl with the QEMU UI * layer, and also trying to take the iothread lock would deadlock. - * When cocoa_display_init() does register the dcl, the UI layer - * will call cocoa_switch(), which will call updateUIInfo, so - * we don't lose any information here. + * When applicationDidFinishLaunching() does register the dcl, the + * UI layer will call cocoa_switch(), which will call updateUIInfo, + * so we don't lose any information here. */ return; } @@ -823,9 +811,7 @@ static CGEventRef handleTapEvent(CGEventTapProxy proxy,= CGEventType type, CGEven /* * Just let OSX have all events that arrive before * applicationDidFinishLaunching. - * This avoids a deadlock on the iothread lock, which cocoa_displa= y_init() - * will not drop until after the app_started_sem is posted. (In th= eory - * there should not be any such events, but OSX Catalina now emits= some.) + * This may not be needed anymore? */ return false; } @@ -1321,10 +1307,27 @@ static CGEventRef handleTapEvent(CGEventTapProxy pr= oxy, CGEventType type, CGEven =20 - (void)applicationDidFinishLaunching: (NSNotification *) note { + QemuThread main_thread; + COCOA_DEBUG("QemuCocoaAppController: applicationDidFinishLaunching\n"); allow_events =3D true; - /* Tell cocoa_display_init to proceed */ - qemu_sem_post(&app_started_sem); + + // register vga output callbacks + register_displaychangelistener(&dcl); + + qemu_clipboard_peer_register(&cbpeer); + + qemu_mutex_unlock_iothread(); + qemu_thread_create(&main_thread, "qemu_main_loop", call_qemu_main_loop, + NULL, QEMU_THREAD_DETACHED); + + if (full_screen) { + [NSApp activateIgnoringOtherApps: YES]; + [self toggleFullScreen: nil]; + } + if (full_grab) { + [self setFullGrab: nil]; + } } =20 - (void)applicationWillTerminate:(NSNotification *)aNotification @@ -1941,22 +1944,17 @@ static void cocoa_clipboard_request(QemuClipboardIn= fo *info, } } =20 -int main (int argc, char **argv) { - QemuThread thread; - +int main(int argc, char **argv, char **envp) +{ COCOA_DEBUG("Entered main()\n"); - gArgc =3D argc; - gArgv =3D argv; =20 - qemu_sem_init(&display_init_sem, 0); - qemu_sem_init(&app_started_sem, 0); - - qemu_thread_create(&thread, "qemu_main", call_qemu_main, - NULL, QEMU_THREAD_DETACHED); - - COCOA_DEBUG("Main thread: waiting for display_init_sem\n"); - qemu_sem_wait(&display_init_sem); - COCOA_DEBUG("Main thread: initializing app\n"); + /* Takes iothread lock, released in applicationDidFinishLaunching:. */ + qemu_init(argc, argv, envp); + if (!have_cocoa_ui) { + qemu_main_loop(); + qemu_cleanup(); + return 0; + } =20 NSAutoreleasePool * pool =3D [[NSAutoreleasePool alloc] init]; =20 @@ -1979,6 +1977,9 @@ int main (int argc, char **argv) { add_console_menu_entries(); addRemovableDevicesMenuItems(); =20 + qemu_event_init(&cbevent, false); + cbowner =3D [[QemuCocoaPasteboardTypeOwner alloc] init]; + // Create an Application controller QemuCocoaAppController *appController =3D [[QemuCocoaAppController all= oc] init]; [NSApp setDelegate:appController]; @@ -2071,24 +2072,13 @@ static void cocoa_refresh(DisplayChangeListener *dc= l) static void cocoa_display_init(DisplayState *ds, DisplayOptions *opts) { COCOA_DEBUG("qemu_cocoa: cocoa_display_init\n"); + have_cocoa_ui =3D 1; =20 - /* Tell main thread to go ahead and create the app and enter the run l= oop */ - qemu_sem_post(&display_init_sem); - qemu_sem_wait(&app_started_sem); - COCOA_DEBUG("cocoa_display_init: app start completed\n"); - - QemuCocoaAppController *controller =3D (QemuCocoaAppController *)[[NSA= pplication sharedApplication] delegate]; - /* if fullscreen mode is to be used */ if (opts->has_full_screen && opts->full_screen) { - dispatch_async(dispatch_get_main_queue(), ^{ - [NSApp activateIgnoringOtherApps: YES]; - [controller toggleFullScreen: nil]; - }); + full_screen =3D 1; } if (opts->u.cocoa.has_full_grab && opts->u.cocoa.full_grab) { - dispatch_async(dispatch_get_main_queue(), ^{ - [controller setFullGrab: nil]; - }); + full_grab =3D 1; } =20 if (opts->has_show_cursor && opts->show_cursor) { @@ -2101,13 +2091,6 @@ static void cocoa_display_init(DisplayState *ds, Dis= playOptions *opts) if (opts->u.cocoa.has_left_command_key && !opts->u.cocoa.left_command_= key) { left_command_key_enabled =3D 0; } - - // register vga output callbacks - register_displaychangelistener(&dcl); - - qemu_event_init(&cbevent, false); - cbowner =3D [[QemuCocoaPasteboardTypeOwner alloc] init]; - qemu_clipboard_peer_register(&cbpeer); } =20 static QemuDisplay qemu_display_cocoa =3D { --=20 2.34.1