From nobody Sat Nov 15 12:48:50 2025 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=1752561744; cv=none; d=zohomail.com; s=zohoarc; b=mxR2MUWCIYOBd7dYbmvTmndxxatHFQaMePRBVmhUK9Q8HE5Rux4L77Rq48yXkw6Z6HRo53+HaoUYrkgU0fcilKInnPaGSb+qF4LGYeBFs1dwXe1XYkIlMFSaFIdJ33oB45KLlqw4mVUiJrS+Ia9YPV0Fx05PPilrLvIhncucZQU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1752561744; 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=/4myqjH/Kdl7ZWCnYA3d+VdEmgMCkL9UEwDV1RI1+bc=; b=EbBrpu0Ly8+2W+LoD2gB++mhTq9qEt5PLwwsfYlWSGBBmanBRoL6c/F5kzrdW3r9sEFtbvwOCE4bFa2vyY2f6c9YutugPSxfAUe4IHGpUidpJYmPteQ/oc803GDc0HsYhsuC2DW+BjG+XKb9/Wcu61QyYQ7M6KXQPQ9bc1PvkhU= 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1752561744886731.9873001020047; Mon, 14 Jul 2025 23:42:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ubZMj-0003FC-JB; Tue, 15 Jul 2025 02:42:13 -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 1ubZFJ-0003VV-BK for qemu-devel@nongnu.org; Tue, 15 Jul 2025 02:34:33 -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 1ubZFH-0003lx-DO for qemu-devel@nongnu.org; Tue, 15 Jul 2025 02:34:33 -0400 Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-47-R2upl8ZnO2acescwyKm7rw-1; Tue, 15 Jul 2025 02:34:25 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 696011956080; Tue, 15 Jul 2025 06:34:24 +0000 (UTC) Received: from localhost (unknown [10.45.242.9]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4B0191956094; Tue, 15 Jul 2025 06:34:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1752561269; 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=/4myqjH/Kdl7ZWCnYA3d+VdEmgMCkL9UEwDV1RI1+bc=; b=f3/SDgFVZS/YQ2x2qAHIGhmvLFvRqICOFEnrBuXgtboAkD7x/wIrRBSlHpDeiu9ZOPl4jz Eh4cV1GWia/wn/G2r559iVKoOGth+685hBAcv1vq6IvZog7U/WyCFiCowRozFmm8RXi3T2 bNBgDUg4905hj6EFfNKYivmzvYjfLzs= X-MC-Unique: R2upl8ZnO2acescwyKm7rw-1 X-Mimecast-MFC-AGG-ID: R2upl8ZnO2acescwyKm7rw_1752561264 From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, Weifeng Liu , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Eric Blake , Markus Armbruster Subject: [PULL v2 12/13] ui/gtk: Add scale option Date: Tue, 15 Jul 2025 10:32:58 +0400 Message-ID: <20250715063301.145191-13-marcandre.lureau@redhat.com> In-Reply-To: <20250715063301.145191-1-marcandre.lureau@redhat.com> References: <20250715063301.145191-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.0 on 10.30.177.15 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=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: 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: 1752561746232116600 From: Weifeng Liu Allow user to set a preferred scale (defaulting to 1) of the virtual display. Along with zoom-to-fix=3Dfalse, this would be helpful for users running QEMU on hi-dpi host desktop to achieve pixel to pixel display -- e.g., if the scale factor of a user's host desktop is set to 200%, then they can set a 0.5 scale for the virtual display to avoid magnification that might cause blurriness. Signed-off-by: Weifeng Liu Reviewed-by: Marc-Andr=C3=A9 Lureau Tested-by: Marc-Andr=C3=A9 Lureau Message-Id: <20250601045245.36778-3-weifeng.liu.z@gmail.com> --- qapi/ui.json | 5 ++++- include/ui/gtk.h | 1 + ui/gtk.c | 46 +++++++++++++++++++++++++++++----------------- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/qapi/ui.json b/qapi/ui.json index 9e496b4835..a465d671c7 100644 --- a/qapi/ui.json +++ b/qapi/ui.json @@ -1338,6 +1338,8 @@ # @keep-aspect-ratio: Keep width/height aspect ratio of guest content when # resizing host window. Defaults to "on". (Since 10.1) # +# @scale: Set preferred scale of the display. Defaults to 1.0. (Since 10= .1) +# # Since: 2.12 ## { 'struct' : 'DisplayGTK', @@ -1345,7 +1347,8 @@ '*zoom-to-fit' : 'bool', '*show-tabs' : 'bool', '*show-menubar' : 'bool', - '*keep-aspect-ratio' : 'bool' } } + '*keep-aspect-ratio' : 'bool', + '*scale' : 'number' } } =20 ## # @DisplayEGLHeadless: diff --git a/include/ui/gtk.h b/include/ui/gtk.h index b7cfbf218e..3e6ce3cb48 100644 --- a/include/ui/gtk.h +++ b/include/ui/gtk.h @@ -41,6 +41,7 @@ typedef struct VirtualGfxConsole { DisplaySurface *ds; pixman_image_t *convert; cairo_surface_t *surface; + double preferred_scale; double scale_x; double scale_y; #if defined(CONFIG_OPENGL) diff --git a/ui/gtk.c b/ui/gtk.c index 9104509ee1..e91d093a49 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -67,6 +67,7 @@ #define VC_TERM_X_MIN 80 #define VC_TERM_Y_MIN 25 #define VC_SCALE_MIN 0.25 +#define VC_SCALE_MAX 4 #define VC_SCALE_STEP 0.25 =20 #ifdef GDK_WINDOWING_X11 @@ -272,15 +273,11 @@ static void gd_update_geometry_hints(VirtualConsole *= vc) if (!vc->gfx.ds) { return; } - if (s->free_scale) { - geo.min_width =3D surface_width(vc->gfx.ds) * VC_SCALE_MIN; - geo.min_height =3D surface_height(vc->gfx.ds) * VC_SCALE_MIN; - mask |=3D GDK_HINT_MIN_SIZE; - } else { - geo.min_width =3D surface_width(vc->gfx.ds) * vc->gfx.scale_x; - geo.min_height =3D surface_height(vc->gfx.ds) * vc->gfx.scale_= y; - mask |=3D GDK_HINT_MIN_SIZE; - } + double scale_x =3D s->free_scale ? VC_SCALE_MIN : vc->gfx.scale_x; + double scale_y =3D s->free_scale ? VC_SCALE_MIN : vc->gfx.scale_y; + geo.min_width =3D surface_width(vc->gfx.ds) * scale_x; + geo.min_height =3D surface_height(vc->gfx.ds) * scale_y; + mask |=3D GDK_HINT_MIN_SIZE; geo_widget =3D vc->gfx.drawing_area; gtk_widget_set_size_request(geo_widget, geo.min_width, geo.min_hei= ght); =20 @@ -1579,8 +1576,8 @@ static void gd_menu_full_screen(GtkMenuItem *item, vo= id *opaque) } s->full_screen =3D FALSE; if (vc->type =3D=3D GD_VC_GFX) { - vc->gfx.scale_x =3D 1.0; - vc->gfx.scale_y =3D 1.0; + vc->gfx.scale_x =3D vc->gfx.preferred_scale; + vc->gfx.scale_y =3D vc->gfx.preferred_scale; gd_update_windowsize(vc); } } @@ -1636,8 +1633,8 @@ static void gd_menu_zoom_fixed(GtkMenuItem *item, voi= d *opaque) GtkDisplayState *s =3D opaque; VirtualConsole *vc =3D gd_vc_find_current(s); =20 - vc->gfx.scale_x =3D 1.0; - vc->gfx.scale_y =3D 1.0; + vc->gfx.scale_x =3D vc->gfx.preferred_scale; + vc->gfx.scale_y =3D vc->gfx.preferred_scale; =20 gd_update_windowsize(vc); } @@ -1651,8 +1648,8 @@ static void gd_menu_zoom_fit(GtkMenuItem *item, void = *opaque) s->free_scale =3D TRUE; } else { s->free_scale =3D FALSE; - vc->gfx.scale_x =3D 1.0; - vc->gfx.scale_y =3D 1.0; + vc->gfx.scale_x =3D vc->gfx.preferred_scale; + vc->gfx.scale_y =3D vc->gfx.preferred_scale; } =20 gd_update_windowsize(vc); @@ -2243,6 +2240,11 @@ static void gl_area_realize(GtkGLArea *area, Virtual= Console *vc) } #endif =20 +static bool gd_scale_valid(double scale) +{ + return scale >=3D VC_SCALE_MIN && scale <=3D VC_SCALE_MAX; +} + static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc, QemuConsole *con, int idx, GSList *group, GtkWidget *view_menu) @@ -2252,8 +2254,18 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, Vi= rtualConsole *vc, =20 vc->label =3D qemu_console_get_label(con); vc->s =3D s; - vc->gfx.scale_x =3D 1.0; - vc->gfx.scale_y =3D 1.0; + vc->gfx.preferred_scale =3D 1.0; + if (s->opts->u.gtk.has_scale) { + if (gd_scale_valid(s->opts->u.gtk.scale)) { + vc->gfx.preferred_scale =3D s->opts->u.gtk.scale; + } else { + error_report("Invalid scale value %lf given, being ignored", + s->opts->u.gtk.scale); + s->opts->u.gtk.has_scale =3D false; + } + } + vc->gfx.scale_x =3D vc->gfx.preferred_scale; + vc->gfx.scale_y =3D vc->gfx.preferred_scale; =20 #if defined(CONFIG_OPENGL) if (display_opengl) { --=20 2.50.0