From nobody Mon Feb 9 16:34:21 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1710942899; cv=none; d=zohomail.com; s=zohoarc; b=POp4YyD2uv7hiIC2+fWaNJrI7tTXaEaLI1wxiYR0bcr7FCafSRtBVkK55MQoMyhs1G14CILd/k6d+5FI/ZqXUWJHExTczeVfM4WDsnU64qqdyh2HHdEWPpiJQNvX1j6mIGtQEKwLVNcr5hbVxCj86O/CMBWP8kxqx1wqmyxzwCM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1710942899; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=hd7LmA408dvHfo5kRnbpaogkLqac1ZzU7woAzEbOZcM=; b=CYoCGOahLJMWGeKdan3OMtrDnV/CDt0dZShmflqATE5oDbrZZjLhJ7mXIffaO8IVawV1b+itMJ4AAhVHxWhfJxx9GLVZGa2ZbSSEJX5hA13kzMBmJl4/xGuljfy5z5aq+t+Yfcyr+X1EAcX4rkWdyLryAo1n+ktQbObbOuEHelA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1710942899886350.4866806759237; Wed, 20 Mar 2024 06:54:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rmwOm-0004Be-Op; Wed, 20 Mar 2024 09:54:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rmwOl-0004Ai-6a for qemu-devel@nongnu.org; Wed, 20 Mar 2024 09:54:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rmwOj-0000BA-6O for qemu-devel@nongnu.org; Wed, 20 Mar 2024 09:54:30 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-453-qbo5EUDpP7OV8an0IpsA-A-1; Wed, 20 Mar 2024 09:54:25 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A7A7381A285; Wed, 20 Mar 2024 13:54:22 +0000 (UTC) Received: from localhost (unknown [10.39.208.32]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1B286492BCA; Wed, 20 Mar 2024 13:54:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710942868; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hd7LmA408dvHfo5kRnbpaogkLqac1ZzU7woAzEbOZcM=; b=a9bk0C5Ce1qyqJlzp6G0FSzdlTM1gs9KFg+135shxW25f2Xq+HEtro9kQepG7mAGgpuNOp KHWYnqovmOqB0JW0oRxYudDRfh2otNyV80tFYvhIKHxdvqBxOjPlUKe0b0t/cqtMD2lQt2 8LfBzUpaetLQUrWljRLQC7BybNsbM4Y= X-MC-Unique: qbo5EUDpP7OV8an0IpsA-A-1 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , Peter Maydell , Gerd Hoffmann , Akihiko Odaki , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PULL 3/5] ui/cocoa: Do not use console_select() Date: Wed, 20 Mar 2024 17:53:47 +0400 Message-ID: <20240320135349.2139402-4-marcandre.lureau@redhat.com> In-Reply-To: <20240320135349.2139402-1-marcandre.lureau@redhat.com> References: <20240320135349.2139402-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.9 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=170.10.129.124; envelope-from=marcandre.lureau@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.417, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1710942900285100001 From: Akihiko Odaki ui/cocoa needs to update the UI info and reset the keyboard state tracker when switching the console, or the new console will see the stale UI info or keyboard state. Previously, updating the UI info was done with cocoa_switch(), but it is meant to be called when the surface is being replaced, and may be called even when not switching the console. ui/cocoa never reset the keyboard state, which resulted in stuck keys. Add ui/cocoa's own implementation of console_select(), which updates the UI info and resets the keyboard state tracker. Signed-off-by: Akihiko Odaki Reviewed-by: Marc-Andr=C3=A9 Lureau Message-Id: <20240319-console-v2-3-3fd6feef321a@daynix.com> --- ui/cocoa.m | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index fa879d7dcd..810751cf26 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -102,6 +102,7 @@ static void cocoa_switch(DisplayChangeListener *dcl, static DisplayChangeListener dcl =3D { .ops =3D &dcl_ops, }; +static QKbdState *kbd; static int cursor_hide =3D 1; static int left_command_key_enabled =3D 1; static bool swap_opt_cmd; @@ -309,7 +310,6 @@ @interface QemuCocoaView : NSView NSTrackingArea *trackingArea; QEMUScreen screen; pixman_image_t *pixman_image; - QKbdState *kbd; BOOL isMouseGrabbed; BOOL isAbsoluteEnabled; CFMachPortRef eventsTap; @@ -361,7 +361,6 @@ - (id)initWithFrame:(NSRect)frameRect =20 screen.width =3D frameRect.size.width; screen.height =3D frameRect.size.height; - kbd =3D qkbd_state_init(dcl.con); #if MAC_OS_X_VERSION_MAX_ALLOWED >=3D MAC_OS_VERSION_14_0 [self setClipsToBounds:YES]; #endif @@ -378,8 +377,6 @@ - (void) dealloc pixman_image_unref(pixman_image); } =20 - qkbd_state_free(kbd); - if (eventsTap) { CFRelease(eventsTap); } @@ -429,6 +426,20 @@ - (void) viewWillMoveToWindow:(NSWindow *)newWindow [self removeTrackingRect]; } =20 +- (void) selectConsoleLocked:(unsigned int)index +{ + QemuConsole *con =3D qemu_console_lookup_by_index(index); + if (!con) { + return; + } + + unregister_displaychangelistener(&dcl); + qkbd_state_switch_console(kbd, con); + dcl.con =3D con; + register_displaychangelistener(&dcl); + [self updateUIInfo]; +} + - (void) hideCursor { if (!cursor_hide) { @@ -718,7 +729,8 @@ - (void) handleMonitorInput:(NSEvent *)event } =20 if (keysym) { - qemu_text_console_put_keysym(NULL, keysym); + QemuTextConsole *con =3D QEMU_TEXT_CONSOLE(dcl.con); + qemu_text_console_put_keysym(con, keysym); } } =20 @@ -898,7 +910,7 @@ - (bool) handleEventLocked:(NSEvent *)event =20 // enable graphic console case '1' ... '9': - console_select(key - '0' - 1); /* ascii math */ + [self selectConsoleLocked:key - '0' - 1]; /* a= scii math */ return true; =20 // release the mouse grab @@ -909,7 +921,7 @@ - (bool) handleEventLocked:(NSEvent *)event } } =20 - if (qemu_console_is_graphic(NULL)) { + if (qemu_console_is_graphic(dcl.con)) { qkbd_state_key_event(kbd, keycode, true); } else { [self handleMonitorInput: event]; @@ -924,7 +936,7 @@ - (bool) handleEventLocked:(NSEvent *)event return true; } =20 - if (qemu_console_is_graphic(NULL)) { + if (qemu_console_is_graphic(dcl.con)) { qkbd_state_key_event(kbd, keycode, false); } return true; @@ -1374,7 +1386,7 @@ - (void)toggleZoomInterpolation:(id) sender - (void)displayConsole:(id)sender { with_bql(^{ - console_select([sender tag]); + [cocoaView selectConsoleLocked:[sender tag]]; }); } =20 @@ -1945,7 +1957,6 @@ static void cocoa_switch(DisplayChangeListener *dcl, pixman_image_ref(image); =20 dispatch_async(dispatch_get_main_queue(), ^{ - [cocoaView updateUIInfo]; [cocoaView switchSurface:image]; }); } @@ -1955,7 +1966,7 @@ static void cocoa_refresh(DisplayChangeListener *dcl) NSAutoreleasePool * pool =3D [[NSAutoreleasePool alloc] init]; =20 COCOA_DEBUG("qemu_cocoa: cocoa_refresh\n"); - graphic_hw_update(NULL); + graphic_hw_update(dcl->con); =20 if (qemu_input_is_absolute(dcl->con)) { dispatch_async(dispatch_get_main_queue(), ^{ @@ -2039,8 +2050,12 @@ static void cocoa_display_init(DisplayState *ds, Dis= playOptions *opts) add_console_menu_entries(); addRemovableDevicesMenuItems(); =20 + dcl.con =3D qemu_console_lookup_default(); + kbd =3D qkbd_state_init(dcl.con); + // register vga output callbacks register_displaychangelistener(&dcl); + [cocoaView updateUIInfo]; =20 qemu_event_init(&cbevent, false); cbowner =3D [[QemuCocoaPasteboardTypeOwner alloc] init]; --=20 2.44.0