SDL  2.0
SDL_waylandclipboard.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2020 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 
25 #include "SDL_waylanddatamanager.h"
26 #include "SDL_waylandevents_c.h"
27 
28 int
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 
59 char *
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)) {
112  result = SDL_TRUE;
113  } else if(data_device != NULL && Wayland_data_source_has_mime(
114  data_device->selection_source, TEXT_MIME)) {
115  result = SDL_TRUE;
116  }
117  }
118  return result;
119 }
120 
121 #endif /* SDL_VIDEO_DRIVER_WAYLAND */
122 
123 /* vi: set ts=4 sw=4 expandtab: */
SDL_waylandevents_c.h
SDL_VideoDevice::driverdata
void * driverdata
Definition: SDL_sysvideo.h:389
Wayland_HasClipboardText
SDL_bool Wayland_HasClipboardText(_THIS)
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_get_data
void * Wayland_data_source_get_data(SDL_WaylandDataSource *source, size_t *length, const char *mime_type, SDL_bool null_terminate)
Wayland_get_data_device
SDL_WaylandDataDevice * Wayland_get_data_device(struct SDL_WaylandInput *input)
source
GLsizei GLsizei GLchar * source
Definition: SDL_opengl_glext.h:680
NULL
#define NULL
Definition: begin_code.h:167
SDL_VideoData::input
struct SDL_WaylandInput * input
Definition: SDL_waylandvideo.h:73
Wayland_data_source_destroy
void Wayland_data_source_destroy(SDL_WaylandDataSource *source)
Wayland_data_device_set_selection
int Wayland_data_device_set_selection(SDL_WaylandDataDevice *device, SDL_WaylandDataSource *source)
length
GLuint GLsizei GLsizei * length
Definition: SDL_opengl_glext.h:672
Wayland_data_device_clear_selection
int Wayland_data_device_clear_selection(SDL_WaylandDataDevice *device)
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9435
buffer
GLuint buffer
Definition: SDL_opengl_glext.h:536
Wayland_data_source_add_data
int Wayland_data_source_add_data(SDL_WaylandDataSource *source, const char *mime_type, const void *buffer, size_t length)
_this
static SDL_VideoDevice * _this
Definition: SDL_video.c:121
_THIS
#define _THIS
Definition: SDL_alsa_audio.h:31
text
static char text[MAX_TEXT_LENGTH]
Definition: testime.c:47
SDL_TRUE
@ SDL_TRUE
Definition: SDL_stdinc.h:164
SDL_waylanddatamanager.h
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)
Wayland_data_source_create
SDL_WaylandDataSource * Wayland_data_source_create(_THIS)
SDL_WaylandDataSource
Definition: SDL_waylanddatamanager.h:40
Wayland_GetClipboardText
char * Wayland_GetClipboardText(_THIS)
SDL_SetError
#define SDL_SetError
Definition: SDL_dynapi_overrides.h:30
SDL_WaylandDataDevice::selection_offer
SDL_WaylandDataOffer * selection_offer
Definition: SDL_waylanddatamanager.h:58
Wayland_data_source_has_mime
SDL_bool Wayland_data_source_has_mime(SDL_WaylandDataSource *source, const char *mime_type)
SDL_strdup
#define SDL_strdup
Definition: SDL_dynapi_overrides.h:397
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:162
SDL_WaylandDataDevice::selection_source
SDL_WaylandDataSource * selection_source
Definition: SDL_waylanddatamanager.h:62
SDL_FALSE
@ SDL_FALSE
Definition: SDL_stdinc.h:163
SDL_WaylandDataDevice
Definition: SDL_waylanddatamanager.h:51
TEXT_MIME
#define TEXT_MIME
Definition: SDL_waylanddatamanager.h:30
SDL_VideoData
Definition: SDL_androidvideo.h:37