Skip to content

Commit

Permalink
Implement platform-agnostic paste in SDL2 backend
Browse files Browse the repository at this point in the history
  • Loading branch information
falbrechtskirchinger committed Jul 20, 2023
1 parent f0a8f2b commit 589b0c5
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions extras/videoDrivers/SDL2/VideoSDL2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,29 +213,27 @@ void VideoSDL2::PrintError(const std::string& msg) const

void VideoSDL2::HandlePaste()
{
#ifdef _WIN32
if(!IsClipboardFormatAvailable(CF_UNICODETEXT))
if(!SDL_HasClipboardText())

Check warning on line 216 in extras/videoDrivers/SDL2/VideoSDL2.cpp

View check run for this annotation

Codecov / codecov/patch

extras/videoDrivers/SDL2/VideoSDL2.cpp#L216

Added line #L216 was not covered by tests
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());

Check warning on line 223 in extras/videoDrivers/SDL2/VideoSDL2.cpp

View check run for this annotation

Codecov / codecov/patch

extras/videoDrivers/SDL2/VideoSDL2.cpp#L219-L223

Added lines #L219 - L223 were not covered by tests

KeyEvent ke = {KeyType::Invalid, 0, false, false, false};
while(pData && *pData)
auto* p = text;
while(*p)

Check warning on line 227 in extras/videoDrivers/SDL2/VideoSDL2.cpp

View check run for this annotation

Codecov / codecov/patch

extras/videoDrivers/SDL2/VideoSDL2.cpp#L226-L227

Added lines #L226 - L227 were not covered by tests
{
ke.c = *(pData++);
ke.c = static_cast<unsigned char>(*(p++));

Check warning on line 229 in extras/videoDrivers/SDL2/VideoSDL2.cpp

View check run for this annotation

Codecov / codecov/patch

extras/videoDrivers/SDL2/VideoSDL2.cpp#L229

Added line #L229 was not covered by tests
if(ke.c == L' ')
ke.kt = KeyType::Space;
else
ke.kt = KeyType::Char;
CallBack->Msg_KeyDown(ke);
}

GlobalUnlock(hData);
CloseClipboard();
#endif
SDL_free(text);

Check warning on line 236 in extras/videoDrivers/SDL2/VideoSDL2.cpp

View check run for this annotation

Codecov / codecov/patch

extras/videoDrivers/SDL2/VideoSDL2.cpp#L236

Added line #L236 was not covered by tests
}

void VideoSDL2::DestroyScreen()
Expand Down

0 comments on commit 589b0c5

Please sign in to comment.