From 589b0c5812ba631c1c1256a3d2b55fc076bae689 Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Thu, 20 Jul 2023 10:27:53 +0200 Subject: [PATCH] Implement platform-agnostic paste in SDL2 backend --- extras/videoDrivers/SDL2/VideoSDL2.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/extras/videoDrivers/SDL2/VideoSDL2.cpp b/extras/videoDrivers/SDL2/VideoSDL2.cpp index afd519c10..ad3ad57df 100644 --- a/extras/videoDrivers/SDL2/VideoSDL2.cpp +++ b/extras/videoDrivers/SDL2/VideoSDL2.cpp @@ -213,29 +213,27 @@ void VideoSDL2::PrintError(const std::string& msg) const void VideoSDL2::HandlePaste() { -#ifdef _WIN32 - if(!IsClipboardFormatAvailable(CF_UNICODETEXT)) + if(!SDL_HasClipboardText()) return; - OpenClipboard(nullptr); - - HANDLE hData = GetClipboardData(CF_UNICODETEXT); - const wchar_t* pData = (const wchar_t*)GlobalLock(hData); + auto* text = SDL_GetClipboardText(); + if(!text) + return; + if(text[0] == '\0') + PrintError(SDL_GetError()); KeyEvent ke = {KeyType::Invalid, 0, false, false, false}; - while(pData && *pData) + auto* p = text; + while(*p) { - ke.c = *(pData++); + ke.c = static_cast(*(p++)); if(ke.c == L' ') ke.kt = KeyType::Space; else ke.kt = KeyType::Char; CallBack->Msg_KeyDown(ke); } - - GlobalUnlock(hData); - CloseClipboard(); -#endif + SDL_free(text); } void VideoSDL2::DestroyScreen()