diff options
author | Weifeng Liu <weifeng.liu.z@gmail.com> | 2025-06-01 12:52:32 +0800 |
---|---|---|
committer | Marc-André Lureau <marcandre.lureau@redhat.com> | 2025-07-15 10:22:33 +0400 |
commit | c65680a76c190d187be1bfd18207b22227541d77 (patch) | |
tree | 8093afc462fcaa28e9bb95699888485eef69b317 | |
parent | 454f4b0f593b149c7a6d8192e1ed3de00de9ae24 (diff) | |
download | qemu-c65680a76c190d187be1bfd18207b22227541d77.zip qemu-c65680a76c190d187be1bfd18207b22227541d77.tar.gz qemu-c65680a76c190d187be1bfd18207b22227541d77.tar.bz2 |
ui/gtk: Add keep-aspect-ratio option
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>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Tested-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20250601045245.36778-2-weifeng.liu.z@gmail.com>
-rw-r--r-- | include/ui/gtk.h | 1 | ||||
-rw-r--r-- | qapi/ui.json | 12 | ||||
-rw-r--r-- | ui/gtk.c | 12 |
3 files changed, 19 insertions, 6 deletions
diff --git a/include/ui/gtk.h b/include/ui/gtk.h index d394404..b7cfbf2 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 514fa15..9e496b4 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: @@ -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; |