X11Application: Ensure TIS operations are done on the main thread

Fixes: https://github.com/XQuartz/XQuartz/issues/205
Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
This commit is contained in:
Jeremy Huddleston Sequoia 2022-06-12 22:06:01 -07:00
parent c11b55f3c0
commit b1afcecc61

View File

@ -1701,8 +1701,17 @@ handle_mouse:
}
if (darwinSyncKeymap) {
TISInputSourceRef key_layout =
TISCopyCurrentKeyboardLayoutInputSource();
__block TISInputSourceRef key_layout;
dispatch_block_t copyCurrentKeyboardLayoutInputSource = ^{
key_layout = TISCopyCurrentKeyboardLayoutInputSource();
};
/* This is an ugly ant-pattern, but it is more expedient to address the problem right now. */
if (pthread_main_np()) {
copyCurrentKeyboardLayoutInputSource();
} else {
dispatch_sync(dispatch_get_main_queue(), copyCurrentKeyboardLayoutInputSource);
}
TISInputSourceRef clear;
if (CFEqual(key_layout, last_key_layout)) {
CFRelease(key_layout);