summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Huddleston Sequoia <jeremyhu@apple.com>2021-02-01 16:27:38 -0800
committerJeremy Huddleston Sequoia <jeremyhu@apple.com>2021-02-17 09:56:56 -0800
commit972ec24e0cf4f69b6087acb8464585fd97e41cf6 (patch)
tree531c3962044d22f2fd20be394965e09bba030480
parent9f72dc854bc2402ad575ec98f368e404d4f88f72 (diff)
downloadxserver-972ec24e0cf4f69b6087acb8464585fd97e41cf6.tar.gz
xquartz: Ensure we call into TIS on the main thread
There is a place where this code was called on the main thread. We're using a rather nasty anti-pattern to just call a block inline rather than synchonously calling it on the main thread if we're already on the main thread. This code could use a good overhaul, but I don't have time to rip it apart right now. This will address the immediate issue. Fixes: https://github.com/XQuartz/XQuartz/issues/40 Fixes: https://github.com/XQuartz/XQuartz/issues/48 Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com> (cherry picked from commit c9a3b14c1472632afaff340f73a77a2b961f195a)
-rw-r--r--hw/xquartz/quartzKeyboard.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/hw/xquartz/quartzKeyboard.c b/hw/xquartz/quartzKeyboard.c
index d854cd196..b16b7b34f 100644
--- a/hw/xquartz/quartzKeyboard.c
+++ b/hw/xquartz/quartzKeyboard.c
@@ -757,23 +757,33 @@ make_dead_key(KeySym in)
static Bool
QuartzReadSystemKeymap(darwinKeyboardInfo *info)
{
- const void *chr_data = NULL;
+ __block const void *chr_data = NULL;
int num_keycodes = NUM_KEYCODES;
- UInt32 keyboard_type = LMGetKbdType();
+ __block UInt32 keyboard_type;
int i, j;
OSStatus err;
KeySym *k;
- CFDataRef currentKeyLayoutDataRef = NULL;
- TISInputSourceRef currentKeyLayoutRef =
- TISCopyCurrentKeyboardLayoutInputSource();
+ dispatch_block_t getKeyboardData = ^{
+ keyboard_type = LMGetKbdType();
- if (currentKeyLayoutRef) {
- currentKeyLayoutDataRef = (CFDataRef)TISGetInputSourceProperty(
- currentKeyLayoutRef, kTISPropertyUnicodeKeyLayoutData);
- if (currentKeyLayoutDataRef)
- chr_data = CFDataGetBytePtr(currentKeyLayoutDataRef);
- CFRelease(currentKeyLayoutRef);
+ TISInputSourceRef currentKeyLayoutRef = TISCopyCurrentKeyboardLayoutInputSource();
+
+ if (currentKeyLayoutRef) {
+ CFDataRef currentKeyLayoutDataRef = (CFDataRef)TISGetInputSourceProperty(currentKeyLayoutRef,
+ kTISPropertyUnicodeKeyLayoutData);
+ if (currentKeyLayoutDataRef)
+ chr_data = CFDataGetBytePtr(currentKeyLayoutDataRef);
+
+ CFRelease(currentKeyLayoutRef);
+ }
+ };
+
+ /* This is an ugly ant-pattern, but it is more expedient to address the problem right now. */
+ if (pthread_main_np()) {
+ getKeyboardData();
+ } else {
+ dispatch_sync(dispatch_get_main_queue(), getKeyboardData);
}
if (chr_data == NULL) {