From nobody Mon Aug 24 11:10:00 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=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1781168793; cv=none; d=zohomail.com; s=zohoarc; b=Sl4cg7eL59NXItMBIAtmRiipvzV18c24gQY7ldx3B/9IU+Gbgme8NCOjxtnhJeYQhI2E0/fVjtqLCxJ5MPNOIlr2HbTB7ldyzLwAuet8zPv5PKQ6G6aU53l0GG5rYpzqR6l5gg47gwUmGO2dAWAIp8j08K/3xha7FEOb4AAKke8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1781168793; 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=tKlxCGNKs0kk4ALX1vXp/DYEb4dpEwlOWrBgQleDG7c=; b=RaZ9tCRDQ6M29AdfC+KZdFV6Dh2la/A13kt9y7f1OqskndsNA9FkjjZtFGZqCq4OjtiABJMjy01QWPPzgYary3JQ4JJL3XyluB8YEdg1BcpiJ8ZjVE4HLN1A2XK0USpoMmUTRfeUNe3Il4bMS3n6xE61rGVi8DGVyKypC+ygy54= 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=quarantine dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1781168793467488.11627783673543; Thu, 11 Jun 2026 02:06:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wXbMF-0005ES-Be; Thu, 11 Jun 2026 05:05:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wXbMD-00058S-M5 for qemu-devel@nongnu.org; Thu, 11 Jun 2026 05:05:49 -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 1wXbMC-0005Az-0m for qemu-devel@nongnu.org; Thu, 11 Jun 2026 05:05:49 -0400 Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-161-ZrJZQHXBMQmVfPQTwyeVCQ-1; Thu, 11 Jun 2026 05:05:43 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 947C91802170; Thu, 11 Jun 2026 09:05:42 +0000 (UTC) Received: from localhost (unknown [10.44.24.21]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4FFF43008B34; Thu, 11 Jun 2026 09:05:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1781168747; 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=tKlxCGNKs0kk4ALX1vXp/DYEb4dpEwlOWrBgQleDG7c=; b=S2zpsvDh38SO93grwAfvjiui/5394d95Jc6qeXGhD4TsxJW+O7UirKQJjMZ8RUBVsaUnem qTG6EJcfZK0LfIwLc95pDvxn49nLDWSR/smFrMaTUHipSYPf+anUQ8gM99QANE7VMWhURq 2rtqv9qDQBsAyEVsCuo+tmD33ggTps8= X-MC-Unique: ZrJZQHXBMQmVfPQTwyeVCQ-1 X-Mimecast-MFC-AGG-ID: ZrJZQHXBMQmVfPQTwyeVCQ_1781168742 From: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= Date: Thu, 11 Jun 2026 13:03:38 +0400 Subject: [PATCH v3 23/35] ui/gtk: implement display cleanup MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260611-b4-ui-v3-23-72bcbbea0fae@redhat.com> References: <20260611-b4-ui-v3-0-72bcbbea0fae@redhat.com> In-Reply-To: <20260611-b4-ui-v3-0-72bcbbea0fae@redhat.com> To: qemu-devel@nongnu.org Cc: Paolo Bonzini , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Pierrick Bouvier , Fabiano Rosas , Laurent Vivier , Alex Williamson , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Peter Maydell , Akihiko Odaki , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Developer-Signature: v=1; a=openpgp-sha256; l=3764; i=marcandre.lureau@redhat.com; h=from:subject:message-id; bh=+DG8xB4KJmLQS3EpZUbBQpkZhWCN+8ypFWbdujyuWPI=; b=owEBbQKS/ZANAwAKAdro4Ql1lpzlAcsmYgBqKnngr+N9u4sRqPhZrsRj/RtBI24fTQRU7DDt5 mKytcqg8U2JAjMEAAEKAB0WIQSHqb2TP4fGBtJ29i3a6OEJdZac5QUCaip54AAKCRDa6OEJdZac 5Q6DD/0RV3QQIuVBtTFRFNc8h4YAAUP2NgMSzNm3nitsj4ITdJ29Cx77YuzD+NDniYAocY0bVef XhZgsyzXM6zkWBkWASafj+Ck35dvJ0Cp1K5REq6EFLHDCGLfM6PTAaDAw1I9A7lPIB1Hzk30hPU Z/S+RUEfiPYtN5rJZxXRaEX/dXHXTwQkuijU1A9ZIQhjYuxp74fy6TP8q+b1dRoET3MWA1husYL bBtA9dLgwpWMCI1QVVxx2SfSRqM6xVecorffAyZ75lMcP5UFh7ohcLpeUrKJV2A8zx1QRVke8hM /j84ETxqzDX4NyPDg0QZp/zfvwVpeoodkoKkeD1wPdnogo7b/dnkJp+Ad8HefEYkEJSVm2H8rlO FRtVQ9WT8GFPXRpMB0x4Sq9odmFmM17OkHNDkk8dHcCje7nIWBlFLFcAEddMe7bU3RCORIE8PJL fIBKiWKHlW3hyGLYAgOFLKjfd9x0ororJ/uSKe07GYjLv+ws9soSP2+CPCBcSs4EfUgHxZEhe8U nl49HWmuIcmnbsD4OhkCPx47IZRoasIcaw+p8P3j3zEBpq55uQTAyPTX5AjsllLkyO+JpCDUQT3 f1e5gCtveOuS2k8fslGrcPj7hgwugCe3xXybJwzBJ0L+WWRReJiAwXaWLV/brAg/xYxdIxa2BSR PKWKGIhOkj4tKMQ== X-Developer-Key: i=marcandre.lureau@redhat.com; a=openpgp; fpr=87A9BD933F87C606D276F62DDAE8E10975969CE5 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 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=lists1p.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.445, 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_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 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: qemu development 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: 1781168794229158500 Add gtk_display_cleanup() to properly tear down GTK display state: remove console and mouse notifiers, unregister clipboard peer, destroy the main window and virtual consoles. Signed-off-by: Marc-Andr=C3=A9 Lureau --- include/ui/gtk.h | 2 ++ ui/gtk-clipboard.c | 15 +++++++++++++++ ui/gtk.c | 20 +++++++++++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/include/ui/gtk.h b/include/ui/gtk.h index 3e6ce3cb48c..f4c8e6a9f00 100644 --- a/include/ui/gtk.h +++ b/include/ui/gtk.h @@ -140,6 +140,7 @@ struct GtkDisplayState { =20 GdkCursor *null_cursor; Notifier mouse_mode_notifier; + VMChangeStateEntry *vmse; gboolean free_scale; gboolean keep_aspect_ratio; =20 @@ -225,6 +226,7 @@ int gd_gl_area_make_current(DisplayGLCtx *dgc, =20 /* gtk-clipboard.c */ void gd_clipboard_init(GtkDisplayState *gd); +void gd_clipboard_cleanup(GtkDisplayState *gd); =20 void gd_update_scale(VirtualConsole *vc, int ww, int wh, int fbw, int fbh); =20 diff --git a/ui/gtk-clipboard.c b/ui/gtk-clipboard.c index ea9444be70f..476e6b8303c 100644 --- a/ui/gtk-clipboard.c +++ b/ui/gtk-clipboard.c @@ -235,3 +235,18 @@ void gd_clipboard_init(GtkDisplayState *gd) g_signal_connect(gd->gtkcb[QEMU_CLIPBOARD_SELECTION_SECONDARY], "owner-change", G_CALLBACK(gd_owner_change), gd); } + +void gd_clipboard_cleanup(GtkDisplayState *gd) +{ + if (!gd->cbpeer.name) { + return; + } + qemu_clipboard_peer_unregister(&gd->cbpeer); + g_signal_handlers_disconnect_by_data( + gd->gtkcb[QEMU_CLIPBOARD_SELECTION_CLIPBOARD], gd); + g_signal_handlers_disconnect_by_data( + gd->gtkcb[QEMU_CLIPBOARD_SELECTION_PRIMARY], gd); + g_signal_handlers_disconnect_by_data( + gd->gtkcb[QEMU_CLIPBOARD_SELECTION_SECONDARY], gd); + gd->cbpeer.name =3D NULL; +} diff --git a/ui/gtk.c b/ui/gtk.c index 2ee826b56fb..dfef1b10fe3 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -2505,6 +2505,7 @@ static void gd_create_menus(GtkDisplayState *s, Displ= ayOptions *opts) } =20 =20 +static GtkDisplayState *gtk_display_state; static gboolean gtkinit; =20 static void gtk_display_init(DisplayState *ds, DisplayOptions *opts) @@ -2523,6 +2524,7 @@ static void gtk_display_init(DisplayState *ds, Displa= yOptions *opts) } assert(opts->type =3D=3D DISPLAY_TYPE_GTK); s =3D g_malloc0(sizeof(*s)); + gtk_display_state =3D s; s->opts =3D opts; =20 theme =3D gtk_icon_theme_get_default(); @@ -2560,7 +2562,7 @@ static void gtk_display_init(DisplayState *ds, Displa= yOptions *opts) =20 s->mouse_mode_notifier.notify =3D gd_mouse_mode_change; qemu_add_mouse_mode_change_notifier(&s->mouse_mode_notifier); - qemu_add_vm_change_state_handler(gd_change_runstate, s); + s->vmse =3D qemu_add_vm_change_state_handler(gd_change_runstate, s); =20 gtk_window_set_icon_name(GTK_WINDOW(s->window), "qemu"); =20 @@ -2681,10 +2683,26 @@ static void early_gtk_display_init(DisplayOptions *= opts) #endif } =20 +static void gtk_display_cleanup(void) +{ + GtkDisplayState *s =3D gtk_display_state; + + if (!s) { + return; + } + qemu_del_vm_change_state_handler(s->vmse); + qemu_remove_mouse_mode_change_notifier(&s->mouse_mode_notifier); + gd_clipboard_cleanup(s); + g_clear_pointer(&s->window, gtk_widget_destroy); + g_clear_object(&s->null_cursor); + g_clear_pointer(>k_display_state, g_free); +} + static QemuDisplay qemu_display_gtk =3D { .type =3D DISPLAY_TYPE_GTK, .early_init =3D early_gtk_display_init, .init =3D gtk_display_init, + .cleanup =3D gtk_display_cleanup, .vc =3D "vc", }; =20 --=20 2.54.0