Skip to contentSkip to conversation

ui/sdl2: Add SDL clipboard support

PATCH In review startergo via 3 participants 3 messages Aug 5, 2025 – Aug 8, 2025 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ui/sdl2: Add SDL clipboard support

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
index dbe6e3d973..0cadbe8c1c 100644
@@ -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
index 41f68d3806..4a37df9669 100644
@@ -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
index 59d973bca0..be2cba3a30 100644
@@ -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
index 35fb04cadf..6d1bf3477e 100644
@@ -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
index cda4293a53..00a17b68a7 100644
@@ -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
#1 lore raw

Hi

Quoted 16 lines · startergo via

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.

Quoted 5 lines

Tested on macOS with successful build and runtime clipboard functionality verification.

Thanks for sending a patch that can be applied with git am !

Next time, make sure it passes checkpatch too:
https://www.qemu.org/docs/master/devel/submitting-a-patch.html#writing-your-patches

Quoted 50 lines
---
 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
index dbe6e3d973..0cadbe8c1c 100644
@@ -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 +0 -0
index 41f68d3806..4a37df9669 100644

meson.build else · line 1599

Quoted 4 lines
meson.build +1 -0
@@ -1596,6 +1596,8 @@ else
   sdl_image = not_found
 endif
 
+have_sdl_clipboard = sdl.found() and get_option('sdl_clipboard')

you should handle the option the same way as gtk_clipboard: fail if requested but sdl not enabled, make it a feature, disabled by default ? etc

Quoted 45 lines
meson.build +2 -0
+
 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
index 59d973bca0..be2cba3a30 100644
@@ -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
index 35fb04cadf..6d1bf3477e 100644
@@ -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 +0 -0
new file mode 100644
index 0000000000..e50ff11d5a

ui/sdl2-clipboard.c line 3

Quoted 3 lines
ui/sdl2-clipboard.c new file +3 -0
@@ -0,0 +1,154 @@
+/*
+ * SDL UI -- clipboard support (improved async version)
+ *

drop the "(improved async version)"

ui/sdl2-clipboard.c line 16

Quoted 13 lines
ui/sdl2-clipboard.c new file +13 -0
+ * Copyright (C) 2023 Kamay Xutax <[email protected]>
+ * Copyright (C) 2025 startergo <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "ui/console.h"
+#include "ui/clipboard.h"
+#include "ui/sdl2.h"
+#include "qemu/log.h"
+
+#ifdef CONFIG_SDL_CLIPBOARD

this condition is unnecessary if the unit is already filtered out by meson

Quoted 8 lines
ui/sdl2-clipboard.c new file +8 -0
+
+/* Track pending clipboard requests to handle async data */
+typedef struct {
+    struct sdl2_console *scon;
+    QemuClipboardInfo *info;
+    QemuClipboardType type;
+} SDLClipboardRequest;
+

ui/sdl2-clipboard.c line 34

