SDL 2.0
SDL_waylandclipboard.c
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21#include "../../SDL_internal.h"
22
23#if SDL_VIDEO_DRIVER_WAYLAND
24
26#include "SDL_waylandevents_c.h"
27
28int
30{
31 SDL_VideoData *video_data = NULL;
32 SDL_WaylandDataDevice *data_device = NULL;
33
34 int status = 0;
35
36 if (_this == NULL || _this->driverdata == NULL) {
37 status = SDL_SetError("Video driver uninitialized");
38 } else {
39 video_data = _this->driverdata;
40 /* TODO: Support more than one seat */
41 data_device = Wayland_get_data_device(video_data->input);
42 if (text[0] != '\0') {
45 strlen(text) + 1);
46
47 status = Wayland_data_device_set_selection(data_device, source);
48 if (status != 0) {
50 }
51 } else {
52 status = Wayland_data_device_clear_selection(data_device);
53 }
54 }
55
56 return status;
57}
58
59char *
61{
62 SDL_VideoData *video_data = NULL;
63 SDL_WaylandDataDevice *data_device = NULL;
64
65 char *text = NULL;
66
67 void *buffer = NULL;
68 size_t length = 0;
69
70 if (_this == NULL || _this->driverdata == NULL) {
71 SDL_SetError("Video driver uninitialized");
72 } else {
73 video_data = _this->driverdata;
74 /* TODO: Support more than one seat */
75 data_device = Wayland_get_data_device(video_data->input);
76 if (data_device->selection_offer != NULL) {
79 if (length > 0) {
80 text = (char*) buffer;
81 }
82 } else if (data_device->selection_source != NULL) {
85 if (length > 0) {
86 text = (char*) buffer;
87 }
88 }
89 }
90
91 if (text == NULL) {
92 text = SDL_strdup("");
93 }
94
95 return text;
96}
97
100{
101 SDL_VideoData *video_data = NULL;
102 SDL_WaylandDataDevice *data_device = NULL;
103
105 if (_this == NULL || _this->driverdata == NULL) {
106 SDL_SetError("Video driver uninitialized");
107 } else {
108 video_data = _this->driverdata;
109 data_device = Wayland_get_data_device(video_data->input);
110 if (data_device != NULL && Wayland_data_offer_has_mime(
111 data_device->selection_offer, TEXT_MIME)) {
113 } else if(data_device != NULL && Wayland_data_source_has_mime(
114 data_device->selection_source, TEXT_MIME)) {
116 }
117 }
118 return result;
119}
120
121#endif /* SDL_VIDEO_DRIVER_WAYLAND */
122
123/* vi: set ts=4 sw=4 expandtab: */
#define _THIS
#define SDL_SetError
#define SDL_strdup
GLuint64EXT * result
GLsizei GLsizei GLchar * source
GLuint buffer
GLuint GLsizei GLsizei * length
SDL_bool
Definition: SDL_stdinc.h:162
@ SDL_TRUE
Definition: SDL_stdinc.h:164
@ SDL_FALSE
Definition: SDL_stdinc.h:163
static SDL_VideoDevice * _this
Definition: SDL_video.c:118
SDL_bool Wayland_HasClipboardText(_THIS)
char * Wayland_GetClipboardText(_THIS)
int Wayland_SetClipboardText(_THIS, const char *text)
SDL_bool Wayland_data_source_has_mime(SDL_WaylandDataSource *source, const char *mime_type)
int Wayland_data_device_set_selection(SDL_WaylandDataDevice *device, SDL_WaylandDataSource *source)
void * Wayland_data_source_get_data(SDL_WaylandDataSource *source, size_t *length, const char *mime_type, SDL_bool null_terminate)
int Wayland_data_device_clear_selection(SDL_WaylandDataDevice *device)
SDL_WaylandDataSource * Wayland_data_source_create(_THIS)
void Wayland_data_source_destroy(SDL_WaylandDataSource *source)
#define TEXT_MIME
SDL_bool Wayland_data_offer_has_mime(SDL_WaylandDataOffer *offer, const char *mime_type)
void * Wayland_data_offer_receive(SDL_WaylandDataOffer *offer, size_t *length, const char *mime_type, SDL_bool null_terminate)
int Wayland_data_source_add_data(SDL_WaylandDataSource *source, const char *mime_type, const void *buffer, size_t length)
SDL_WaylandDataDevice * Wayland_get_data_device(struct SDL_WaylandInput *input)
#define NULL
Definition: begin_code.h:167
struct SDL_WaylandInput * input
SDL_WaylandDataSource * selection_source
SDL_WaylandDataOffer * selection_offer
static char text[MAX_TEXT_LENGTH]
Definition: testime.c:47