FreeRDP
Loading...
Searching...
No Matches
sdlClip Class Reference

object that handles clipboard context for the SDL3 client More...

#include <sdl_clip.hpp>

Public Member Functions

 sdlClip (SdlContext *sdl)
 
 sdlClip (const sdlClip &)=delete
 
 sdlClip (sdlClip &&)=delete
 
sdlClipoperator= (const sdlClip &)=delete
 
sdlClipoperator= (sdlClip &&)=delete
 
BOOL init (CliprdrClientContext *clip)
 
BOOL uninit (CliprdrClientContext *clip)
 
bool handle_update (const SDL_ClipboardEvent &ev)
 

Detailed Description

object that handles clipboard context for the SDL3 client

Definition at line 88 of file sdl_clip.hpp.

Constructor & Destructor Documentation

◆ sdlClip()

sdlClip::sdlClip ( SdlContext sdl)
explicit

Definition at line 128 of file sdl_clip.cpp.

129 : _sdl(sdl), _file(cliprdr_file_context_new(this)), _log(WLog_Get(TAG)),
130 _system(ClipboardCreate()), _event(CreateEventA(nullptr, TRUE, FALSE, nullptr))
131{
132 WINPR_ASSERT(sdl);
133}

◆ ~sdlClip()

sdlClip::~sdlClip ( )
virtual

Definition at line 135 of file sdl_clip.cpp.

136{
137 cliprdr_file_context_free(_file);
138 ClipboardDestroy(_system);
139 (void)CloseHandle(_event);
140}

Member Function Documentation

◆ handle_update()

bool sdlClip::handle_update ( const SDL_ClipboardEvent &  ev)

Definition at line 167 of file sdl_clip.cpp.

168{
169 if (!_ctx || !_sync || ev.owner)
170 {
171 /* TODO: Hack to identify our own updates */
172 if (ev.owner && (ev.reserved == 0x42))
173 {
174 _cache_data.clear();
175 auto rc =
176 SDL_SetClipboardData(sdlClip::ClipDataCb, sdlClip::ClipCleanCb, this, ev.mime_types,
177 WINPR_ASSERTING_INT_CAST(size_t, ev.num_mime_types));
178 _current_mimetypes.clear();
179 return rc;
180 }
181 return true;
182 }
183
184 clearServerFormats();
185
186 std::string mime_html = s_mime_html;
187
188 std::vector<std::string> mime_bitmap = { BMP_MIME_LIST };
189 std::string mime_webp = s_mime_webp;
190 std::string mime_png = s_mime_png;
191 std::string mime_jpeg = s_mime_jpg;
192 std::string mime_tiff = s_mime_tiff;
193 std::vector<std::string> mime_images = { mime_webp, mime_png, mime_jpeg, mime_tiff };
194
195 std::vector<std::string> clientFormatNames;
196 std::vector<CLIPRDR_FORMAT> clientFormats;
197
198 size_t nformats = WINPR_ASSERTING_INT_CAST(size_t, ev.num_mime_types);
199 const char** clipboard_mime_formats = ev.mime_types;
200
201 WLog_Print(_log, WLOG_TRACE, "SDL has %d formats", nformats);
202
203 bool textPushed = false;
204 bool imgPushed = false;
205
206 for (size_t i = 0; i < nformats; i++)
207 {
208 std::string local_mime = clipboard_mime_formats[i];
209 WLog_Print(_log, WLOG_TRACE, " - %s", local_mime.c_str());
210
211 if (std::find(s_mime_text().begin(), s_mime_text().end(), local_mime) !=
212 s_mime_text().end())
213 {
214 /* text formats */
215 if (!textPushed)
216 {
217 clientFormats.push_back({ CF_TEXT, nullptr });
218 clientFormats.push_back({ CF_OEMTEXT, nullptr });
219 clientFormats.push_back({ CF_UNICODETEXT, nullptr });
220 textPushed = true;
221 }
222 }
223 else if (local_mime == mime_html)
224 /* html */
225 clientFormatNames.emplace_back(s_type_HtmlFormat);
226 else if ((std::find(mime_bitmap.begin(), mime_bitmap.end(), local_mime) !=
227 mime_bitmap.end()) ||
228 (std::find(mime_images.begin(), mime_images.end(), local_mime) !=
229 mime_images.end()))
230 {
231 /* image formats */
232 if (!imgPushed)
233 {
234 clientFormats.push_back({ CF_DIB, nullptr });
235#if defined(WINPR_UTILS_IMAGE_DIBv5)
236 clientFormats.push_back({ CF_DIBV5, nullptr });
237#endif
238
239 for (auto& bmp : mime_bitmap)
240 clientFormatNames.push_back(bmp);
241
242 for (auto& img : mime_images)
243 clientFormatNames.push_back(img);
244
245 clientFormatNames.emplace_back(s_type_HtmlFormat);
246 imgPushed = true;
247 }
248 }
249 }
250
251 for (auto& name : clientFormatNames)
252 {
253 clientFormats.push_back({ ClipboardRegisterFormat(_system, name.c_str()), name.data() });
254 }
255
256 std::sort(clientFormats.begin(), clientFormats.end(),
257 [](const auto& a, const auto& b) { return a < b; });
258 auto u = std::unique(clientFormats.begin(), clientFormats.end());
259 clientFormats.erase(u, clientFormats.end());
260
261 const CLIPRDR_FORMAT_LIST formatList = {
262 { CB_FORMAT_LIST, 0, 0 },
263 static_cast<UINT32>(clientFormats.size()),
264 clientFormats.data(),
265 };
266
267 WLog_Print(_log, WLOG_TRACE,
268 "-------------- client format list [%" PRIu32 "] ------------------",
269 formatList.numFormats);
270 for (UINT32 x = 0; x < formatList.numFormats; x++)
271 {
272 auto format = &formatList.formats[x];
273 WLog_Print(_log, WLOG_TRACE, "client announces %" PRIu32 " [%s][%s]", format->formatId,
274 ClipboardGetFormatIdString(format->formatId), format->formatName);
275 }
276
277 WINPR_ASSERT(_ctx);
278 WINPR_ASSERT(_ctx->ClientFormatList);
279 return _ctx->ClientFormatList(_ctx, &formatList) == CHANNEL_RC_OK;
280}

◆ init()

BOOL sdlClip::init ( CliprdrClientContext *  clip)

Definition at line 142 of file sdl_clip.cpp.

143{
144 WINPR_ASSERT(clip);
145 _ctx = clip;
146 clip->custom = this;
147 _ctx->MonitorReady = sdlClip::MonitorReady;
148 _ctx->ServerCapabilities = sdlClip::ReceiveServerCapabilities;
149 _ctx->ServerFormatList = sdlClip::ReceiveServerFormatList;
150 _ctx->ServerFormatListResponse = sdlClip::ReceiveFormatListResponse;
151 _ctx->ServerFormatDataRequest = sdlClip::ReceiveFormatDataRequest;
152 _ctx->ServerFormatDataResponse = sdlClip::ReceiveFormatDataResponse;
153
154 return cliprdr_file_context_init(_file, _ctx);
155}

◆ uninit()

BOOL sdlClip::uninit ( CliprdrClientContext *  clip)

Definition at line 157 of file sdl_clip.cpp.

158{
159 WINPR_ASSERT(clip);
160 if (!cliprdr_file_context_uninit(_file, _ctx))
161 return FALSE;
162 _ctx = nullptr;
163 clip->custom = nullptr;
164 return TRUE;
165}

The documentation for this class was generated from the following files: