SDL_waylandclipboard.c
Go to the documentation of this file.
/*
Simple DirectMedia Layer
Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_WAYLAND
#include "SDL_waylanddatamanager.h"
#include "SDL_waylandevents_c.h"
int
Wayland_SetClipboardText(_THIS, const char *text)
{
SDL_VideoData *video_data = NULL;
SDL_WaylandDataDevice *data_device = NULL;
int status = 0;
if (_this == NULL || _this->driverdata == NULL) {
status = SDL_SetError("Video driver uninitialized");
} else {
video_data = _this->driverdata;
/* TODO: Support more than one seat */
data_device = Wayland_get_data_device(video_data->input);
if (text[0] != '\0') {
SDL_WaylandDataSource* source = Wayland_data_source_create(_this);
Wayland_data_source_add_data(source, TEXT_MIME, text,
strlen(text) + 1);
status = Wayland_data_device_set_selection(data_device, source);
if (status != 0) {
Wayland_data_source_destroy(source);
}
} else {
status = Wayland_data_device_clear_selection(data_device);
}
}
return status;
}
char *
Wayland_GetClipboardText(_THIS)
{
SDL_VideoData *video_data = NULL;
SDL_WaylandDataDevice *data_device = NULL;
char *text = NULL;
void *buffer = NULL;
size_t length = 0;
if (_this == NULL || _this->driverdata == NULL) {
SDL_SetError("Video driver uninitialized");
} else {
video_data = _this->driverdata;
/* TODO: Support more than one seat */
data_device = Wayland_get_data_device(video_data->input);
if (data_device->selection_offer != NULL) {
buffer = Wayland_data_offer_receive(data_device->selection_offer,
&length, TEXT_MIME, SDL_TRUE);
if (length > 0) {
text = (char*) buffer;
}
} else if (data_device->selection_source != NULL) {
buffer = Wayland_data_source_get_data(data_device->selection_source,
&length, TEXT_MIME, SDL_TRUE);
if (length > 0) {
text = (char*) buffer;
}
}
}
if (text == NULL) {
text = SDL_strdup("");
}
return text;
}
SDL_bool
Wayland_HasClipboardText(_THIS)
{
SDL_VideoData *video_data = NULL;
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;
data_device = Wayland_get_data_device(video_data->input);
if (data_device != NULL && Wayland_data_offer_has_mime(
data_device->selection_offer, TEXT_MIME)) {
result = SDL_TRUE;
} else if(data_device != NULL && Wayland_data_source_has_mime(
data_device->selection_source, TEXT_MIME)) {
result = SDL_TRUE;
}
}
return result;
}
#endif /* SDL_VIDEO_DRIVER_WAYLAND */
/* vi: set ts=4 sw=4 expandtab: */
Wayland_data_device_set_selection
int Wayland_data_device_set_selection(SDL_WaylandDataDevice *device, SDL_WaylandDataSource *source)
SDL_TRUE
Definition: SDL_stdinc.h:142
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9432
Wayland_GetClipboardText
char * Wayland_GetClipboardText(_THIS)
Wayland_data_offer_has_mime
SDL_bool Wayland_data_offer_has_mime(SDL_WaylandDataOffer *offer, const char *mime_type)
Wayland_SetClipboardText
int Wayland_SetClipboardText(_THIS, const char *text)
SDL_FALSE
Definition: SDL_stdinc.h:141
SDL_VideoDevice::driverdata
void * driverdata
Definition: SDL_sysvideo.h:377
TEXT_MIME
#define TEXT_MIME
Definition: SDL_waylanddatamanager.h:30
SDL_WaylandDataDevice
Definition: SDL_waylanddatamanager.h:51
SDL_VideoData::input
struct SDL_WaylandInput * input
Definition: SDL_waylandvideo.h:60
SDL_WaylandDataDevice::selection_source
SDL_WaylandDataSource * selection_source
Definition: SDL_waylanddatamanager.h:62
Wayland_data_source_has_mime
SDL_bool Wayland_data_source_has_mime(SDL_WaylandDataSource *source, const char *mime_type)
_this
static SDL_VideoDevice * _this
Definition: SDL_video.c:121
Wayland_data_source_destroy
void Wayland_data_source_destroy(SDL_WaylandDataSource *source)
_THIS
#define _THIS
Definition: SDL_alsa_audio.h:31
source
GLsizei GLsizei GLchar * source
Definition: SDL_opengl_glext.h:677
Wayland_data_source_create
SDL_WaylandDataSource * Wayland_data_source_create(_THIS)
SDL_waylanddatamanager.h
Wayland_get_data_device
SDL_WaylandDataDevice * Wayland_get_data_device(struct SDL_WaylandInput *input)
NULL
#define NULL
Definition: begin_code.h:164
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:139
buffer
GLuint buffer
Definition: SDL_opengl_glext.h:533
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
text
static char text[MAX_TEXT_LENGTH]
Definition: testime.c:47
SDL_WaylandDataDevice::selection_offer
SDL_WaylandDataOffer * selection_offer
Definition: SDL_waylanddatamanager.h:58
SDL_strdup
#define SDL_strdup
Definition: SDL_dynapi_overrides.h:397
Wayland_HasClipboardText
SDL_bool Wayland_HasClipboardText(_THIS)
SDL_VideoData
Definition: SDL_androidvideo.h:35
SDL_waylandevents_c.h
Wayland_data_device_clear_selection
int Wayland_data_device_clear_selection(SDL_WaylandDataDevice *device)
length
GLuint GLsizei GLsizei * length
Definition: SDL_opengl_glext.h:669
Wayland_data_offer_receive
void * Wayland_data_offer_receive(SDL_WaylandDataOffer *offer, size_t *length, const char *mime_type, SDL_bool null_terminate)
Wayland_data_source_add_data
int Wayland_data_source_add_data(SDL_WaylandDataSource *source, const char *mime_type, const void *buffer, size_t length)
Wayland_data_source_get_data
void * Wayland_data_source_get_data(SDL_WaylandDataSource *source, size_t *length, const char *mime_type, SDL_bool null_terminate)
SDL_WaylandDataSource
Definition: SDL_waylanddatamanager.h:40