ui/sdl2: Add SDL clipboard support
PATCH 1/1 ui/sdl2: Add SDL clipboard support
From ef834d229fda71f1773f483f4ef6ef7c50e485d0 Mon Sep 17 00:00:00 2001
From: Test User <[email protected]>
Date: Tue, 5 Aug 2025 13:53:00 +0100
Subject: [PATCH] ui/sdl2: Add SDL clipboard support
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Implement bidirectional clipboard integration between QEMU and host system when using the SDL display backend. This allows seamless copy-paste operations between the guest and host environments.
Features:
- Bidirectional clipboard sync (guest <-> host)
- Async clipboard request handling to prevent blocking
- Self-update detection to avoid clipboard manager conflicts
- Configurable via --enable-sdl-clipboard build option
- Text-only clipboard support (following existing QEMU patterns)
The implementation follows the same patterns used by the existing GTK and VNC clipboard implementations, integrating with QEMU's clipboard subsystem through QemuClipboardPeer.
Tested on macOS with successful build and runtime clipboard functionality verification.
--- include/ui/sdl2.h | 12 ++++ meson.build | 3 + meson_options.txt | 2 + ui/meson.build | 3 + ui/sdl2-clipboard.c | 154 ++++++++++++++++++++++++++++++++++++++++++++ ui/sdl2.c | 9 +++ 6 files changed, 183 insertions(+) create mode 100644 ui/sdl2-clipboard.c
include/ui/sdl2.h +12 -0
@@ -21,6 +21,10 @@# include <SDL_image.h> #endif +#ifdef CONFIG_SDL_CLIPBOARD +#include "ui/clipboard.h" +#endif +#include "ui/kbd-state.h" #ifdef CONFIG_OPENGL # include "ui/egl-helpers.h"
@@ -45,6 +49,9 @@ struct sdl2_console {bool gui_keysym;SDL_GLContext winctx;QKbdState *kbd; +#ifdef CONFIG_SDL_CLIPBOARD +QemuClipboardPeer cbpeer; +#endif #ifdef CONFIG_OPENGL QemuGLShader *gls;egl_fb guest_fb;
@@ -97,4 +104,9 @@ void sdl2_gl_scanout_texture(DisplayChangeListener *dcl,void sdl2_gl_scanout_flush (DisplayChangeListener *dcl,uint32_t x,uint32_t y,uint32_t w,uint32_t h); +#ifdef CONFIG_SDL_CLIPBOARD +void sdl2_clipboard_init (struct sdl2_console *scon); +void sdl2_clipboard_handle_request (struct sdl2_console *scon); +#endif +#endif /* SDL2_H */
meson.build +3 -0
@@ -1596,6 +1596,8 @@ else sdl_image = not_found endif +have_sdl_clipboard = sdl.found() and get_option('sdl_clipboard') + rbd = not_found if not get_option('rbd').auto() or have_block librados = cc.find_library('rados', required: get_option('rbd'))
@@ -2511,6 +2513,7 @@ config_host_data.set('CONFIG_RELOCATABLE', get_option('relocatable')) config_host_data.set('CONFIG_SAFESTACK', get_option('safe_stack')) config_host_data.set('CONFIG_SDL', sdl.found()) config_host_data.set('CONFIG_SDL_IMAGE', sdl_image.found()) +config_host_data.set('CONFIG_SDL_CLIPBOARD', have_sdl_clipboard) config_host_data.set('CONFIG_SECCOMP', seccomp.found()) if seccomp.found() config_host_data.set('CONFIG_SECCOMP_SYSRAWRC', seccomp_has_sysrawrc)
meson_options.txt +2 -0
@@ -212,6 +212,8 @@ option('sdl', type : 'feature', value : 'auto', description: 'SDL user interface') option('sdl_image', type : 'feature', value : 'auto', description: 'SDL Image support for icons') +option('sdl_clipboard', type : 'boolean', value : true, + description: 'SDL clipboard support') option('seccomp', type : 'feature', value : 'auto', description: 'seccomp support') option('smartcard', type : 'feature', value : 'auto',
ui/meson.build +3 -0
@@ -126,6 +126,9 @@ if sdl.found() 'sdl2-input.c', 'sdl2.c', )) + if have_sdl_clipboard + sdl_ss.add(files('sdl2-clipboard.c')) + endif sdl_ss.add(when: opengl, if_true: files('sdl2-gl.c')) sdl_ss.add(when: x11, if_true: files('x_keymap.c')) ui_modules += {'sdl' : sdl_ss}
ui/sdl2-clipboard.c new file +154 -0
154 lines not on this page · raw message
ui/sdl2.c +9 -0
@@ -691,6 +691,11 @@ void sdl2_poll_events(struct sdl2_console *scon)case SDL_WINDOWEVENT :handle_windowevent (ev);break ; +#ifdef CONFIG_SDL_CLIPBOARD +case SDL_CLIPBOARDUPDATE : +sdl2_clipboard_handle_request (scon); +break ; +#endif default :break ; }
@@ -901,6 +906,10 @@ static void sdl2_display_init(DisplayState *ds, DisplayOptions *o) }register_displaychangelistener (&sdl2_console[i].dcl); +#ifdef CONFIG_SDL_CLIPBOARD +sdl2_clipboard_init (&sdl2_console[i]); +#endif +#if defined(SDL_VIDEO_DRIVER_WINDOWS ) || defined(SDL_VIDEO_DRIVER_X11 )if (SDL_GetWindowWMInfo (sdl2_console[i].real_window, &info)) {#if defined(SDL_VIDEO_DRIVER_WINDOWS )
Signature · 1 line
2.50.1