From a2ba5e90524a7e4f5bcbfc2bf53c737fecc09b26 Mon Sep 17 00:00:00 2001
From: Linus Probert <[EMAIL REDACTED]>
Date: Mon, 12 Jun 2023 13:06:16 +0200
Subject: [PATCH] clipboard: Fixes testautomation fails introduced by clipboard
changes
---
src/video/wayland/SDL_waylandclipboard.c | 31 +++++++++++++++---------
src/video/x11/SDL_x11clipboard.c | 6 ++++-
2 files changed, 25 insertions(+), 12 deletions(-)
diff --git a/src/video/wayland/SDL_waylandclipboard.c b/src/video/wayland/SDL_waylandclipboard.c
index dd962a801e52..bc3dc102d603 100644
--- a/src/video/wayland/SDL_waylandclipboard.c
+++ b/src/video/wayland/SDL_waylandclipboard.c
@@ -245,14 +245,16 @@ static SDL_bool HasClipboardData(SDL_VideoDevice *_this, const char *mime_type)
SDL_WaylandDataDevice *data_device = NULL;
SDL_bool result = SDL_FALSE;
- if (_this == NULL || _this->driverdata == NULL) {
- SDL_SetError("Video driver uninitialized");
- } else {
- video_data = _this->driverdata;
- if (video_data->input != NULL && video_data->input->data_device != NULL) {
- data_device = video_data->input->data_device;
- result = result ||
- Wayland_data_offer_has_mime(data_device->selection_offer, mime_type);
+ video_data = _this->driverdata;
+ if (video_data->input != NULL && video_data->input->data_device != NULL) {
+ data_device = video_data->input->data_device;
+ if (data_device->selection_source != NULL) {
+ size_t length = 0;
+ char *buffer = Wayland_data_source_get_data(data_device->selection_source, &length, mime_type, SDL_TRUE);
+ result = buffer != NULL;
+ SDL_free(buffer);
+ } else {
+ result = Wayland_data_offer_has_mime(data_device->selection_offer, mime_type);
}
}
return result;
@@ -280,9 +282,16 @@ SDL_bool Wayland_HasPrimarySelectionText(SDL_VideoDevice *_this)
video_data = _this->driverdata;
if (video_data->input != NULL && video_data->input->primary_selection_device != NULL) {
primary_selection_device = video_data->input->primary_selection_device;
- result = result ||
- Wayland_primary_selection_offer_has_mime(
- primary_selection_device->selection_offer, TEXT_MIME);
+ if (primary_selection_device->selection_source != NULL) {
+ size_t length = 0;
+ char *buffer = Wayland_primary_selection_source_get_data(primary_selection_device->selection_source,
+ &length, TEXT_MIME, SDL_TRUE);
+ result = buffer != NULL;
+ SDL_free(buffer);
+ } else {
+ result = Wayland_primary_selection_offer_has_mime(
+ primary_selection_device->selection_offer, TEXT_MIME);
+ }
}
}
return result;
diff --git a/src/video/x11/SDL_x11clipboard.c b/src/video/x11/SDL_x11clipboard.c
index 2b3c0b3d0744..cee4c664da7f 100644
--- a/src/video/x11/SDL_x11clipboard.c
+++ b/src/video/x11/SDL_x11clipboard.c
@@ -181,7 +181,7 @@ static void *GetSelectionData(SDL_VideoDevice *_this, Atom selection_type, size_
owner = X11_XGetSelectionOwner(display, selection_type);
if (owner == None) {
/* This requires a fallback to ancient X10 cut-buffers. We will just skip those for now */
- return NULL;
+ data = NULL;
} else if (owner == window) {
owner = DefaultRootWindow(display);
if (selection_type == XA_PRIMARY) {
@@ -229,6 +229,10 @@ static void *GetSelectionData(SDL_VideoDevice *_this, Atom selection_type, size_
}
}
+ if (nullterminate && data == NULL) {
+ data = strdup("");
+ }
+
return data;
}