From: Weifeng Liu <weifeng.liu.z@gmail.com>
To: qemu-devel@nongnu.org
Cc: Weifeng Liu <weifeng.liu.z@gmail.com>
Subject: [PATCH 7/9] ui/gtk: Consider scaling when propagating ui info
Date: Sun, 11 May 2025 15:33:17 +0800 [thread overview]
Message-ID: <20250511073337.876650-8-weifeng.liu.z@gmail.com> (raw)
In-Reply-To: <20250511073337.876650-1-weifeng.liu.z@gmail.com>
The ui width and height sent to guest is supposed to be in buffer
coordinate. Hence conversion is required.
If scaling (global window scale and zooming scale) is not respected in
non-free-scale mode, window size could keep changing because of the
existence of the iteration of the following steps:
1. In resize event or configure event, a size larger (or smaller) than
the currently used one might be calculated due to not considering
scaling.
2. On reception of the display size change event in guest, the guest
might decide to do a mode setting and use the larger (or smaller)
mode.
3. When the new guest scan-out command arrives, QEMU would request the
window size to change to fit the new buffer size. This will trigger a
resize event or a configure event, making us go back to step 1.
Signed-off-by: Weifeng Liu <weifeng.liu.z@gmail.com>
---
ui/gtk.c | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/ui/gtk.c b/ui/gtk.c
index 47af49e387..8c4a94c8f6 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -772,8 +772,21 @@ static void gd_resize_event(GtkGLArea *area,
gint width, gint height, gpointer *opaque)
{
VirtualConsole *vc = (void *)opaque;
+ double pw = width, ph = height;
+ double sx = vc->gfx.scale_x, sy = vc->gfx.scale_y;
+ GdkWindow *window = gtk_widget_get_window(GTK_WIDGET(area));
+ const int gs = gdk_window_get_scale_factor(window);
- gd_set_ui_size(vc, width, height);
+ if (!vc->s->free_scale && !vc->s->full_screen) {
+ pw /= sx;
+ ph /= sy;
+ }
+
+ /**
+ * width and height here are in pixel coordinate, so we must divide it
+ * by global window scale (gs)
+ */
+ gd_set_ui_size(vc, pw / gs, ph / gs);
}
#endif
@@ -1836,8 +1849,16 @@ static gboolean gd_configure(GtkWidget *widget,
GdkEventConfigure *cfg, gpointer opaque)
{
VirtualConsole *vc = opaque;
+ const double sx = vc->gfx.scale_x, sy = vc->gfx.scale_y;
+ double width = cfg->width, height = cfg->height;
+
+ if (!vc->s->free_scale && !vc->s->full_screen) {
+ width /= sx;
+ height /= sy;
+ }
+
+ gd_set_ui_size(vc, width, height);
- gd_set_ui_size(vc, cfg->width, cfg->height);
return FALSE;
}
--
2.49.0
next prev parent reply other threads:[~2025-05-11 7:35 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-11 7:33 [PATCH 0/9] ui: Improve scale handling Weifeng Liu
2025-05-11 7:33 ` [PATCH 1/9] ui/gtk: Document scale and coordinate handling Weifeng Liu
2025-05-12 11:46 ` Gerd Hoffmann
2025-05-14 2:50 ` Weifeng Liu
2025-05-14 11:50 ` BALATON Zoltan
2025-05-15 5:55 ` Weifeng Liu
2025-05-11 7:33 ` [PATCH 2/9] ui/gtk: Use consistent naming for variables in different coordinates Weifeng Liu
2025-05-11 7:33 ` [PATCH 3/9] gtk/ui: Introduce helper gd_update_scale Weifeng Liu
2025-05-13 1:26 ` Kim, Dongwon
2025-05-13 2:08 ` Weifeng Liu
2025-05-13 20:01 ` Kim, Dongwon
2025-05-14 2:12 ` Weifeng Liu
2025-05-11 7:33 ` [PATCH 4/9] ui/gtk: Update scales in fixed-scale mode when rendering GL area Weifeng Liu
2025-05-11 7:33 ` [PATCH 5/9] ui/sdl: Consider scaling in mouse event handling Weifeng Liu
2025-05-11 7:33 ` [PATCH 6/9] ui/gtk: Don't update scale in fixed scale mode in gtk-egl.c Weifeng Liu
2025-05-11 7:33 ` Weifeng Liu [this message]
2025-05-11 7:33 ` [PATCH 8/9] ui/gtk-gl-area: Render guest content with padding in fixed-scale mode Weifeng Liu
2025-05-13 0:37 ` Kim, Dongwon
2025-05-13 2:28 ` Weifeng Liu
2025-05-13 9:52 ` BALATON Zoltan
2025-05-13 12:44 ` Weifeng Liu
2025-05-13 13:42 ` BALATON Zoltan
2025-05-11 7:33 ` [PATCH 9/9] ui/gtk-egl: " Weifeng Liu
2025-05-12 11:49 ` [PATCH 0/9] ui: Improve scale handling Gerd Hoffmann
2025-05-29 7:23 ` Michael Tokarev
2025-05-30 6:39 ` Weifeng Liu
2025-05-30 10:44 ` Michael Tokarev
2025-05-30 10:56 ` Michael Tokarev
2025-06-01 8:23 ` Weifeng Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250511073337.876650-8-weifeng.liu.z@gmail.com \
--to=weifeng.liu.z@gmail.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).