ui/gtk: Turn clipboard flag into runtime option

- Compile the GTK clipboard support unconditionally

- Introduce GTK clipboard option, defaulting to off

Signed-off-by: Jindrich Makovicka <makovick@gmail.com>
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-ID: <20260427-gtk-clipboard-v5-2-6968feb31a5d@gmail.com>
This commit is contained in:
Jindřich Makovička
2026-04-27 22:06:44 +02:00
committed by Marc-André Lureau
parent 9a007326e8
commit 335e32cbd0
7 changed files with 17 additions and 24 deletions

View File

@@ -1932,7 +1932,6 @@ endif
gtk = not_found
gtkx11 = not_found
vte = not_found
have_gtk_clipboard = get_option('gtk_clipboard').enabled()
if get_option('gtk') \
.disable_auto_if(not have_system) \
@@ -1954,8 +1953,6 @@ if get_option('gtk') \
method: 'pkg-config',
required: get_option('vte'))
endif
elif have_gtk_clipboard
error('GTK clipboard requested, but GTK not found')
endif
endif
@@ -2475,7 +2472,6 @@ if glusterfs.found()
endif
config_host_data.set('CONFIG_GTK', gtk.found())
config_host_data.set('CONFIG_VTE', vte.found())
config_host_data.set('CONFIG_GTK_CLIPBOARD', have_gtk_clipboard)
config_host_data.set('CONFIG_HEXAGON_IDEF_PARSER', get_option('hexagon_idef_parser'))
config_host_data.set('CONFIG_LIBATTR', have_old_libattr)
config_host_data.set('CONFIG_LIBCAP_NG', libcap_ng.found())

View File

@@ -262,13 +262,6 @@ option('vnc_sasl', type : 'feature', value : 'auto',
description: 'SASL authentication for VNC server')
option('vte', type : 'feature', value : 'auto',
description: 'vte support for the gtk UI')
# GTK Clipboard implementation is disabled by default, since it may cause hangs
# of the guest VCPUs. See gitlab issue 1150:
# https://gitlab.com/qemu-project/qemu/-/issues/1150
option('gtk_clipboard', type: 'feature', value : 'disabled',
description: 'clipboard support for the gtk UI (EXPERIMENTAL, MAY HANG)')
option('xkbcommon', type : 'feature', value : 'auto',
description: 'xkbcommon support')
option('zstd', type : 'feature', value : 'auto',

View File

@@ -1319,6 +1319,9 @@
#
# GTK display options.
#
# @clipboard: Enable host-guest clipboard sharing. Defaults to "off".
# (Since 11.1)
#
# @grab-on-hover: Grab keyboard input on mouse hover.
#
# @zoom-to-fit: Zoom guest display to fit into the host window. When
@@ -1344,7 +1347,8 @@
# Since: 2.12
##
{ 'struct' : 'DisplayGTK',
'data' : { '*grab-on-hover' : 'bool',
'data' : { '*clipboard' : 'bool',
'*grab-on-hover' : 'bool',
'*zoom-to-fit' : 'bool',
'*show-tabs' : 'bool',
'*show-menubar' : 'bool',

View File

@@ -2209,9 +2209,9 @@ DEF("display", HAS_ARG, QEMU_OPTION_display,
" [,window-close=on|off]\n"
#endif
#if defined(CONFIG_GTK)
"-display gtk[,full-screen=on|off][,gl=on|off][,grab-on-hover=on|off]\n"
" [,show-tabs=on|off][,show-cursor=on|off][,window-close=on|off]\n"
" [,show-menubar=on|off][,zoom-to-fit=on|off]\n"
"-display gtk[,clipboard=on|off][,full-screen=on|off][,gl=on|off]\n"
" [,grab-on-hover=on|off][,show-tabs=on|off][,show-cursor=on|off]\n"
" [,window-close=on|off][,show-menubar=on|off][,zoom-to-fit=on|off]\n"
#endif
#if defined(CONFIG_VNC)
"-display vnc=<display>[,<optargs>]\n"
@@ -2295,6 +2295,9 @@ SRST
drop-down menus and other UI elements to configure and control
the VM during runtime. Valid parameters are:
``clipboard=on|off`` : Enable host-guest clipboard sharing,
defaults to "off"
``full-screen=on|off`` : Start in fullscreen mode
``gl=on|off`` : Use OpenGL for displaying

View File

@@ -124,7 +124,6 @@ meson_options_help() {
printf "%s\n" ' glusterfs Glusterfs block device driver'
printf "%s\n" ' gnutls GNUTLS cryptography support'
printf "%s\n" ' gtk GTK+ user interface'
printf "%s\n" ' gtk-clipboard clipboard support for the gtk UI (EXPERIMENTAL, MAY HANG)'
printf "%s\n" ' guest-agent Build QEMU Guest Agent'
printf "%s\n" ' guest-agent-msi Build MSI package for the QEMU Guest Agent'
printf "%s\n" ' hv-balloon hv-balloon driver (requires Glib 2.68+ GTree API)'
@@ -336,8 +335,6 @@ _meson_option_parse() {
--disable-gnutls) printf "%s" -Dgnutls=disabled ;;
--enable-gtk) printf "%s" -Dgtk=enabled ;;
--disable-gtk) printf "%s" -Dgtk=disabled ;;
--enable-gtk-clipboard) printf "%s" -Dgtk_clipboard=enabled ;;
--disable-gtk-clipboard) printf "%s" -Dgtk_clipboard=disabled ;;
--enable-guest-agent) printf "%s" -Dguest_agent=enabled ;;
--disable-guest-agent) printf "%s" -Dguest_agent=disabled ;;
--enable-guest-agent-msi) printf "%s" -Dguest_agent_msi=enabled ;;

View File

@@ -2601,9 +2601,11 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
opts->u.gtk.show_tabs) {
gtk_menu_item_activate(GTK_MENU_ITEM(s->show_tabs_item));
}
#ifdef CONFIG_GTK_CLIPBOARD
gd_clipboard_init(s);
#endif /* CONFIG_GTK_CLIPBOARD */
if (opts->u.gtk.has_clipboard &&
opts->u.gtk.clipboard) {
gd_clipboard_init(s);
}
/* GTK's event polling must happen on the main thread. */
qemu_main = NULL;

View File

@@ -112,9 +112,7 @@ if gtk.found()
gtk_ss = ss.source_set()
gtk_ss.add(gtk, vte, pixman, files('gtk.c'))
if have_gtk_clipboard
gtk_ss.add(files('gtk-clipboard.c'))
endif
gtk_ss.add(files('gtk-clipboard.c'))
gtk_ss.add(when: x11, if_true: files('x_keymap.c'))
gtk_ss.add(when: opengl, if_true: files('gtk-gl-area.c'))
gtk_ss.add(when: [x11, opengl], if_true: files('gtk-egl.c'))