From dff742ad27efa474ec04accdbf422c9acfd3e30e Mon Sep 17 00:00:00 2001 From: Hikaru Nishida Date: Tue, 15 Oct 2019 10:07:34 +0900 Subject: [PATCH 1/4] ui: Fix hanging up Cocoa display on macOS 10.15 (Catalina) macOS API documentation says that before applicationDidFinishLaunching is called, any events will not be processed. However, some events are fired before it is called in macOS Catalina. This causes deadlock of iothread_lock in handleEvent while it will be released after the app_started_sem is posted. This patch avoids processing events before the app_started_sem is posted to prevent this deadlock. Buglink: https://bugs.launchpad.net/qemu/+bug/1847906 Signed-off-by: Hikaru Nishida Message-id: 20191015010734.85229-1-hikarupsp@gmail.com Signed-off-by: Gerd Hoffmann --- ui/cocoa.m | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ui/cocoa.m b/ui/cocoa.m index f12e21df6e..fbb5b1b45f 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -134,6 +134,7 @@ NSArray * supportedImageFileTypes; static QemuSemaphore display_init_sem; static QemuSemaphore app_started_sem; +static bool allow_events; // Utility functions to run specified code block with iothread lock held typedef void (^CodeBlock)(void); @@ -729,6 +730,16 @@ QemuCocoaView *cocoaView; - (bool) handleEvent:(NSEvent *)event { + if(!allow_events) { + /* + * Just let OSX have all events that arrive before + * applicationDidFinishLaunching. + * This avoids a deadlock on the iothread lock, which cocoa_display_init() + * will not drop until after the app_started_sem is posted. (In theory + * there should not be any such events, but OSX Catalina now emits some.) + */ + return false; + } return bool_with_iothread_lock(^{ return [self handleEventLocked:event]; }); @@ -1156,6 +1167,7 @@ QemuCocoaView *cocoaView; - (void)applicationDidFinishLaunching: (NSNotification *) note { COCOA_DEBUG("QemuCocoaAppController: applicationDidFinishLaunching\n"); + allow_events = true; /* Tell cocoa_display_init to proceed */ qemu_sem_post(&app_started_sem); } From cd54ea456dbb2c704e8eb88c8ef4d3316aec133b Mon Sep 17 00:00:00 2001 From: Matthew Kilgore Date: Thu, 3 Oct 2019 23:53:37 -0400 Subject: [PATCH 2/4] curses: use the bit mask constants provided by curses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The curses API provides the A_ATTRIBUTES and A_CHARTEXT bit masks for getting the attributes and character parts of a chtype, respectively. We should use provided constants instead of using 0xff. Signed-off-by: Matthew Kilgore Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Samuel Thibault Tested-by: Samuel Thibault Message-id: 20191004035338.25601-2-mattkilgore12@gmail.com Signed-off-by: Gerd Hoffmann --- ui/curses.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/curses.c b/ui/curses.c index ec281125ac..84003f56a3 100644 --- a/ui/curses.c +++ b/ui/curses.c @@ -75,8 +75,8 @@ static void curses_update(DisplayChangeListener *dcl, line = screen + y * width; for (h += y; y < h; y ++, line += width) { for (x = 0; x < width; x++) { - chtype ch = line[x] & 0xff; - chtype at = line[x] & ~0xff; + chtype ch = line[x] & A_CHARTEXT; + chtype at = line[x] & A_ATTRIBUTES; ret = getcchar(&vga_to_curses[ch], wch, &attrs, &colors, NULL); if (ret == ERR || wch[0] == 0) { wch[0] = ch; From 30f5a9dd7a6252d31fb73ab5193f3be1be7766c7 Mon Sep 17 00:00:00 2001 From: Matthew Kilgore Date: Thu, 3 Oct 2019 23:53:38 -0400 Subject: [PATCH 3/4] curses: correctly pass the color pair to setcchar() The current code does not correctly pass the color pair information to setcchar(), it instead always passes zero. This results in the curses output always being in white on black. This patch fixes this by using PAIR_NUMBER() to retrieve the color pair number from the chtype value, and then passes that value as an argument to setcchar(). Signed-off-by: Matthew Kilgore Reviewed-by: Samuel Thibault Tested-by: Samuel Thibault Message-id: 20191004035338.25601-3-mattkilgore12@gmail.com Signed-off-by: Gerd Hoffmann --- ui/curses.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ui/curses.c b/ui/curses.c index 84003f56a3..3a1b71451c 100644 --- a/ui/curses.c +++ b/ui/curses.c @@ -77,12 +77,14 @@ static void curses_update(DisplayChangeListener *dcl, for (x = 0; x < width; x++) { chtype ch = line[x] & A_CHARTEXT; chtype at = line[x] & A_ATTRIBUTES; + short color_pair = PAIR_NUMBER(line[x]); + ret = getcchar(&vga_to_curses[ch], wch, &attrs, &colors, NULL); if (ret == ERR || wch[0] == 0) { wch[0] = ch; wch[1] = 0; } - setcchar(&curses_line[x], wch, at, 0, NULL); + setcchar(&curses_line[x], wch, at, color_pair, NULL); } mvwadd_wchnstr(screenpad, y, 0, curses_line, width); } From 707f75070a94c28889f887deef0ab4da09e25ddf Mon Sep 17 00:00:00 2001 From: Laurent Vivier Date: Tue, 24 Sep 2019 00:06:58 +0200 Subject: [PATCH 4/4] ui: fix keymap file search in input-barrier object If we try to start QEMU with "-k en-us", qemu prints a message and exits with: qemu-system-i386: could not read keymap file: 'en-us' It's because this function is called way too early, before qemu_add_data_dir() is called, and so qemu_find_file() fails. To fix that, move init_keyboard_layout() from the class init function to the instance init function. Reported-by: Anthony PERARD Reviewed-by: Anthony PERARD Signed-off-by: Laurent Vivier Message-id: 20190923220658.27007-1-laurent@vivier.eu Fixes: 6105683da35b ("ui: add an embedded Barrier client") Signed-off-by: Laurent Vivier Signed-off-by: Gerd Hoffmann --- ui/input-barrier.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ui/input-barrier.c b/ui/input-barrier.c index a2c961f285..fe35049b83 100644 --- a/ui/input-barrier.c +++ b/ui/input-barrier.c @@ -682,6 +682,13 @@ static void input_barrier_instance_init(Object *obj) { InputBarrier *ib = INPUT_BARRIER(obj); + /* always use generic keymaps */ + if (keyboard_layout && !kbd_layout) { + /* We use X11 key id, so use VNC name2keysym */ + kbd_layout = init_keyboard_layout(name2keysym, keyboard_layout, + &error_fatal); + } + ib->saddr.type = SOCKET_ADDRESS_TYPE_INET; ib->saddr.u.inet.host = g_strdup("localhost"); ib->saddr.u.inet.port = g_strdup("24800"); @@ -719,13 +726,6 @@ static void input_barrier_class_init(ObjectClass *oc, void *data) UserCreatableClass *ucc = USER_CREATABLE_CLASS(oc); ucc->complete = input_barrier_complete; - - /* always use generic keymaps */ - if (keyboard_layout) { - /* We use X11 key id, so use VNC name2keysym */ - kbd_layout = init_keyboard_layout(name2keysym, keyboard_layout, - &error_fatal); - } } static const TypeInfo input_barrier_info = {