#10183·deskflow

macOS client drops BCP-47 language tags, so Chinese layouts are never detected: `server layouts missing on this computer: zh`

Author: feng-qinxiangCreated Sep 25, 2026Updated Sep 25, 2026
Labels:apple: mac

Before reporting a bug, please complete the sanity checks above.

  • I have done the sanity checks, and my issue persists.

Running the latest continuous build; no crash; I searched for existing reports (queries: local layouts, layouts missing, zh-Hans, macOS layouts) and did not find one about macOS dropping BCP-47 language tags in getKeyboardLayoutList(). Verified against master today.

Deskflow version info

Deskflow: 1.26.0.470 (427ee652)
Qt: 6.11.2
System: macOS 27.2 (arm64)

Build types

  • Official release (installer/package from GitHub releases)

(Windows server: release build. macOS client: continuous build deskflow-continuous-macos-arm64.dmg.)

Deskflow configuration

  • Windows server (physical keyboard and mouse), macOS client, one monitor each.
  • The server's active layout is Chinese (zh); the client is a Mac with several Chinese input sources enabled.

What steps will reproduce the problem?

  1. On macOS, enable any Chinese input source. Apple's own Pinyin is enough (com.apple.inputmethod.SCIM / com.apple.inputmethod.SCIM.ITABC); no third-party IME is required.
  2. Start the Mac as a Deskflow client and connect to a server whose active layout is zh.
  3. Watch the client core log while the server's layout is Chinese.

Expected: the local layout list contains zh, so the server layout is not reported missing, and KeyboardLayoutManager::getMissedLayouts() can be satisfied for a Chinese layout on macOS.

Actual: the local layout list is en only. The GUI also shows the "Missing Keyboard Layouts" warning dialog and asks the user to install zh — which is not something a macOS user can do, since Chinese input sources on macOS are IMEs with BCP-47 language tags, not two-letter keylayouts.

Log output

Show log

INFO: connected to secure socket
INFO: server tls certificate info: /CN=Deskflow
INFO: local layouts: en
INFO: remote layouts: zh
WARNING: server layouts missing on this computer: zh

Additional information

Cause

AppUtilUnix::getKeyboardLayoutList() keeps a language code only if it is exactly two characters long (src/lib/deskflow/unix/AppUtilUnix.cpp, master, line 71):

cpp
std::string langCode(temporaryCString);
if (langCode.size() == 2 &&
    std::find(layoutLangCodes.begin(), layoutLangCodes.end(), langCode) == layoutLangCodes.end()) {
  layoutLangCodes.push_back(langCode);
}

// Save only first language code
break;

On macOS, Chinese input sources report a BCP-47 tag (zh-Hans), never a bare ISO 639-1 code, so every one of them is dropped and the client is left with ["en"]. This is not specific to third-party IMEs: Apple's own Pinyin is dropped the same way.

TISCreateInputSourceList(kTISCategoryKeyboardInputSource, false) (enabled sources only, the same call Deskflow makes) on this Mac:

# input source id name first language has key layout?
0 com.apple.keylayout.ABC ABC en yes
1 com.apple.inputmethod.SCIM.ITABC Pinyin – Simplified zh-Hans no (IME)
2 com.apple.inputmethod.SCIM Chinese, Simplified zh-Hans no (IME)
3 com.tencent.inputmethod.wetype.pinyin 微信输入法 zh-Hans no (IME)
4 com.tencent.inputmethod.wetype 微信输入法 zh-Hans no (IME)

Minimal reproduction of the walk (no Deskflow build required):

objc
// clang -framework Carbon -framework Foundation -o /tmp/tis-walk tis-walk.m && /tmp/tis-walk
#import <Carbon/Carbon.h>

