From 6e05e1e65ec32e639933b3f84cbef8e1cd61e1fd Mon Sep 17 00:00:00 2001 From: Frederik Carlier Date: Sat, 14 Sep 2024 00:23:01 +0200 Subject: [PATCH 1/3] Support building natively on Windows (#51) When building for Windows using a native toolchain (i.e. not MinGW or MSYS), `` is not available. Include `` instead and define `strcasecmp`. --- Tools/gpbs.m | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Tools/gpbs.m b/Tools/gpbs.m index fb7bac2f..5cf72511 100644 --- a/Tools/gpbs.m +++ b/Tools/gpbs.m @@ -38,7 +38,12 @@ #endif #include +#ifdef HAVE_UNISTD_H #include +#else +#include +#define strcasecmp _stricmp +#endif #include #ifdef __MINGW__ From ba1c582024db70bf6848a33bc5606097682a4b31 Mon Sep 17 00:00:00 2001 From: Frederik Carlier Date: Tue, 17 Sep 2024 21:19:25 +0200 Subject: [PATCH 2/3] Define WINBOOL on non-MinGW platforms (#52) The Windows SDK declares BOOL as an int. Objective C defines BOOl as a char. Those two types clash. MinGW's implementation of the Windows SDK uses the WINBOOL type to avoid this clash. When compiling natively on Windows, we need to manually define WINBOOL. MinGW will define _DEF_WINBOOL_ if it has defined WINBOOL so we can use the same trick here. See https://github.com/mingw-w64/mingw-w64/blob/master/mingw-w64-headers/include/ntdef.h#L355 --- Source/win32/WIN32Server.m | 12 ++++++++++++ Source/win32/w32_windowdisplay.m | 12 ++++++++++++ Tools/win32pbs.m | 12 ++++++++++++ 3 files changed, 36 insertions(+) diff --git a/Source/win32/WIN32Server.m b/Source/win32/WIN32Server.m index e98c4012..537ecad2 100644 --- a/Source/win32/WIN32Server.m +++ b/Source/win32/WIN32Server.m @@ -63,6 +63,18 @@ #include +// The Windows SDK declares BOOL as an int. Objective C defines BOOl as a char. +// Those two types clash. MinGW's implementation of the Windows SDK uses the WINBOOL +// type to avoid this clash. When compiling natively on Windows, we need to manually +// define WINBOOL. +// MinGW will define _DEF_WINBOOL_ if it has defined WINBOOL so we can use the same trick +// here. +// See https://github.com/mingw-w64/mingw-w64/blob/master/mingw-w64-headers/include/ntdef.h#L355 +#ifndef _DEF_WINBOOL_ +#define _DEF_WINBOOL_ +typedef int WINBOOL; +#endif + // To update the cursor.. static BOOL update_cursor = NO; static BOOL should_handle_cursor = NO; diff --git a/Source/win32/w32_windowdisplay.m b/Source/win32/w32_windowdisplay.m index 8f61e9e7..5487d1ce 100644 --- a/Source/win32/w32_windowdisplay.m +++ b/Source/win32/w32_windowdisplay.m @@ -33,6 +33,18 @@ #include "win32/WIN32Server.h" #include "win32/WIN32Geometry.h" +// The Windows SDK declares BOOL as an int. Objective C defines BOOl as a char. +// Those two types clash. MinGW's implementation of the Windows SDK uses the WINBOOL +// type to avoid this clash. When compiling natively on Windows, we need to manually +// define WINBOOL. +// MinGW will define _DEF_WINBOOL_ if it has defined WINBOOL so we can use the same trick +// here. +// See https://github.com/mingw-w64/mingw-w64/blob/master/mingw-w64-headers/include/ntdef.h#L355 +#ifndef _DEF_WINBOOL_ +#define _DEF_WINBOOL_ +typedef int WINBOOL; +#endif + static void invalidateWindow(WIN32Server *svr, HWND hwnd, RECT rect) { diff --git a/Tools/win32pbs.m b/Tools/win32pbs.m index 740dc7c8..a989bba2 100755 --- a/Tools/win32pbs.m +++ b/Tools/win32pbs.m @@ -40,6 +40,18 @@ #include #endif +// The Windows SDK declares BOOL as an int. Objective C defines BOOl as a char. +// Those two types clash. MinGW's implementation of the Windows SDK uses the WINBOOL +// type to avoid this clash. When compiling natively on Windows, we need to manually +// define WINBOOL. +// MinGW will define _DEF_WINBOOL_ if it has defined WINBOOL so we can use the same trick +// here. +// See https://github.com/mingw-w64/mingw-w64/blob/master/mingw-w64-headers/include/ntdef.h#L355 +#ifndef _DEF_WINBOOL_ +#define _DEF_WINBOOL_ +typedef int WINBOOL; +#endif + @interface Win32PbOwner : NSObject { NSPasteboard *_pb; From 4e3ca27c0b60295b3564429a497a1871d17c08d8 Mon Sep 17 00:00:00 2001 From: Riccardo Date: Thu, 19 Sep 2024 08:32:46 +0200 Subject: [PATCH 3/3] instead of just getting Latin1 we practically see getting 2 or 3 bytes (even for characters that representable in Latin1) so try our best to interpret them (#50) --- Source/x11/XIMInputServer.m | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Source/x11/XIMInputServer.m b/Source/x11/XIMInputServer.m index 690d807f..77bc594c 100644 --- a/Source/x11/XIMInputServer.m +++ b/Source/x11/XIMInputServer.m @@ -151,12 +151,18 @@ - (NSString *) lookupStringForEvent: (XKeyEvent *)event { /* Always returns a Latin-1 string according to the manpage */ count = XLookupString (event, buf, BUF_LEN, &keysym, NULL); - if (count) + if (count == 1) { keys = [[[NSString alloc] initWithBytes: buf length: count encoding: NSISOLatin1StringEncoding] autorelease]; } + else if (count > 1) // manpage lies and we suppose UTF-8 + { + keys = [[[NSString alloc] initWithBytes: buf + length: count + encoding: NSUTF8StringEncoding] autorelease]; + } if (keysymptr) *keysymptr = keysym;