|
@@ -22,19 +22,19 @@
|
|
|
|
|
|
#ifdef SDL_VIDEO_DRIVER_WAYLAND
|
|
|
|
|
|
-#include "../../events/SDL_events_c.h"
|
|
|
#include "SDL_waylanddatamanager.h"
|
|
|
#include "SDL_waylandevents_c.h"
|
|
|
#include "SDL_waylandclipboard.h"
|
|
|
+#include "../SDL_clipboard_c.h"
|
|
|
+#include "../../events/SDL_events_c.h"
|
|
|
+
|
|
|
|
|
|
int Wayland_SetClipboardData(SDL_VideoDevice *_this)
|
|
|
{
|
|
|
- SDL_VideoData *video_data = NULL;
|
|
|
+ SDL_VideoData *video_data = _this->driverdata;
|
|
|
SDL_WaylandDataDevice *data_device = NULL;
|
|
|
-
|
|
|
int status = 0;
|
|
|
|
|
|
- video_data = _this->driverdata;
|
|
|
if (video_data->input != NULL && video_data->input->data_device != NULL) {
|
|
|
data_device = video_data->input->data_device;
|
|
|
|
|
@@ -54,170 +54,95 @@ int Wayland_SetClipboardData(SDL_VideoDevice *_this)
|
|
|
return status;
|
|
|
}
|
|
|
|
|
|
-#define TEXT_MIME_TYPES_LEN 5
|
|
|
-static const char *text_mime_types[TEXT_MIME_TYPES_LEN] = {
|
|
|
- TEXT_MIME,
|
|
|
- "text/plain",
|
|
|
- "TEXT",
|
|
|
- "UTF8_STRING",
|
|
|
- "STRING",
|
|
|
-};
|
|
|
-
|
|
|
-static const void *Wayland_ClipboardTextCallback(void *userdata, const char *mime_type, size_t *length)
|
|
|
-{
|
|
|
- const void *data = NULL;
|
|
|
-
|
|
|
- *length = 0;
|
|
|
-
|
|
|
- if (userdata) {
|
|
|
- for (size_t i = 0; i < TEXT_MIME_TYPES_LEN; ++i) {
|
|
|
- if (SDL_strcmp(mime_type, text_mime_types[i]) == 0) {
|
|
|
- char *text = userdata;
|
|
|
- *length = SDL_strlen(text);
|
|
|
- data = userdata;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return data;
|
|
|
-}
|
|
|
-
|
|
|
-int Wayland_SetClipboardText(SDL_VideoDevice *_this, const char *text)
|
|
|
+void *Wayland_GetClipboardData(SDL_VideoDevice *_this, const char *mime_type, size_t *length)
|
|
|
{
|
|
|
- SDL_VideoData *video_data = NULL;
|
|
|
+ SDL_VideoData *video_data = _this->driverdata;
|
|
|
SDL_WaylandDataDevice *data_device = NULL;
|
|
|
+ void *buffer = NULL;
|
|
|
|
|
|
- int status = 0;
|
|
|
-
|
|
|
- if (_this == NULL || _this->driverdata == NULL) {
|
|
|
- status = 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;
|
|
|
-
|
|
|
- if (text[0] != '\0') {
|
|
|
- SDL_WaylandDataSource *source = Wayland_data_source_create(_this);
|
|
|
- Wayland_data_source_set_callback(source, Wayland_ClipboardTextCallback, SDL_strdup(text), 0);
|
|
|
-
|
|
|
- status = Wayland_data_device_set_selection(data_device, source, text_mime_types, TEXT_MIME_TYPES_LEN);
|
|
|
- if (status != 0) {
|
|
|
- Wayland_data_source_destroy(source);
|
|
|
- }
|
|
|
- } else {
|
|
|
- status = Wayland_data_device_clear_selection(data_device);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return status;
|
|
|
-}
|
|
|
-
|
|
|
-int Wayland_SetPrimarySelectionText(SDL_VideoDevice *_this, const char *text)
|
|
|
-{
|
|
|
- SDL_VideoData *video_data = NULL;
|
|
|
- SDL_WaylandPrimarySelectionDevice *primary_selection_device = NULL;
|
|
|
-
|
|
|
- int status = 0;
|
|
|
-
|
|
|
- if (_this == NULL || _this->driverdata == NULL) {
|
|
|
- status = SDL_SetError("Video driver uninitialized");
|
|
|
- } else {
|
|
|
- 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;
|
|
|
- if (text[0] != '\0') {
|
|
|
- SDL_WaylandPrimarySelectionSource *source = Wayland_primary_selection_source_create(_this);
|
|
|
- Wayland_primary_selection_source_set_callback(source, Wayland_ClipboardTextCallback, SDL_strdup(text));
|
|
|
-
|
|
|
- status = Wayland_primary_selection_device_set_selection(primary_selection_device,
|
|
|
- source,
|
|
|
- text_mime_types,
|
|
|
- TEXT_MIME_TYPES_LEN);
|
|
|
- if (status != 0) {
|
|
|
- Wayland_primary_selection_source_destroy(source);
|
|
|
- }
|
|
|
- } else {
|
|
|
- status = Wayland_primary_selection_device_clear_selection(primary_selection_device);
|
|
|
- }
|
|
|
+ if (video_data->input != NULL && video_data->input->data_device != NULL) {
|
|
|
+ data_device = video_data->input->data_device;
|
|
|
+ if (data_device->selection_source) {
|
|
|
+ buffer = SDL_GetInternalClipboardData(_this, mime_type, length);
|
|
|
+ } else if (Wayland_data_offer_has_mime(data_device->selection_offer, mime_type)) {
|
|
|
+ buffer = Wayland_data_offer_receive(data_device->selection_offer, mime_type, length);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return status;
|
|
|
+ return buffer;
|
|
|
}
|
|
|
|
|
|
-void *Wayland_GetClipboardData(SDL_VideoDevice *_this, const char *mime_type, size_t *length)
|
|
|
+SDL_bool Wayland_HasClipboardData(SDL_VideoDevice *_this, const char *mime_type)
|
|
|
{
|
|
|
- SDL_VideoData *video_data = NULL;
|
|
|
+ SDL_VideoData *video_data = _this->driverdata;
|
|
|
SDL_WaylandDataDevice *data_device = NULL;
|
|
|
+ SDL_bool result = SDL_FALSE;
|
|
|
|
|
|
- void *buffer = NULL;
|
|
|
-
|
|
|
- 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 && data_device->selection_source->userdata.sequence != 0) {
|
|
|
- buffer = Wayland_data_source_get_data(data_device->selection_source, mime_type, length, SDL_FALSE);
|
|
|
- } else if (Wayland_data_offer_has_mime(data_device->selection_offer, mime_type)) {
|
|
|
- buffer = Wayland_data_offer_receive(data_device->selection_offer, mime_type, length, SDL_FALSE);
|
|
|
+ if (data_device->selection_source != NULL) {
|
|
|
+ result = SDL_HasInternalClipboardData(_this, mime_type);
|
|
|
+ } else {
|
|
|
+ result = Wayland_data_offer_has_mime(data_device->selection_offer, mime_type);
|
|
|
}
|
|
|
}
|
|
|
+ return result;
|
|
|
+}
|
|
|
|
|
|
- return buffer;
|
|
|
+static const char *text_mime_types[] = {
|
|
|
+ TEXT_MIME,
|
|
|
+ "text/plain",
|
|
|
+ "TEXT",
|
|
|
+ "UTF8_STRING",
|
|
|
+ "STRING"
|
|
|
+};
|
|
|
+
|
|
|
+const char **Wayland_GetTextMimeTypes(SDL_VideoDevice *_this, size_t *num_mime_types)
|
|
|
+{
|
|
|
+ *num_mime_types = SDL_arraysize(text_mime_types);
|
|
|
+ return text_mime_types;
|
|
|
}
|
|
|
|
|
|
-char *Wayland_GetClipboardText(SDL_VideoDevice *_this)
|
|
|
+int Wayland_SetPrimarySelectionText(SDL_VideoDevice *_this, const char *text)
|
|
|
{
|
|
|
- SDL_VideoData *video_data = NULL;
|
|
|
- SDL_WaylandDataDevice *data_device = NULL;
|
|
|
+ SDL_VideoData *video_data = _this->driverdata;
|
|
|
+ SDL_WaylandPrimarySelectionDevice *primary_selection_device = NULL;
|
|
|
+ int status = 0;
|
|
|
|
|
|
- char *text = NULL;
|
|
|
- size_t length = 0;
|
|
|
+ if (video_data->input != NULL && video_data->input->primary_selection_device != NULL) {
|
|
|
+ primary_selection_device = video_data->input->primary_selection_device;
|
|
|
+ if (text[0] != '\0') {
|
|
|
+ SDL_WaylandPrimarySelectionSource *source = Wayland_primary_selection_source_create(_this);
|
|
|
+ Wayland_primary_selection_source_set_callback(source, SDL_ClipboardTextCallback, SDL_strdup(text));
|
|
|
|
|
|
- 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;
|
|
|
- if (data_device->selection_source && data_device->selection_source->userdata.sequence == 0) {
|
|
|
- text = Wayland_data_source_get_data(data_device->selection_source, TEXT_MIME, &length, SDL_TRUE);
|
|
|
- } else if (Wayland_data_offer_has_mime(
|
|
|
- data_device->selection_offer, TEXT_MIME)) {
|
|
|
- text = Wayland_data_offer_receive(data_device->selection_offer,
|
|
|
- TEXT_MIME, &length, SDL_TRUE);
|
|
|
+ status = Wayland_primary_selection_device_set_selection(primary_selection_device,
|
|
|
+ source,
|
|
|
+ text_mime_types,
|
|
|
+ SDL_arraysize(text_mime_types));
|
|
|
+ if (status != 0) {
|
|
|
+ Wayland_primary_selection_source_destroy(source);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ status = Wayland_primary_selection_device_clear_selection(primary_selection_device);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (text == NULL) {
|
|
|
- text = SDL_strdup("");
|
|
|
- }
|
|
|
-
|
|
|
- return text;
|
|
|
+ return status;
|
|
|
}
|
|
|
|
|
|
char *Wayland_GetPrimarySelectionText(SDL_VideoDevice *_this)
|
|
|
{
|
|
|
- SDL_VideoData *video_data = NULL;
|
|
|
+ SDL_VideoData *video_data = _this->driverdata;
|
|
|
SDL_WaylandPrimarySelectionDevice *primary_selection_device = NULL;
|
|
|
-
|
|
|
char *text = NULL;
|
|
|
size_t length = 0;
|
|
|
|
|
|
- if (_this == NULL || _this->driverdata == NULL) {
|
|
|
- SDL_SetError("Video driver uninitialized");
|
|
|
- } else {
|
|
|
- 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;
|
|
|
- if (primary_selection_device->selection_source != NULL) {
|
|
|
- text = Wayland_primary_selection_source_get_data(primary_selection_device->selection_source, TEXT_MIME, &length, SDL_TRUE);
|
|
|
- } else if (Wayland_primary_selection_offer_has_mime(
|
|
|
- primary_selection_device->selection_offer, TEXT_MIME)) {
|
|
|
- text = Wayland_primary_selection_offer_receive(primary_selection_device->selection_offer,
|
|
|
- TEXT_MIME, &length, SDL_TRUE);
|
|
|
- }
|
|
|
+ if (video_data->input != NULL && video_data->input->primary_selection_device != NULL) {
|
|
|
+ primary_selection_device = video_data->input->primary_selection_device;
|
|
|
+ if (primary_selection_device->selection_source != NULL) {
|
|
|
+ text = Wayland_primary_selection_source_get_data(primary_selection_device->selection_source, TEXT_MIME, &length);
|
|
|
+ } else if (Wayland_primary_selection_offer_has_mime(primary_selection_device->selection_offer, TEXT_MIME)) {
|
|
|
+ text = Wayland_primary_selection_offer_receive(primary_selection_device->selection_offer, TEXT_MIME, &length);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -228,59 +153,18 @@ char *Wayland_GetPrimarySelectionText(SDL_VideoDevice *_this)
|
|
|
return text;
|
|
|
}
|
|
|
|
|
|
-static SDL_bool HasClipboardData(SDL_VideoDevice *_this, const char *mime_type)
|
|
|
-{
|
|
|
- SDL_VideoData *video_data = NULL;
|
|
|
- SDL_WaylandDataDevice *data_device = NULL;
|
|
|
-
|
|
|
- SDL_bool result = SDL_FALSE;
|
|
|
- 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, mime_type, &length, SDL_TRUE);
|
|
|
- result = (buffer ? SDL_TRUE : SDL_FALSE);
|
|
|
- SDL_free(buffer);
|
|
|
- } else {
|
|
|
- result = Wayland_data_offer_has_mime(data_device->selection_offer, mime_type);
|
|
|
- }
|
|
|
- }
|
|
|
- return result;
|
|
|
-}
|
|
|
-
|
|
|
-SDL_bool Wayland_HasClipboardData(SDL_VideoDevice *_this, const char *mime_type)
|
|
|
-{
|
|
|
- return HasClipboardData(_this, mime_type);
|
|
|
-}
|
|
|
-
|
|
|
-SDL_bool Wayland_HasClipboardText(SDL_VideoDevice *_this)
|
|
|
-{
|
|
|
- return HasClipboardData(_this, TEXT_MIME);
|
|
|
-}
|
|
|
-
|
|
|
SDL_bool Wayland_HasPrimarySelectionText(SDL_VideoDevice *_this)
|
|
|
{
|
|
|
- SDL_VideoData *video_data = NULL;
|
|
|
+ SDL_VideoData *video_data = _this->driverdata;
|
|
|
SDL_WaylandPrimarySelectionDevice *primary_selection_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->primary_selection_device != NULL) {
|
|
|
- primary_selection_device = video_data->input->primary_selection_device;
|
|
|
- if (primary_selection_device->selection_source != NULL) {
|
|
|
- size_t length = 0;
|
|
|
- char *buffer = Wayland_primary_selection_source_get_data(primary_selection_device->selection_source,
|
|
|
- TEXT_MIME, &length, SDL_TRUE);
|
|
|
- result = buffer != NULL;
|
|
|
- SDL_free(buffer);
|
|
|
- } else {
|
|
|
- result = Wayland_primary_selection_offer_has_mime(
|
|
|
- primary_selection_device->selection_offer, TEXT_MIME);
|
|
|
- }
|
|
|
+
|
|
|
+ if (video_data->input != NULL && video_data->input->primary_selection_device != NULL) {
|
|
|
+ primary_selection_device = video_data->input->primary_selection_device;
|
|
|
+ if (primary_selection_device->selection_source != NULL) {
|
|
|
+ result = SDL_TRUE;
|
|
|
+ } else {
|
|
|
+ result = Wayland_primary_selection_offer_has_mime(primary_selection_device->selection_offer, TEXT_MIME);
|
|
|
}
|
|
|
}
|
|
|
return result;
|