int main(void) {
  @autoreleasepool {
    CFStringRef keys[] = {kTISPropertyInputSourceCategory};
    CFStringRef values[] = {kTISCategoryKeyboardInputSource};
    CFDictionaryRef dict = CFDictionaryCreate(NULL, (const void **)keys, (const void **)values, 1, NULL, NULL);
    CFArrayRef list = TISCreateInputSourceList(dict, false); // false = enabled only, same as Deskflow
    for (CFIndex i = 0; i < CFArrayGetCount(list); i++) {
      TISInputSourceRef src = (TISInputSourceRef)CFArrayGetValueAtIndex(list, i);
      CFStringRef sid = (CFStringRef)TISGetInputSourceProperty(src, kTISPropertyInputSourceID);
      CFArrayRef langs = (CFArrayRef)TISGetInputSourceProperty(src, kTISPropertyInputSourceLanguages);
      char id[256] = {0}, lang[64] = {0};
      CFStringGetCString(sid, id, sizeof id, kCFStringEncodingUTF8);
      if (langs && CFArrayGetCount(langs) > 0) {
        CFStringGetCString((CFStringRef)CFArrayGetValueAtIndex(langs, 0), lang, sizeof lang, kCFStringEncodingUTF8);
      }
      BOOL hasKeyLayout = TISGetInputSourceProperty(src, kTISPropertyUnicodeKeyLayoutData) != NULL;
      printf("%-40s %-10s key layout: %s\n", id, lang, hasKeyLayout ? "yes" : "no");
    }
    CFRelease(list);
  }
  return 0;
}

Proposed fix for the detection problem

Normalise the tag to its primary subtag before the length check. Keeping the two-character test is important: the wire protocol sends layouts as concatenated two-character codes (KeyboardLayoutManager::setRemoteLayouts() parses them in 2-byte chunks), so the fix must still emit only codes that are two characters long.

cpp
std::string langCode(temporaryCString);
if (auto dash = langCode.find('-'); dash != std::string::npos) {
  langCode.resize(dash);   // zh-Hans -> zh
}
if (langCode.size() == 2 &&
    std::find(layoutLangCodes.begin(), layoutLangCodes.end(), langCode) == layoutLangCodes.end()) {
  layoutLangCodes.push_back(langCode);
}

Caveat: the same list is also the language → group index map

KeyState hands this list to KeyMap::setLanguageData(), and KeyMap::getLanguageGroupID() returns the index of the language in that list as the keymap group to use. On macOS, a group index is an index into the input source list: OSXKeyState::getGroups() walks the very same TISCreateInputSourceList(..., false) array, and OSXKeyState::getKeyMap() stores one group per input source. IME groups have no kTISPropertyUnicodeKeyLayoutData, so OSXKeyState::getKeyMap() logs no keyboard resource for group %d and that group ends up with no key items.

With the normalised list and a server layout of zh, getLanguageGroupID(group, "zh") returns 1 = com.apple.inputmethod.SCIM.ITABC (Apple Pinyin), an empty group. KeyMap::getKeyItemList() then falls through to the ABC group and returns a KeyItem with m_group == 0; KeyMap::keysForKeyItem() sees group != keyItem.m_group and calls addGroupToKeystroke(), which resolves zh to index 1 again and emits an absolute group switch. On macOS that means Deskflow would try to select Apple Pinyin on every keystroke while the server layout is Chinese, silently replacing the input source the user is actually typing with, and pollActiveGroup() != group would log failed to set new keyboard layout each time.

So the normalised tags are wanted for the "is this layout installed on this computer?" question (getMissedLayouts() / isLayoutInstalled(), i.e. the GUI dialog and the warning), but the language → group mapping must not be pointed at empty IME groups by this change.

Two related observations while looking at this, which is why I did not just send the one-line patch:

  • The list is index-aligned with the group list only when every input source contributes exactly one entry. Since the current loop drops entries, en resolves to index 0 by luck on this machine (ABC is the first enabled input source); on a Mac where an IME is listed before ABC, en would already resolve to the wrong group today.
  • For key mapping, a language whose only groups are IMEs should probably keep the current group (the key layout underneath the IME is what physically produces the keysyms), while the "installed" check should accept the normalised language. That argues for separating "languages installed on this computer" from "language → usable keymap group", rather than fixing the 2-char test alone.

Related observation (happy to file separately)

can't get the active group, use the first group instead (src/lib/platform/OSXKeyState.cpp) — pollActiveGroup() looks up the kTISPropertyInputSourceID of TISCopyCurrentKeyboardLayoutInputSource() in m_groupMap, which is a std::map<CFDataRef, int32_t> compared by pointer identity, and it queries the current layout input source rather than the current input source. On this machine the lookup misses and falls back to group 0. I have seen this warning both flooding several times per second while typing on the client and almost never appearing.

I have a standalone self-check program (clang, Carbon + Foundation) that reproduces the current and the proposed behaviour side by side and prints the resulting group index and whether that group has a key layout, if that is useful for the fix — let me know and I will attach it.