Quoted 10 lines
ui/sdl2-clipboard.c new file +10 -0
+static SDLClipboardRequest *pending_request = NULL;
+
+static void sdl2_clipboard_clear_pending(void)
+{
+    if (pending_request) {
+        if (pending_request->info) {
+            qemu_clipboard_info_unref(pending_request->info);
+        }
+        g_free(pending_request);
+        pending_request = NULL;

or g_clear_pointer(&pending_request, g_free)

Quoted 28 lines
ui/sdl2-clipboard.c new file +28 -0
+    }
+}
+
+static void sdl2_clipboard_notify(Notifier *notifier, void *data)
+{
+    QemuClipboardNotify *notify = data;
+    struct sdl2_console *scon =
+        container_of(notifier, struct sdl2_console, cbpeer.notifier);
+    bool self_update = notify->info->owner == &scon->cbpeer;
+    const char *text_data;
+    size_t text_size;
+
+    switch (notify->type) {
+    case QEMU_CLIPBOARD_UPDATE_INFO:
+        {
+            /* Skip self-updates to avoid clipboard manager conflicts */
+            if (self_update) {
+                return;
+            }
+
+            if (!notify->info->types[QEMU_CLIPBOARD_TYPE_TEXT].available) {
+                return;
+            }
+
+            /* Check if this is completion of our pending request */
+            if (pending_request && pending_request->info == notify->info &&
+                pending_request->type == QEMU_CLIPBOARD_TYPE_TEXT) {
+                sdl2_clipboard_clear_pending();

ui/sdl2-clipboard.c line 72

Quoted 10 lines
ui/sdl2-clipboard.c new file +10 -0
+            }
+
+            /* Check if data is available, request asynchronously if not */
+            if (!notify->info->types[QEMU_CLIPBOARD_TYPE_TEXT].data) {
+                if (!pending_request) {
+                    pending_request = g_new0(SDLClipboardRequest, 1);
+                    pending_request->scon = scon;
+                    pending_request->info = qemu_clipboard_info_ref(notify->info);
+                    pending_request->type = QEMU_CLIPBOARD_TYPE_TEXT;
+                    qemu_clipboard_request(notify->info, QEMU_CLIPBOARD_TYPE_TEXT);

There is a risk of requesting clipboard text, getting nothing back, and going in a loop. It should handle that.

Quoted 7 lines
ui/sdl2-clipboard.c new file +7 -0
+                }
+                return;
+            }
+
+            /* Process available data */
+            text_size = notify->info->types[QEMU_CLIPBOARD_TYPE_TEXT].size;
+            if (text_size == 0) {

ui/sdl2-clipboard.c line 89

Quoted 10 lines
ui/sdl2-clipboard.c new file +10 -0
+                return;
+            }
+
+            text_data = (const char *)notify->info->types[QEMU_CLIPBOARD_TYPE_TEXT].data;
+
+            /* Ensure null termination for SDL clipboard */
+            g_autofree char *text = g_strndup(text_data, text_size);
+            if (text && text[0] != '\0') {
+                SDL_SetClipboardText(text);
+            } else if (!text) {

At this point text_data != NULL and text_size != 0, in this case g_strndup() will never return NULL. If OOM, the process will abort() before that.

ui/sdl2-clipboard.c line 91

Quoted 2 lines
ui/sdl2-clipboard.c new file +2 -0
+                qemu_log_mask(LOG_GUEST_ERROR,
+                              "SDL clipboard: Failed to allocate memory for clipboard text\n");

you will drop this then

ui/sdl2-clipboard.c line 96

Quoted 5 lines
ui/sdl2-clipboard.c new file +5 -0
+            }
+            break;
+        }
+    case QEMU_CLIPBOARD_RESET_SERIAL:
+        sdl2_clipboard_clear_pending();

you can ignore this, just like gtk-clipboard

Quoted 5 lines
ui/sdl2-clipboard.c new file +5 -0
+        break;
+    }
+}
+
+static void sdl2_clipboard_request(QemuClipboardInfo *info,

ui/sdl2-clipboard.c line 111

Quoted 10 lines
ui/sdl2-clipboard.c new file +10 -0
+                                   QemuClipboardType type)
+{
+    g_autofree char *text = NULL;
+
+    if (type != QEMU_CLIPBOARD_TYPE_TEXT) {
+        return;
+    }
+
+    text = SDL_GetClipboardText();
+    if (!text) {

SDL_GetClipboardText doc says: Returns the clipboard text on success or an empty string on failure..Caller must call SDL_free() on the returned pointer when done with it (even if there was an error).

if (!text || !text[0])

ui/sdl2-clipboard.c line 114

Quoted 3 lines
ui/sdl2-clipboard.c new file +3 -0
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "SDL clipboard: Failed to get clipboard text: %s\n",
+                      SDL_GetError());

use warn_report() && call SDL_free(text)

Quoted 7 lines
ui/sdl2-clipboard.c new file +7 -0
+        return;
+    }
+
+    qemu_clipboard_set_data(info->owner, info, type,
+                            strlen(text), text, true);
+}
+

ui/sdl2-clipboard.c line 131

Quoted 10 lines
ui/sdl2-clipboard.c new file +10 -0
+void sdl2_clipboard_init(struct sdl2_console *scon)
+{
+    scon->cbpeer.name = "sdl2-clipboard";
+    scon->cbpeer.notifier.notify = sdl2_clipboard_notify;
+    scon->cbpeer.request = sdl2_clipboard_request;
+
+    qemu_clipboard_peer_register(&scon->cbpeer);
+}
+
+void sdl2_clipboard_handle_request(struct sdl2_console *scon)

The function should be renamed, see below.

ui/sdl2-clipboard.c line 136

Quoted 5 lines
ui/sdl2-clipboard.c new file +5 -0
+{
+    g_autofree char *text = NULL;
+    QemuClipboardInfo *info;
+
+    text = SDL_GetClipboardText();

instead of requesting the content immediately here, we should wait for an actual guest/peer request. This will remove the duplication of code to actually get the content.

Quoted 4 lines
ui/sdl2-clipboard.c new file +4 -0
+    if (!text) {
+        qemu_log_mask(LOG_GUEST_ERROR,
+                      "SDL clipboard: Failed to get clipboard text: %s\n",
+                      SDL_GetError());

ui/sdl2-clipboard.c line 150

Quoted 10 lines
ui/sdl2-clipboard.c new file +10 -0
+        return;
+    }
+
+    if (text[0] == '\0') {
+        return; /* Ignore empty clipboard */
+    }
+
+    info = qemu_clipboard_info_new(&scon->cbpeer, QEMU_CLIPBOARD_SELECTION_CLIPBOARD);
+    qemu_clipboard_set_data(&scon->cbpeer, info, QEMU_CLIPBOARD_TYPE_TEXT,
+                            strlen(text), text, true);

This will simply be qemu_clipboard_update(info)

Quoted 9 lines
ui/sdl2-clipboard.c new file +4 -0
+    qemu_clipboard_info_unref(info);
+}
+
+#endif /* CONFIG_SDL_CLIPBOARD */
ui/sdl2.c +0 -0
index cda4293a53..00a17b68a7 100644

