summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Huddleston Sequoia <jeremyhu@apple.com>2022-06-12 22:06:01 -0700
committerJeremy Huddleston Sequoia <jeremyhu@apple.com>2022-06-13 22:03:54 -0700
commitb5a3b100fcc2c4a9f04da2893dbbd6c66123e0bd (patch)
treee92308d8487e6dd05cd3a15b0a9497fe3de14065
parent2f62b7c0371b46dfe199573b90411ba11c022a5f (diff)
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> (cherry picked from commit b1afcecc61d841f95e786e4f4f84184f91d149f1)
-rw-r--r--hw/xquartz/X11Application.m13
1 files changed, 11 insertions, 2 deletions
diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index fcdac240c..e7262cc12 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -1688,8 +1688,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);