* [PATCH 0/2] ui/gtk: Add keep-aspect-ratio and scale option
@ 2025-06-01 4:52 Weifeng Liu
2025-06-01 4:52 ` [PATCH 1/2] ui/gtk: Add keep-aspect-ratio option Weifeng Liu
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Weifeng Liu @ 2025-06-01 4:52 UTC (permalink / raw)
To: qemu-devel
Cc: Weifeng Liu, BALATON Zoltan, Gerd Hoffmann,
Marc-André Lureau, Marc-André Lureau, Kim, Dongwon,
Dmitry Osipenko, Alex Bennée
Add these options to give users more control over behaviors in gtk
display backend:
- keep-aspect-ratio: when set to true, if the aspect ratio of host
window differs from that of guest frame-buffer, padding will be added
to the host window to preserve the aspect ratio of guest frame-buffer.
- scale: allow user to set a preferred scale factor, which would be
helpful for users running on a hi-dpi desktop to achieve pixel to
pixel display.
Cc: BALATON Zoltan <balaton@eik.bme.hu>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Cc: Marc-André Lureau <marcandre.lureau@gmail.com>
Cc: "Kim, Dongwon" <dongwon.kim@intel.com>
Cc: Alex Bennée <alex.bennee@linaro.org>
Cc: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Best regards,
Weifeng
Weifeng Liu (2):
ui/gtk: Add keep-aspect-ratio option
ui/gtk: Add scale option
include/ui/gtk.h | 2 ++
qapi/ui.json | 15 +++++++++----
ui/gtk.c | 58 ++++++++++++++++++++++++++++++++----------------
3 files changed, 52 insertions(+), 23 deletions(-)
--
2.49.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/2] ui/gtk: Add keep-aspect-ratio option
2025-06-01 4:52 [PATCH 0/2] ui/gtk: Add keep-aspect-ratio and scale option Weifeng Liu
@ 2025-06-01 4:52 ` Weifeng Liu
2025-06-01 4:52 ` [PATCH 2/2] ui/gtk: Add scale option Weifeng Liu
2025-06-03 8:21 ` [PATCH 0/2] ui/gtk: Add keep-aspect-ratio and " Marc-André Lureau
2 siblings, 0 replies; 4+ messages in thread
From: Weifeng Liu @ 2025-06-01 4:52 UTC (permalink / raw)
To: qemu-devel
Cc: Weifeng Liu, BALATON Zoltan, Gerd Hoffmann,
Marc-André Lureau, Marc-André Lureau, Kim, Dongwon,
Dmitry Osipenko, Alex Bennée
When aspect ratio of host window and that of guest display are not
aligned, we can either zoom the guest content to fill the whole host
window or add padding to respect aspect ratio of the guest. Add an
option keep-aspect-ratio to allow users to select their preferred
behavior in this case.
Suggested-by: BALATON Zoltan <balaton@eik.bme.hu>
Suggested-by: Kim, Dongwon <dongwon.kim@intel.com>
Signed-off-by: Weifeng Liu <weifeng.liu.z@gmail.com>
---
include/ui/gtk.h | 1 +
qapi/ui.json | 12 ++++++++----
ui/gtk.c | 12 ++++++++++--
3 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/include/ui/gtk.h b/include/ui/gtk.h
index d3944046db..b7cfbf218e 100644
--- a/include/ui/gtk.h
+++ b/include/ui/gtk.h
@@ -140,6 +140,7 @@ struct GtkDisplayState {
GdkCursor *null_cursor;
Notifier mouse_mode_notifier;
gboolean free_scale;
+ gboolean keep_aspect_ratio;
bool external_pause_update;
diff --git a/qapi/ui.json b/qapi/ui.json
index 3d0c853c9a..4f7d994e26 100644
--- a/qapi/ui.json
+++ b/qapi/ui.json
@@ -1335,13 +1335,17 @@
# @show-menubar: Display the main window menubar. Defaults to "on".
# (Since 8.0)
#
+# @keep-aspect-ratio: Keep width/height aspect ratio of guest content when
+# resizing host window. Defaults to "on". (Since 10.1)
+#
# Since: 2.12
##
{ 'struct' : 'DisplayGTK',
- 'data' : { '*grab-on-hover' : 'bool',
- '*zoom-to-fit' : 'bool',
- '*show-tabs' : 'bool',
- '*show-menubar' : 'bool' } }
+ 'data' : { '*grab-on-hover' : 'bool',
+ '*zoom-to-fit' : 'bool',
+ '*show-tabs' : 'bool',
+ '*show-menubar' : 'bool',
+ '*keep-aspect-ratio' : 'bool' } }
##
# @DisplayEGLHeadless:
diff --git a/ui/gtk.c b/ui/gtk.c
index 8c4a94c8f6..9104509ee1 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -828,8 +828,12 @@ void gd_update_scale(VirtualConsole *vc, int ww, int wh, int fbw, int fbh)
sx = (double)ww / fbw;
sy = (double)wh / fbh;
-
- vc->gfx.scale_x = vc->gfx.scale_y = MIN(sx, sy);
+ if (vc->s->keep_aspect_ratio) {
+ vc->gfx.scale_x = vc->gfx.scale_y = MIN(sx, sy);
+ } else {
+ vc->gfx.scale_x = sx;
+ vc->gfx.scale_y = sy;
+ }
}
}
/**
@@ -2328,6 +2332,10 @@ static GSList *gd_vc_gfx_init(GtkDisplayState *s, VirtualConsole *vc,
s->free_scale = true;
}
+ s->keep_aspect_ratio = true;
+ if (s->opts->u.gtk.has_keep_aspect_ratio)
+ s->keep_aspect_ratio = s->opts->u.gtk.keep_aspect_ratio;
+
for (i = 0; i < INPUT_EVENT_SLOTS_MAX; i++) {
struct touch_slot *slot = &touch_slots[i];
slot->tracking_id = -1;
--
2.49.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] ui/gtk: Add scale option
2025-06-01 4:52 [PATCH 0/2] ui/gtk: Add keep-aspect-ratio and scale option Weifeng Liu
2025-06-01 4:52 ` [PATCH 1/2] ui/gtk: Add keep-aspect-ratio option Weifeng Liu
@ 2025-06-01 4:52 ` Weifeng Liu
2025-06-03 8:21 ` [PATCH 0/2] ui/gtk: Add keep-aspect-ratio and " Marc-André Lureau
2 siblings, 0 replies; 4+ messages in thread
From: Weifeng Liu @ 2025-06-01 4:52 UTC (permalink / raw)
To: qemu-devel
Cc: Weifeng Liu, BALATON Zoltan, Gerd Hoffmann,
Marc-André Lureau, Marc-André Lureau, Kim, Dongwon,
Dmitry Osipenko, Alex Bennée
Allow user to set a preferred scale (defaulting to 1) of the virtual
display. Along with zoom-to-fix=false, 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 <weifeng.liu.z@gmail.com>
---
include/ui/gtk.h | 1 +
qapi/ui.json | 5 ++++-
ui/gtk.c | 46 +++++++++++++++++++++++++++++-----------------
3 files changed, 34 insertions(+), 18 deletions(-)
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/qapi/ui.json b/qapi/ui.json
index 4f7d994e26..023d055ef1 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' } }
##
# @DisplayEGLHeadless:
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
#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 = surface_width(vc->gfx.ds) * VC_SCALE_MIN;
- geo.min_height = surface_height(vc->gfx.ds) * VC_SCALE_MIN;
- mask |= GDK_HINT_MIN_SIZE;
- } else {
- geo.min_width = surface_width(vc->gfx.ds) * vc->gfx.scale_x;
- geo.min_height = surface_height(vc->gfx.ds) * vc->gfx.scale_y;
- mask |= GDK_HINT_MIN_SIZE;
- }
+ double scale_x = s->free_scale ? VC_SCALE_MIN : vc->gfx.scale_x;
+ double scale_y = s->free_scale ? VC_SCALE_MIN : vc->gfx.scale_y;
+ geo.min_width = surface_width(vc->gfx.ds) * scale_x;
+ geo.min_height = surface_height(vc->gfx.ds) * scale_y;
+ mask |= GDK_HINT_MIN_SIZE;
geo_widget = vc->gfx.drawing_area;
gtk_widget_set_size_request(geo_widget, geo.min_width, geo.min_height);
@@ -1579,8 +1576,8 @@ static void gd_menu_full_screen(GtkMenuItem *item, void *opaque)
}
s->full_screen = FALSE;
if (vc->type == GD_VC_GFX) {
- vc->gfx.scale_x = 1.0;
- vc->gfx.scale_y = 1.0;
+ vc->gfx.scale_x = vc->gfx.preferred_scale;
+ vc->gfx.scale_y = vc->gfx.preferred_scale;
gd_update_windowsize(vc);
}
}
@@ -1636,8 +1633,8 @@ static void gd_menu_zoom_fixed(GtkMenuItem *item, void *opaque)
GtkDisplayState *s = opaque;
VirtualConsole *vc = gd_vc_find_current(s);
- vc->gfx.scale_x = 1.0;
- vc->gfx.scale_y = 1.0;
+ vc->gfx.scale_x = vc->gfx.preferred_scale;
+ vc->gfx.scale_y = vc->gfx.preferred_scale;
gd_update_windowsize(vc);
}
@@ -1651,8 +1648,8 @@ static void gd_menu_zoom_fit(GtkMenuItem *item, void *opaque)
s->free_scale = TRUE;
} else {
s->free_scale = FALSE;
- vc->gfx.scale_x = 1.0;
- vc->gfx.scale_y = 1.0;
+ vc->gfx.scale_x = vc->gfx.preferred_scale;
+ vc->gfx.scale_y = vc->gfx.preferred_scale;
}
gd_update_windowsize(vc);
@@ -2243,6 +2240,11 @@ static void gl_area_realize(GtkGLArea *area, VirtualConsole *vc)
}
#endif
+static bool gd_scale_valid(double scale)
+{
+ return scale >= VC_SCALE_MIN && scale <= 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, VirtualConsole *vc,
vc->label = qemu_console_get_label(con);
vc->s = s;
- vc->gfx.scale_x = 1.0;
- vc->gfx.scale_y = 1.0;
+ vc->gfx.preferred_scale = 1.0;
+ if (s->opts->u.gtk.has_scale) {
+ if (gd_scale_valid(s->opts->u.gtk.scale)) {
+ vc->gfx.preferred_scale = 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 = false;
+ }
+ }
+ vc->gfx.scale_x = vc->gfx.preferred_scale;
+ vc->gfx.scale_y = vc->gfx.preferred_scale;
#if defined(CONFIG_OPENGL)
if (display_opengl) {
--
2.49.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 0/2] ui/gtk: Add keep-aspect-ratio and scale option
2025-06-01 4:52 [PATCH 0/2] ui/gtk: Add keep-aspect-ratio and scale option Weifeng Liu
2025-06-01 4:52 ` [PATCH 1/2] ui/gtk: Add keep-aspect-ratio option Weifeng Liu
2025-06-01 4:52 ` [PATCH 2/2] ui/gtk: Add scale option Weifeng Liu
@ 2025-06-03 8:21 ` Marc-André Lureau
2 siblings, 0 replies; 4+ messages in thread
From: Marc-André Lureau @ 2025-06-03 8:21 UTC (permalink / raw)
To: Weifeng Liu
Cc: qemu-devel, BALATON Zoltan, Gerd Hoffmann, Marc-André Lureau,
Kim, Dongwon, Dmitry Osipenko, Alex Bennée
[-- Attachment #1: Type: text/plain, Size: 1387 bytes --]
On Sun, Jun 1, 2025 at 8:53 AM Weifeng Liu <weifeng.liu.z@gmail.com> wrote:
> Add these options to give users more control over behaviors in gtk
> display backend:
>
> - keep-aspect-ratio: when set to true, if the aspect ratio of host
> window differs from that of guest frame-buffer, padding will be added
> to the host window to preserve the aspect ratio of guest frame-buffer.
>
> - scale: allow user to set a preferred scale factor, which would be
> helpful for users running on a hi-dpi desktop to achieve pixel to
> pixel display.
>
> Cc: BALATON Zoltan <balaton@eik.bme.hu>
> Cc: Gerd Hoffmann <kraxel@redhat.com>
> Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
> Cc: Marc-André Lureau <marcandre.lureau@gmail.com>
> Cc: "Kim, Dongwon" <dongwon.kim@intel.com>
> Cc: Alex Bennée <alex.bennee@linaro.org>
> Cc: Dmitry Osipenko <dmitry.osipenko@collabora.com>
>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Tested-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> Best regards,
> Weifeng
>
> Weifeng Liu (2):
> ui/gtk: Add keep-aspect-ratio option
> ui/gtk: Add scale option
>
> include/ui/gtk.h | 2 ++
> qapi/ui.json | 15 +++++++++----
> ui/gtk.c | 58 ++++++++++++++++++++++++++++++++----------------
> 3 files changed, 52 insertions(+), 23 deletions(-)
>
> --
> 2.49.0
>
>
[-- Attachment #2: Type: text/html, Size: 2576 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-06-03 8:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-01 4:52 [PATCH 0/2] ui/gtk: Add keep-aspect-ratio and scale option Weifeng Liu
2025-06-01 4:52 ` [PATCH 1/2] ui/gtk: Add keep-aspect-ratio option Weifeng Liu
2025-06-01 4:52 ` [PATCH 2/2] ui/gtk: Add scale option Weifeng Liu
2025-06-03 8:21 ` [PATCH 0/2] ui/gtk: Add keep-aspect-ratio and " Marc-André Lureau
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).