ui/sdl2.c void sdl2_poll_events(struct sdl2_console *scon) · line 696

Quoted 6 lines
ui/sdl2.c +3 -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);

It's not a request, it's an update. Please rename the function accordingly.

Quoted 17 lines
ui/sdl2.c +6 -1
+            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)
--
Quoted 3 lines

2.50.1

--
Marc-André Lureau

#2 lore raw

PATCH 1/1 ui/sdl2: Add SDL clipboard support

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
- Screen lock/unlock handling for improved reliability
- 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.

Changes in v2:
- Fixed meson option to use 'feature' type instead of 'boolean'
- Improved error handling with warn_report() and proper SDL_free()
- Added protection against async request loops
- Simplified clipboard data handling
- Fixed line length violations for checkpatch compliance
- Maintained compatibility with existing screen lock handling

---
 include/ui/sdl2.h   |  15 ++++
 meson.build         |   1 +
 meson_options.txt   |   2 +
 ui/meson.build      |   6 ++
 ui/sdl2-clipboard.c | 148 ++++++++++++++++++++++++++++++++++++++++++++
 ui/sdl2.c           |  30 +++++++++
 6 files changed, 202 insertions(+)
 create mode 100644 ui/sdl2-clipboard.c
include/ui/sdl2.h renamed from tmp/qemu-pristine/qemu-10.0.0/include/ui/sdl2.h +16 -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,11 @@
     bool gui_keysym;
     SDL_GLContext winctx;
     QKbdState *kbd;
+#ifdef CONFIG_SDL_CLIPBOARD
+    QemuClipboardPeer cbpeer;
+    bool clipboard_active;
+    uint32_t last_focus_time;
+#endif
 #ifdef CONFIG_OPENGL
     QemuGLShader *gls;
     egl_fb guest_fb;
@@ -97,4 +106,11 @@
 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_focus_change(struct sdl2_console *scon,
+                                         bool gained_focus);
+void sdl2_clipboard_handle_request(struct sdl2_console *scon);
+#endif
+
 #endif /* SDL2_H */
meson.build renamed from tmp/qemu-pristine/qemu-10.0.0/meson.build +6 -0
@@ -1594,6 +1594,11 @@
           get_option('sdl').disabled() ? 'disabled' : 'not found'))
   endif
   sdl_image = not_found
+endif
+
+have_sdl_clipboard = false
+if sdl.found()
+  have_sdl_clipboard = get_option('sdl_clipboard').require(sdl.found()).allowed()
 endif
 
 rbd = not_found
@@ -2511,6 +2516,7 @@
 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 renamed from tmp/qemu-pristine/qemu-10.0.0/meson_options.txt +2 -0
@@ -212,6 +212,8 @@
        description: 'SDL user interface')
 option('sdl_image', type : 'feature', value : 'auto',
        description: 'SDL Image support for icons')
+option('sdl_clipboard', type : 'feature', value : 'auto',
+       description: 'SDL clipboard support')
 option('seccomp', type : 'feature', value : 'auto',
        description: 'seccomp support')
 option('smartcard', type : 'feature', value : 'auto',
ui/meson.build renamed from tmp/qemu-pristine/qemu-10.0.0/ui/meson.build +3 -0
@@ -126,6 +126,9 @@
     '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 +206 -0

206 lines not on this page · raw message

ui/sdl2.c renamed from tmp/qemu-pristine/qemu-10.0.0/ui/sdl2.c +15 -0
@@ -606,11 +606,17 @@
          * key is released.
          */
         scon->ignore_hotkeys = get_mod_state();
+#ifdef CONFIG_SDL_CLIPBOARD
+        sdl2_clipboard_handle_focus_change(scon, true);
+#endif
         break;
     case SDL_WINDOWEVENT_FOCUS_LOST:
         if (gui_grab && !gui_fullscreen) {
             sdl_grab_end(scon);
         }
+#ifdef CONFIG_SDL_CLIPBOARD
+        sdl2_clipboard_handle_focus_change(scon, false);
+#endif
         break;
     case SDL_WINDOWEVENT_RESTORED:
         update_displaychangelistener(&scon->dcl, GUI_REFRESH_INTERVAL_DEFAULT);
@@ -691,6 +697,11 @@
         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 +912,10 @@
         }
         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)