fix win32 clipboard reading

This commit is contained in:
Allen Webster 2021-07-14 06:29:02 -07:00
parent 0635126cee
commit fd51cb31c7
2 changed files with 29 additions and 23 deletions

View File

@ -378,41 +378,44 @@ win32_read_clipboard_contents(Thread_Context *tctx, Arena *arena){
String_Const_u8 result = {};
#if 0
b32 has_text = false;
b32 has_unicode = IsClipboardFormatAvailable(CF_UNICODETEXT);
if (!has_unicode){
has_text = IsClipboardFormatAvailable(CF_TEXT);
}
b32 can_read = has_unicode || has_text;
#endif
if (can_read){
if (OpenClipboard(win32vars.window_handle)){
if (has_unicode){
b32 got_result = false;
if (!got_result){
HANDLE clip_data = GetClipboardData(CF_UNICODETEXT);
if (clip_data != 0){
u16 *clip_16_ptr = (u16*)GlobalLock(clip_data);
if (clip_16_ptr != 0){
String_Const_u16 clip_16 = SCu16(clip_16_ptr);
got_result = true;
result = string_u8_from_string_u16(arena, clip_16, StringFill_NullTerminate).string;
}
}
GlobalUnlock(clip_data);
}
else{
}
if (!got_result){
HANDLE clip_data = GetClipboardData(CF_TEXT);
if (clip_data != 0){
char *clip_ascii_ptr = (char*)GlobalLock(clip_data);
if (clip_ascii_ptr != 0){
String_Const_char clip_ascii = SCchar(clip_ascii_ptr);
got_result = true;
result = string_u8_from_string_char(arena, clip_ascii, StringFill_NullTerminate).string;
}
}
GlobalUnlock(clip_data);
}
}
CloseClipboard();
}
}
return(result);
}

View File

@ -1,4 +1,7 @@
4.1.8
+ Fix: unreliable clipboard reading on windows
4.1.8
+ On command line "-U <path>" sets the user directory
+ On command line "-L" "> log.txt" to get a startup log