From 16fc5fd5a2ed33b302ba6f2d60e1cc98c223050d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Pereira?= Date: Tue, 28 Dec 2021 17:30:24 +0000 Subject: [PATCH 1/4] Don't use hardcoded xkb rules file paths. * Use xkeyboard-config at compile time to find out the xkb base data dir. * Get the rules in use with XkbRF_GetNamesProp() --- plugin-kbindicator/CMakeLists.txt | 19 +++++++- plugin-kbindicator/src/x11/kbdlayout.cpp | 59 +++++++++++++++++++++++- 2 files changed, 74 insertions(+), 4 deletions(-) diff --git a/plugin-kbindicator/CMakeLists.txt b/plugin-kbindicator/CMakeLists.txt index 29a208f9d..bf9b37e22 100644 --- a/plugin-kbindicator/CMakeLists.txt +++ b/plugin-kbindicator/CMakeLists.txt @@ -31,9 +31,22 @@ set(LIBRARIES find_package(XCB REQUIRED COMPONENTS xcb xcb-xkb) find_package(XKBCommon REQUIRED COMPONENTS XKBCommon X11) +find_package(X11 REQUIRED) find_package(Qt5 ${QT_MINIMUM_VERSION} REQUIRED COMPONENTS X11Extras Xml) -include_directories(${XCB_INCLUDE_DIRS}) +find_package(PkgConfig REQUIRED) +execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=xkb_base xkeyboard-config + OUTPUT_VARIABLE XKB_RULES_DIR + OUTPUT_STRIP_TRAILING_WHITESPACE +) +if(NOT EXISTS "${XKB_RULES_DIR}") + message(FATAL_ERROR "Couldn't find XKB rules location: \"${XKB_RULES_DIR}\".") +endif() + +include_directories( + ${XCB_INCLUDE_DIRS} + ${X11_xkbfile_INCLUDE_PATH} +) set(HEADERS ${HEADERS} @@ -48,11 +61,13 @@ set(SOURCES set(LIBRARIES ${LIBRARIES} ${XCB_LIBRARIES} + ${X11_xkbfile_LIB} XKBCommon::XKBCommon XKBCommon::X11 Qt5::Xml ) -add_definitions(-DX11_ENABLED) +add_definitions(-DX11_ENABLED -DXKB_RULES_DIR=\"${XKB_RULES_DIR}\") + BUILD_LXQT_PLUGIN(${PLUGIN}) diff --git a/plugin-kbindicator/src/x11/kbdlayout.cpp b/plugin-kbindicator/src/x11/kbdlayout.cpp index 90c2b0bcc..981542f36 100644 --- a/plugin-kbindicator/src/x11/kbdlayout.cpp +++ b/plugin-kbindicator/src/x11/kbdlayout.cpp @@ -28,11 +28,15 @@ #include #include #include +#include #include #include "kbdlayout.h" #include #include +#include +#include +#include // Note: We need to override "explicit" as this is a C++ keyword. But it is // used as variable name in xkb.h. This is causing a failure in C++ compile @@ -45,6 +49,56 @@ #include "../kbdinfo.h" #include "../controls.h" +static QString xkbRulesDir(); +static QString xkbRulesFile(); +static QString xkbRulesName(); +static void _lxqt_xkb_free_var_defs(XkbRF_VarDefsRec *var_defs); + +static QString xkbRulesDir() +{ + return QStringLiteral(XKB_RULES_DIR); +} + +static QString xkbRulesFile() +{ + QString rulesFile; + const QString rules = xkbRulesName(); + const QString xkbDir = xkbRulesDir(); + if (!rules.isEmpty()) { + rulesFile = QStringLiteral("%1/rules/%2.xml").arg(xkbDir, rules); + } else { // default + rulesFile = QStringLiteral("%1/rules/evdev.xml").arg(xkbDir); + } + return rulesFile; +} + +static QString xkbRulesName() +{ + if (!QX11Info::isPlatformX11()) { + return QString(); + } + XkbRF_VarDefsRec v{}; + char *file = nullptr; + + if (XkbRF_GetNamesProp(QX11Info::display(), &file, &v) && file != nullptr) { + const QString name = QString::fromUtf8(file); + XFree(file); + _lxqt_xkb_free_var_defs(&v); + return name; + } + return {}; +} + +static void _lxqt_xkb_free_var_defs(XkbRF_VarDefsRec *var_defs) +{ + if (var_defs == nullptr) + return; + + free(static_cast(var_defs->model)); + free(static_cast(var_defs->layout)); + free(static_cast(var_defs->variant)); + free(static_cast(var_defs->options)); +} namespace pimpl { struct LangInfo @@ -245,10 +299,11 @@ class X11Kbd: public QAbstractNativeEventFilter static LangInfo def{QStringLiteral("Unknown"), QStringLiteral("??"), QStringLiteral("None")}; static QHash names; if (names.empty()){ - if(QFile::exists(QStringLiteral("/usr/share/X11/xkb/rules/evdev.xml"))){ + const QString rulesFile{xkbRulesFile()}; + if(QFile::exists(rulesFile)){ QDomDocument doc; - QFile file(QStringLiteral("/usr/share/X11/xkb/rules/evdev.xml")); + QFile file(rulesFile); if (file.open(QIODevice::ReadOnly)){ if (doc.setContent(&file)) { QDomElement docElem = doc.documentElement(); From 2d045a4b837bc58aba9794040e2e7a9b1b581f12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Pereira?= Date: Wed, 29 Dec 2021 10:14:20 +0000 Subject: [PATCH 2/4] CMake Debug --- plugin-kbindicator/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugin-kbindicator/CMakeLists.txt b/plugin-kbindicator/CMakeLists.txt index bf9b37e22..a5e0afeef 100644 --- a/plugin-kbindicator/CMakeLists.txt +++ b/plugin-kbindicator/CMakeLists.txt @@ -43,6 +43,9 @@ if(NOT EXISTS "${XKB_RULES_DIR}") message(FATAL_ERROR "Couldn't find XKB rules location: \"${XKB_RULES_DIR}\".") endif() +message(STATUS "X11_xkbfile_INCLUDE_PATH: ${X11_xkbfile_INCLUDE_PATH}") +message(STATUS "X11_INCLUDE_DIR: ${X11_INCLUDE_DIR}") + include_directories( ${XCB_INCLUDE_DIRS} ${X11_xkbfile_INCLUDE_PATH} From 68548bb04f44e80939b31e994a92800a69e3ff66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Pereira?= Date: Wed, 29 Dec 2021 10:39:39 +0000 Subject: [PATCH 3/4] Update CI --- .ci/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/build.sh b/.ci/build.sh index fa739ccb9..bb7b56a46 100755 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -3,7 +3,7 @@ set -ex source shared-ci/prepare-archlinux.sh # See *depends in https://github.com/archlinuxcn/repo/blob/master/archlinuxcn/lxqt-panel-git/PKGBUILD -pacman -S --noconfirm --needed git cmake qt5-tools lxqt-build-tools-git alsa-lib libpulse lm_sensors libstatgrab libsysstat-git solid menu-cache libxcomposite lxmenu-data libdbusmenu-qt5 lxqt-globalkeys-git +pacman -S --noconfirm --needed git cmake qt5-tools lxqt-build-tools-git alsa-lib libpulse lm_sensors libstatgrab libsysstat-git solid menu-cache libxcomposite lxmenu-data libdbusmenu-qt5 lxqt-globalkeys-git libxkbfile cmake -B build -S . make -C build From 92985d04782c0324f605f67f99f8b9f7abd5c060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Pereira?= Date: Wed, 29 Dec 2021 11:48:36 +0000 Subject: [PATCH 4/4] Make it abort. --- .ci/build.sh | 2 +- plugin-kbindicator/CMakeLists.txt | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.ci/build.sh b/.ci/build.sh index bb7b56a46..fa739ccb9 100755 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -3,7 +3,7 @@ set -ex source shared-ci/prepare-archlinux.sh # See *depends in https://github.com/archlinuxcn/repo/blob/master/archlinuxcn/lxqt-panel-git/PKGBUILD -pacman -S --noconfirm --needed git cmake qt5-tools lxqt-build-tools-git alsa-lib libpulse lm_sensors libstatgrab libsysstat-git solid menu-cache libxcomposite lxmenu-data libdbusmenu-qt5 lxqt-globalkeys-git libxkbfile +pacman -S --noconfirm --needed git cmake qt5-tools lxqt-build-tools-git alsa-lib libpulse lm_sensors libstatgrab libsysstat-git solid menu-cache libxcomposite lxmenu-data libdbusmenu-qt5 lxqt-globalkeys-git cmake -B build -S . make -C build diff --git a/plugin-kbindicator/CMakeLists.txt b/plugin-kbindicator/CMakeLists.txt index a5e0afeef..b30cfddd7 100644 --- a/plugin-kbindicator/CMakeLists.txt +++ b/plugin-kbindicator/CMakeLists.txt @@ -34,6 +34,10 @@ find_package(XKBCommon REQUIRED COMPONENTS XKBCommon X11) find_package(X11 REQUIRED) find_package(Qt5 ${QT_MINIMUM_VERSION} REQUIRED COMPONENTS X11Extras Xml) +if(NOT X11_Xkbfile_FOUND) + MESSAGE(FATAL_ERROR "'libxkbfile' not found. Aborting") +endif() + find_package(PkgConfig REQUIRED) execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=xkb_base xkeyboard-config OUTPUT_VARIABLE XKB_RULES_DIR