From 8c2006ddc5abbd4ac374dabf1cfdd3df8fc88779 Mon Sep 17 00:00:00 2001 From: Jon Turney Date: Mon, 22 Feb 2016 17:41:14 +0000 Subject: xwin: Keyboard layout updates layout zh_TW doesn't exist (anymore), try something else for that. layout it variant mac doesn't seem to exist anymore, try to handle Macintosh keyboards (running under Parallels on Mac) and other oddities in a more generic way, by falling back to matching only on the language identifer part of the input locale identifer. v2: Fix typo of 0xa0000 for 0xa000 Signed-off-by: Jon Turney Reviewed-by: Colin Harrison --- hw/xwin/winconfig.c | 74 ++++++++++++++++++++++++++++++---------------------- hw/xwin/winlayouts.h | 4 +-- 2 files changed, 45 insertions(+), 33 deletions(-) (limited to 'hw/xwin') diff --git a/hw/xwin/winconfig.c b/hw/xwin/winconfig.c index d26cc9376..fb99113d5 100644 --- a/hw/xwin/winconfig.c +++ b/hw/xwin/winconfig.c @@ -224,7 +224,8 @@ winConfigKeyboard(DeviceIntPtr pDevice) { char layoutName[KL_NAMELENGTH]; unsigned char layoutFriendlyName[256]; - static unsigned int layoutNum = 0; + unsigned int layoutNum = 0; + unsigned int deviceIdentifier = 0; int keyboardType; #ifdef XWIN_XF86CONFIG @@ -272,15 +273,10 @@ winConfigKeyboard(DeviceIntPtr pDevice) if (keyboardType > 0 && GetKeyboardLayoutName(layoutName)) { WinKBLayoutPtr pLayout; Bool bfound = FALSE; + int pass; - if (!layoutNum) - layoutNum = strtoul(layoutName, (char **) NULL, 16); + layoutNum = strtoul(layoutName, (char **) NULL, 16); if ((layoutNum & 0xffff) == 0x411) { - /* The japanese layouts know a lot of different IMEs which all have - different layout numbers set. Map them to a single entry. - Same might apply for chinese, korean and other symbol languages - too */ - layoutNum = (layoutNum & 0xffff); if (keyboardType == 7) { /* Japanese layouts have problems with key event messages such as the lack of WM_KEYUP for Caps Lock key. @@ -318,31 +314,47 @@ winConfigKeyboard(DeviceIntPtr pDevice) "Windows keyboard layout: \"%s\" (%08x) \"%s\", type %d\n", layoutName, layoutNum, layoutFriendlyName, keyboardType); - for (pLayout = winKBLayouts; pLayout->winlayout != -1; pLayout++) { - if (pLayout->winlayout != layoutNum) - continue; - if (pLayout->winkbtype > 0 && pLayout->winkbtype != keyboardType) - continue; - - bfound = TRUE; - winMsg(X_PROBED, - "Found matching XKB configuration \"%s\"\n", - pLayout->layoutname); - - winMsg(X_PROBED, - "Model = \"%s\" Layout = \"%s\"" - " Variant = \"%s\" Options = \"%s\"\n", - pLayout->xkbmodel ? pLayout->xkbmodel : "none", - pLayout->xkblayout ? pLayout->xkblayout : "none", - pLayout->xkbvariant ? pLayout->xkbvariant : "none", - pLayout->xkboptions ? pLayout->xkboptions : "none"); + deviceIdentifier = layoutNum >> 16; + for (pass = 0; pass < 2; pass++) { + /* If we didn't find an exact match for the input locale identifer, + try to find an match on the language identifier part only */ + if (pass == 1) + layoutNum = (layoutNum & 0xffff); + + for (pLayout = winKBLayouts; pLayout->winlayout != -1; pLayout++) { + if (pLayout->winlayout != layoutNum) + continue; + if (pLayout->winkbtype > 0 && pLayout->winkbtype != keyboardType) + continue; + + bfound = TRUE; + winMsg(X_PROBED, + "Found matching XKB configuration \"%s\"\n", + pLayout->layoutname); + + winMsg(X_PROBED, + "Model = \"%s\" Layout = \"%s\"" + " Variant = \"%s\" Options = \"%s\"\n", + pLayout->xkbmodel ? pLayout->xkbmodel : "none", + pLayout->xkblayout ? pLayout->xkblayout : "none", + pLayout->xkbvariant ? pLayout->xkbvariant : "none", + pLayout->xkboptions ? pLayout->xkboptions : "none"); + + g_winInfo.xkb.model = pLayout->xkbmodel; + g_winInfo.xkb.layout = pLayout->xkblayout; + g_winInfo.xkb.variant = pLayout->xkbvariant; + g_winInfo.xkb.options = pLayout->xkboptions; + + if (deviceIdentifier == 0xa000) { + winMsg(X_PROBED, "Windows keyboard layout device identifier indicates Macintosh, setting Model = \"macintosh\""); + g_winInfo.xkb.model = "macintosh"; + } - g_winInfo.xkb.model = pLayout->xkbmodel; - g_winInfo.xkb.layout = pLayout->xkblayout; - g_winInfo.xkb.variant = pLayout->xkbvariant; - g_winInfo.xkb.options = pLayout->xkboptions; + break; + } - break; + if (bfound) + break; } if (!bfound) { diff --git a/hw/xwin/winlayouts.h b/hw/xwin/winlayouts.h index d3d5c6df3..c7905e3c2 100644 --- a/hw/xwin/winlayouts.h +++ b/hw/xwin/winlayouts.h @@ -42,7 +42,8 @@ typedef struct { */ WinKBLayoutRec winKBLayouts[] = { - {0x00000404, -1, "pc105", "zh_TW", NULL, NULL, "Chinese (Taiwan)"}, + {0x00000404, -1, "pc105", "cn", NULL, NULL, "Chinese (Traditional)"}, + {0x00000804, -1, "pc105", "cn", NULL, NULL, "Chinese (Simplified)"}, {0x00000405, -1, "pc105", "cz", NULL, NULL, "Czech"}, {0x00010405, -1, "pc105", "cz_qwerty", NULL, NULL, "Czech (QWERTY)"}, {0x00000406, -1, "pc105", "dk", NULL, NULL, "Danish"}, @@ -72,7 +73,6 @@ WinKBLayoutRec winKBLayouts[] = { {0x0000040f, -1, "pc105", "is", NULL, NULL, "Icelandic"}, {0x00000410, -1, "pc105", "it", NULL, NULL, "Italian"}, {0x00010410, -1, "pc105", "it", NULL, NULL, "Italian (142)"}, - {0xa0000410, -1, "macbook79", "it", "mac", NULL, "Italiano (Apple)"}, {0x00000411, 7, "jp106", "jp", NULL, NULL, "Japanese"}, {0x00000412, -1, "kr106", "kr", NULL, NULL, "Korean"}, {0x00000413, -1, "pc105", "nl", NULL, NULL, "Dutch"}, -- cgit v1.2.3