From be6ac69f75acb1114de439fbe70e7636850c2211 Mon Sep 17 00:00:00 2001 From: Marcelo Fernandez Date: Mon, 30 Oct 2017 11:40:42 -0300 Subject: Implemented OS get_latin_keyboard_variant on x11 --- platform/x11/os_x11.cpp | 32 ++++++++++++++++++++++++++++++++ platform/x11/os_x11.h | 2 ++ 2 files changed, 34 insertions(+) diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 48e2d8f81e..d5f0efaf00 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -2253,6 +2253,38 @@ Error OS_X11::move_to_trash(const String &p_path) { return err; } +OS::LatinKeyboardVariant OS_X11::get_latin_keyboard_variant() const { + + XkbDescRec *xkbdesc = XkbAllocKeyboard(); + ERR_FAIL_COND_V(!xkbdesc, LATIN_KEYBOARD_QWERTY); + + XkbGetNames(x11_display, XkbSymbolsNameMask, xkbdesc); + ERR_FAIL_COND_V(!xkbdesc->names, LATIN_KEYBOARD_QWERTY); + ERR_FAIL_COND_V(!xkbdesc->names->symbols, LATIN_KEYBOARD_QWERTY); + + char *layout = XGetAtomName(x11_display, xkbdesc->names->symbols); + ERR_FAIL_COND_V(!layout, LATIN_KEYBOARD_QWERTY); + + Vector info = String(layout).split("+"); + ERR_FAIL_INDEX_V(1, info.size(), LATIN_KEYBOARD_QWERTY); + + /*if (info[1].find("colemak") != -1) { + return LATIN_KEYBOARD_COLEMAK; + } else*/ if (info[1].find("qwertz") != -1) { + return LATIN_KEYBOARD_QWERTZ; + } else if (info[1].find("azerty") != -1) { + return LATIN_KEYBOARD_AZERTY; + } else if (info[1].find("qzerty") != -1) { + return LATIN_KEYBOARD_QZERTY; + } else if (info[1].find("dvorak") != -1) { + return LATIN_KEYBOARD_DVORAK; + } else if (info[1].find("neo") != -1) { + return LATIN_KEYBOARD_NEO; + } + + return LATIN_KEYBOARD_QWERTY; +} + OS_X11::OS_X11() { #ifdef PULSEAUDIO_ENABLED diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index 36355f11bc..b71b456d49 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -275,6 +275,8 @@ public: virtual Error move_to_trash(const String &p_path); + virtual LatinKeyboardVariant get_latin_keyboard_variant() const; + OS_X11(); }; -- cgit v1.2.3