@samitouri / QOSamiQemu / commits / 335e32cbd0

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>

Jindřich Makovička committed Apr 27, 2026 at 22:06 UTC 335e32cbd0a24f13e326d96dd30318cd78740c60
7 files changed +17 -24
meson.build
-4
@@ -1932,7 +1932,6 @@ endif
1932 gtk = not_found
1933 gtkx11 = not_found
1934 vte = not_found
1935 -have_gtk_clipboard = get_option('gtk_clipboard').enabled()
1935
1936 if get_option('gtk') \
1937 .disable_auto_if(not have_system) \
@@ -1954,8 +1953,6 @@ if get_option('gtk') \
1953 method: 'pkg-config',
1954 required: get_option('vte'))
1955 endif
1957 - elif have_gtk_clipboard
1958 - error('GTK clipboard requested, but GTK not found')
1956 endif
1957 endif
1958
@@ -2475,7 +2472,6 @@ if glusterfs.found()
2472 endif
2473 config_host_data.set('CONFIG_GTK', gtk.found())
2474 config_host_data.set('CONFIG_VTE', vte.found())
2478 -config_host_data.set('CONFIG_GTK_CLIPBOARD', have_gtk_clipboard)
2475 config_host_data.set('CONFIG_HEXAGON_IDEF_PARSER', get_option('hexagon_idef_parser'))
2476 config_host_data.set('CONFIG_LIBATTR', have_old_libattr)
2477 config_host_data.set('CONFIG_LIBCAP_NG', libcap_ng.found())
meson_options.txt
-7
@@ -262,13 +262,6 @@ option('vnc_sasl', type : 'feature', value : 'auto',
262 description: 'SASL authentication for VNC server')
263 option('vte', type : 'feature', value : 'auto',
264 description: 'vte support for the gtk UI')
265 -
266 -# GTK Clipboard implementation is disabled by default, since it may cause hangs
267 -# of the guest VCPUs. See gitlab issue 1150:
268 -# https://gitlab.com/qemu-project/qemu/-/issues/1150
269 -
270 -option('gtk_clipboard', type: 'feature', value : 'disabled',
271 - description: 'clipboard support for the gtk UI (EXPERIMENTAL, MAY HANG)')
265 option('xkbcommon', type : 'feature', value : 'auto',
266 description: 'xkbcommon support')
267 option('zstd', type : 'feature', value : 'auto',
qapi/ui.json
+5 -1
@@ -1319,6 +1319,9 @@
1319 #
1320 # GTK display options.
1321 #
1322 +# @clipboard: Enable host-guest clipboard sharing. Defaults to "off".
1323 +# (Since 11.1)
1324 +#
1325 # @grab-on-hover: Grab keyboard input on mouse hover.
1326 #
1327 # @zoom-to-fit: Zoom guest display to fit into the host window. When
@@ -1344,7 +1347,8 @@
1347 # Since: 2.12
1348 ##
1349 { 'struct' : 'DisplayGTK',
1347 - 'data' : { '*grab-on-hover' : 'bool',
1350 + 'data' : { '*clipboard' : 'bool',
1351 + '*grab-on-hover' : 'bool',
1352 '*zoom-to-fit' : 'bool',
1353 '*show-tabs' : 'bool',
1354 '*show-menubar' : 'bool',
qemu-options.hx
+6 -3
@@ -2209,9 +2209,9 @@ DEF("display", HAS_ARG, QEMU_OPTION_display,
2209 " [,window-close=on|off]\n"
2210 #endif
2211 #if defined(CONFIG_GTK)
2212 - "-display gtk[,full-screen=on|off][,gl=on|off][,grab-on-hover=on|off]\n"
2213 - " [,show-tabs=on|off][,show-cursor=on|off][,window-close=on|off]\n"
2214 - " [,show-menubar=on|off][,zoom-to-fit=on|off]\n"
2212 + "-display gtk[,clipboard=on|off][,full-screen=on|off][,gl=on|off]\n"
2213 + " [,grab-on-hover=on|off][,show-tabs=on|off][,show-cursor=on|off]\n"
2214 + " [,window-close=on|off][,show-menubar=on|off][,zoom-to-fit=on|off]\n"
2215 #endif
2216 #if defined(CONFIG_VNC)
2217 "-display vnc=<display>[,<optargs>]\n"
@@ -2295,6 +2295,9 @@ SRST
2295 drop-down menus and other UI elements to configure and control
2296 the VM during runtime. Valid parameters are:
2297
2298 + ``clipboard=on|off`` : Enable host-guest clipboard sharing,
2299 + defaults to "off"
2300 +
2301 ``full-screen=on|off`` : Start in fullscreen mode
2302
2303 ``gl=on|off`` : Use OpenGL for displaying
scripts/meson-buildoptions.sh
-3
@@ -124,7 +124,6 @@ meson_options_help() {
124 printf "%s\n" ' glusterfs Glusterfs block device driver'
125 printf "%s\n" ' gnutls GNUTLS cryptography support'
126 printf "%s\n" ' gtk GTK+ user interface'
127 - printf "%s\n" ' gtk-clipboard clipboard support for the gtk UI (EXPERIMENTAL, MAY HANG)'
127 printf "%s\n" ' guest-agent Build QEMU Guest Agent'
128 printf "%s\n" ' guest-agent-msi Build MSI package for the QEMU Guest Agent'
129 printf "%s\n" ' hv-balloon hv-balloon driver (requires Glib 2.68+ GTree API)'
@@ -336,8 +335,6 @@ _meson_option_parse() {
335 --disable-gnutls) printf "%s" -Dgnutls=disabled ;;
336 --enable-gtk) printf "%s" -Dgtk=enabled ;;
337 --disable-gtk) printf "%s" -Dgtk=disabled ;;
339 - --enable-gtk-clipboard) printf "%s" -Dgtk_clipboard=enabled ;;
340 - --disable-gtk-clipboard) printf "%s" -Dgtk_clipboard=disabled ;;
338 --enable-guest-agent) printf "%s" -Dguest_agent=enabled ;;
339 --disable-guest-agent) printf "%s" -Dguest_agent=disabled ;;
340 --enable-guest-agent-msi) printf "%s" -Dguest_agent_msi=enabled ;;
ui/gtk.c
+5 -3
@@ -2601,9 +2601,11 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
2601 opts->u.gtk.show_tabs) {
2602 gtk_menu_item_activate(GTK_MENU_ITEM(s->show_tabs_item));
2603 }
2604 -#ifdef CONFIG_GTK_CLIPBOARD
2605 - gd_clipboard_init(s);
2606 -#endif /* CONFIG_GTK_CLIPBOARD */
2604 +
2605 + if (opts->u.gtk.has_clipboard &&
2606 + opts->u.gtk.clipboard) {
2607 + gd_clipboard_init(s);
2608 + }
2609
2610 /* GTK's event polling must happen on the main thread. */
2611 qemu_main = NULL;
ui/meson.build
+1 -3
@@ -112,9 +112,7 @@ if gtk.found()
112
113 gtk_ss = ss.source_set()
114 gtk_ss.add(gtk, vte, pixman, files('gtk.c'))
115 - if have_gtk_clipboard
116 - gtk_ss.add(files('gtk-clipboard.c'))
117 - endif
115 + gtk_ss.add(files('gtk-clipboard.c'))
116 gtk_ss.add(when: x11, if_true: files('x_keymap.c'))
117 gtk_ss.add(when: opengl, if_true: files('gtk-gl-area.c'))
118 gtk_ss.add(when: [x11, opengl], if_true: files('gtk-egl.c'))