mirror of
https://github.com/morgan9e/FreeRDP
synced 2026-04-14 08:24:16 +09:00
Merge pull request #11496 from akallabeth/sdl-unique-mime
[client,sdl] use a GUID to identify the clipboard
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <mutex>
|
||||
#include <iterator>
|
||||
#include <algorithm>
|
||||
@@ -129,9 +130,14 @@ static bool operator==(const CLIPRDR_FORMAT& lhs, const CLIPRDR_FORMAT& rhs)
|
||||
|
||||
sdlClip::sdlClip(SdlContext* sdl)
|
||||
: _sdl(sdl), _file(cliprdr_file_context_new(this)), _log(WLog_Get(TAG)),
|
||||
_system(ClipboardCreate()), _event(CreateEventA(nullptr, TRUE, FALSE, nullptr))
|
||||
_system(ClipboardCreate()), _event(CreateEventA(nullptr, TRUE, FALSE, nullptr)),
|
||||
_uuid(sdl::utils::generate_uuid_v4())
|
||||
{
|
||||
WINPR_ASSERT(sdl);
|
||||
|
||||
std::stringstream ss;
|
||||
ss << s_mime_freerdp_update << "-" << _uuid;
|
||||
_mime_uuid = ss.str();
|
||||
}
|
||||
|
||||
sdlClip::~sdlClip()
|
||||
@@ -166,12 +172,12 @@ BOOL sdlClip::uninit(CliprdrClientContext* clip)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static bool contains(const char** mime_types, Sint32 count)
|
||||
bool sdlClip::contains(const char** mime_types, Sint32 count)
|
||||
{
|
||||
for (Sint32 x = 0; x < count; x++)
|
||||
{
|
||||
const auto mime = mime_types[x];
|
||||
if (mime && (strcmp(s_mime_freerdp_update, mime) == 0))
|
||||
if (mime && (strcmp(_mime_uuid.c_str(), mime) == 0))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -542,7 +548,7 @@ UINT sdlClip::ReceiveServerFormatList(CliprdrClientContext* context,
|
||||
clipboard->_current_mimetypes.push_back(s_mime_gnome_copied_files);
|
||||
clipboard->_current_mimetypes.push_back(s_mime_mate_copied_files);
|
||||
}
|
||||
clipboard->_current_mimetypes.push_back(s_mime_freerdp_update);
|
||||
clipboard->_current_mimetypes.push_back(clipboard->_mime_uuid.c_str());
|
||||
|
||||
auto s = clipboard->_current_mimetypes.size();
|
||||
SDL_Event ev = { SDL_EVENT_CLIPBOARD_UPDATE };
|
||||
|
||||
@@ -112,6 +112,8 @@ class sdlClip
|
||||
std::string getServerFormat(uint32_t id);
|
||||
uint32_t serverIdForMime(const std::string& mime);
|
||||
|
||||
bool contains(const char** mime_types, Sint32 count);
|
||||
|
||||
static UINT MonitorReady(CliprdrClientContext* context,
|
||||
const CLIPRDR_MONITOR_READY* monitorReady);
|
||||
|
||||
@@ -162,4 +164,6 @@ class sdlClip
|
||||
};
|
||||
std::map<std::string, cache_entry> _cache_data;
|
||||
std::vector<const char*> _current_mimetypes;
|
||||
std::string _uuid;
|
||||
std::string _mime_uuid;
|
||||
};
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <cassert>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <random>
|
||||
|
||||
#include "sdl_utils.hpp"
|
||||
|
||||
@@ -353,3 +354,37 @@ std::string sdl::utils::rdp_orientation_to_str(uint32_t orientation)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string sdl::utils::generate_uuid_v4()
|
||||
{
|
||||
static std::random_device rd;
|
||||
static std::mt19937 gen(rd());
|
||||
static std::uniform_int_distribution<> dis(0, 255);
|
||||
std::stringstream ss;
|
||||
ss << std::hex << std::setfill('0') << std::setw(2);
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
ss << dis(gen);
|
||||
}
|
||||
ss << "-";
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
ss << dis(gen);
|
||||
}
|
||||
ss << "-";
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
ss << dis(gen);
|
||||
}
|
||||
ss << "-";
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
ss << dis(gen);
|
||||
}
|
||||
ss << "-";
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
ss << dis(gen);
|
||||
};
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
@@ -86,4 +86,6 @@ namespace sdl::utils
|
||||
std::string rdp_orientation_to_str(uint32_t orientation);
|
||||
std::string sdl_orientation_to_str(SDL_DisplayOrientation orientation);
|
||||
UINT32 orientaion_to_rdp(SDL_DisplayOrientation orientation);
|
||||
|
||||
std::string generate_uuid_v4();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user