Skip to content
This repository was archived by the owner on May 31, 2022. It is now read-only.

Commit fd51cb3

Browse files
author
Allen Webster
committed
fix win32 clipboard reading
1 parent 0635126 commit fd51cb3

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

platform_win32/win32_4ed.cpp

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -378,42 +378,45 @@ win32_read_clipboard_contents(Thread_Context *tctx, Arena *arena){
378378

379379
String_Const_u8 result = {};
380380

381+
#if 0
381382
b32 has_text = false;
382383
b32 has_unicode = IsClipboardFormatAvailable(CF_UNICODETEXT);
383384
if (!has_unicode){
384385
has_text = IsClipboardFormatAvailable(CF_TEXT);
385386
}
386387
b32 can_read = has_unicode || has_text;
388+
#endif
387389

388-
if (can_read){
389-
if (OpenClipboard(win32vars.window_handle)){
390-
if (has_unicode){
391-
HANDLE clip_data = GetClipboardData(CF_UNICODETEXT);
392-
if (clip_data != 0){
393-
u16 *clip_16_ptr = (u16*)GlobalLock(clip_data);
394-
if (clip_16_ptr != 0){
395-
String_Const_u16 clip_16 = SCu16(clip_16_ptr);
396-
result = string_u8_from_string_u16(arena, clip_16, StringFill_NullTerminate).string;
397-
}
390+
if (OpenClipboard(win32vars.window_handle)){
391+
b32 got_result = false;
392+
if (!got_result){
393+
HANDLE clip_data = GetClipboardData(CF_UNICODETEXT);
394+
if (clip_data != 0){
395+
u16 *clip_16_ptr = (u16*)GlobalLock(clip_data);
396+
if (clip_16_ptr != 0){
397+
String_Const_u16 clip_16 = SCu16(clip_16_ptr);
398+
got_result = true;
399+
result = string_u8_from_string_u16(arena, clip_16, StringFill_NullTerminate).string;
398400
}
399401
GlobalUnlock(clip_data);
400402
}
401-
else{
402-
HANDLE clip_data = GetClipboardData(CF_TEXT);
403-
if (clip_data != 0){
404-
char *clip_ascii_ptr = (char*)GlobalLock(clip_data);
405-
if (clip_ascii_ptr != 0){
406-
String_Const_char clip_ascii = SCchar(clip_ascii_ptr);
407-
result = string_u8_from_string_char(arena, clip_ascii, StringFill_NullTerminate).string;
408-
}
403+
}
404+
if (!got_result){
405+
HANDLE clip_data = GetClipboardData(CF_TEXT);
406+
if (clip_data != 0){
407+
char *clip_ascii_ptr = (char*)GlobalLock(clip_data);
408+
if (clip_ascii_ptr != 0){
409+
String_Const_char clip_ascii = SCchar(clip_ascii_ptr);
410+
got_result = true;
411+
result = string_u8_from_string_char(arena, clip_ascii, StringFill_NullTerminate).string;
409412
}
410413
GlobalUnlock(clip_data);
411414
}
412-
413-
CloseClipboard();
414415
}
416+
CloseClipboard();
415417
}
416418

419+
417420
return(result);
418421
}
419422

ship_files/changes.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11

2+
4.1.8
3+
+ Fix: unreliable clipboard reading on windows
4+
25
4.1.8
36
+ On command line "-U <path>" sets the user directory
47
+ On command line "-L" "> log.txt" to get a startup log

0 commit comments

Comments
 (0)