1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 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
22#include "SDL_internal.h"
23
24#ifndef SDL_waylanddatamanager_h_
25#define SDL_waylanddatamanager_h_
26
27#include "SDL_waylandvideo.h"
28#include "SDL_waylandwindow.h"
29
30#define TEXT_MIME "text/plain;charset=utf-8"
31#define FILE_MIME "text/uri-list"
32#define FILE_PORTAL_MIME "application/vnd.portal.filetransfer"
33
34typedef struct
35{
36 char *mime_type;
37 void *data;
38 size_t length;
39 struct wl_list link;
40} SDL_MimeDataList;
41
42typedef struct SDL_WaylandUserdata
43{
44 Uint32 sequence;
45 void *data;
46} SDL_WaylandUserdata;
47
48typedef struct
49{
50 struct wl_data_source *source;
51 void *data_device;
52 SDL_ClipboardDataCallback callback;
53 SDL_WaylandUserdata userdata;
54} SDL_WaylandDataSource;
55
56typedef struct
57{
58 struct zwp_primary_selection_source_v1 *source;
59 void *data_device;
60 void *primary_selection_device;
61 SDL_ClipboardDataCallback callback;
62 SDL_WaylandUserdata userdata;
63} SDL_WaylandPrimarySelectionSource;
64
65typedef struct
66{
67 struct wl_data_offer *offer;
68 struct wl_list mimes;
69 void *data_device;
70} SDL_WaylandDataOffer;
71
72typedef struct
73{
74 struct zwp_primary_selection_offer_v1 *offer;
75 struct wl_list mimes;
76 void *primary_selection_device;
77} SDL_WaylandPrimarySelectionOffer;
78
79typedef struct
80{
81 struct wl_data_device *data_device;
82 SDL_VideoData *video_data;
83
84 // Drag and Drop
85 uint32_t drag_serial;
86 SDL_WaylandDataOffer *drag_offer;
87 SDL_WaylandDataOffer *selection_offer;
88 const char *mime_type;
89 bool has_mime_file, has_mime_text;
90 SDL_Window *dnd_window;
91
92 // Clipboard and Primary Selection
93 uint32_t selection_serial;
94 SDL_WaylandDataSource *selection_source;
95} SDL_WaylandDataDevice;
96
97typedef struct
98{
99 struct zwp_primary_selection_device_v1 *primary_selection_device;
100 SDL_VideoData *video_data;
101
102 uint32_t selection_serial;
103 SDL_WaylandPrimarySelectionSource *selection_source;
104 SDL_WaylandPrimarySelectionOffer *selection_offer;
105} SDL_WaylandPrimarySelectionDevice;
106
107// Wayland Data Source / Primary Selection Source - (Sending)
108extern SDL_WaylandDataSource *Wayland_data_source_create(SDL_VideoDevice *_this);
109extern SDL_WaylandPrimarySelectionSource *Wayland_primary_selection_source_create(SDL_VideoDevice *_this);
110extern ssize_t Wayland_data_source_send(SDL_WaylandDataSource *source,
111 const char *mime_type, int fd);
112extern ssize_t Wayland_primary_selection_source_send(SDL_WaylandPrimarySelectionSource *source,
113 const char *mime_type, int fd);
114extern void Wayland_data_source_set_callback(SDL_WaylandDataSource *source,
115 SDL_ClipboardDataCallback callback,
116 void *userdata,
117 Uint32 sequence);
118extern void Wayland_primary_selection_source_set_callback(SDL_WaylandPrimarySelectionSource *source,
119 SDL_ClipboardDataCallback callback,
120 void *userdata);
121extern void *Wayland_data_source_get_data(SDL_WaylandDataSource *source,
122 const char *mime_type,
123 size_t *length);
124extern void *Wayland_primary_selection_source_get_data(SDL_WaylandPrimarySelectionSource *source,
125 const char *mime_type,
126 size_t *length);
127extern void Wayland_data_source_destroy(SDL_WaylandDataSource *source);
128extern void Wayland_primary_selection_source_destroy(SDL_WaylandPrimarySelectionSource *source);
129
130// Wayland Data / Primary Selection Offer - (Receiving)
131extern void *Wayland_data_offer_receive(SDL_WaylandDataOffer *offer,
132 const char *mime_type,
133 size_t *length);
134extern void *Wayland_primary_selection_offer_receive(SDL_WaylandPrimarySelectionOffer *offer,
135 const char *mime_type,
136 size_t *length);
137extern bool Wayland_data_offer_has_mime(SDL_WaylandDataOffer *offer,
138 const char *mime_type);
139extern bool Wayland_primary_selection_offer_has_mime(SDL_WaylandPrimarySelectionOffer *offer,
140 const char *mime_type);
141extern bool Wayland_data_offer_add_mime(SDL_WaylandDataOffer *offer,
142 const char *mime_type);
143extern bool Wayland_primary_selection_offer_add_mime(SDL_WaylandPrimarySelectionOffer *offer,
144 const char *mime_type);
145extern void Wayland_data_offer_destroy(SDL_WaylandDataOffer *offer);
146extern void Wayland_primary_selection_offer_destroy(SDL_WaylandPrimarySelectionOffer *offer);
147
148// Clipboard / Primary Selection
149extern bool Wayland_data_device_clear_selection(SDL_WaylandDataDevice *device);
150extern bool Wayland_primary_selection_device_clear_selection(SDL_WaylandPrimarySelectionDevice *device);
151extern bool Wayland_data_device_set_selection(SDL_WaylandDataDevice *device,
152 SDL_WaylandDataSource *source,
153 const char **mime_types,
154 size_t mime_count);
155extern bool Wayland_primary_selection_device_set_selection(SDL_WaylandPrimarySelectionDevice *device,
156 SDL_WaylandPrimarySelectionSource *source,
157 const char **mime_types,
158 size_t mime_count);
159extern void Wayland_data_device_set_serial(SDL_WaylandDataDevice *device,
160 uint32_t serial);
161extern void Wayland_primary_selection_device_set_serial(SDL_WaylandPrimarySelectionDevice *device,
162 uint32_t serial);
163#endif // SDL_waylanddatamanager_h_
164