Skip to content

Don't use hardcoded xkb rules file paths. #807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lxqt-config-input/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@ project(lxqt-config-input)

find_package(X11 REQUIRED)

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()

if (WITH_TOUCHPAD)
find_package(PkgConfig REQUIRED)
pkg_check_modules(XORG_LIBINPUT REQUIRED xorg-libinput)
pkg_check_modules(XORG_XI REQUIRED xi)
pkg_check_modules(LIBUDEV REQUIRED libudev)
Expand All @@ -27,6 +35,7 @@ endif ()

include_directories(
${lxqt-config-input_INCS}
${X11_xkbfile_INCLUDE_PATH}
)

set(lxqt-config-input_HDRS
Expand Down Expand Up @@ -102,6 +111,7 @@ set(lxqt-config-input_TLBS
Qt5::Widgets
Qt5::X11Extras
${X11_LIBRARIES}
${X11_xkbfile_LIB}
lxqt
lxqt-config-cursor
)
Expand All @@ -114,6 +124,11 @@ if (WITH_TOUCHPAD)
)
endif ()

target_compile_definitions(lxqt-config-input
PRIVATE
"XKB_RULES_DIR=\"${XKB_RULES_DIR}\""
)

target_link_libraries(lxqt-config-input
${lxqt-config-input_TLBS}
)
Expand Down
60 changes: 57 additions & 3 deletions lxqt-config-input/keyboardlayoutconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,65 @@
#include <QFile>
#include <QHash>
#include <QDebug>
#include <QX11Info>
#include "selectkeyboardlayoutdialog.h"
#include <LXQt/Settings>

#include <X11/Xlib.h>
#include <X11/XKBlib.h>
#include <X11/extensions/XKBrules.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.lst").arg(xkbDir, rules);
} else { // default
rulesFile = QStringLiteral("%1/rules/evdev.lst").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<void *>(var_defs->model));
free(static_cast<void *>(var_defs->layout));
free(static_cast<void *>(var_defs->variant));
free(static_cast<void *>(var_defs->options));
}

KeyboardLayoutConfig::KeyboardLayoutConfig(LXQt::Settings* _settings, QWidget* parent):
QWidget(parent),
settings(_settings),
Expand Down Expand Up @@ -101,9 +157,7 @@ enum ListSection{
};

void KeyboardLayoutConfig::loadLists() {
// load known lists from xkb data files
// XKBD_BASELIST_PATH is os dependent see keyboardlayoutconfig.h
QFile file(QLatin1String(XKBD_BASELIST_PATH));
QFile file(xkbRulesFile());
if(file.open(QIODevice::ReadOnly)) {
ListSection section = NoSection;
while(!file.atEnd()) {
Expand Down
10 changes: 0 additions & 10 deletions lxqt-config-input/keyboardlayoutconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@
#define KEYBOARDLAYOUTCONFIG_H

#include <QtCore/QtGlobal>
#ifdef Q_OS_LINUX
#define XKBD_BASELIST_PATH "/usr/share/X11/xkb/rules/base.lst"
#elif defined(Q_OS_FREEBSD)
#define XKBD_BASELIST_PATH "/usr/local/share/X11/xkb/rules/base.lst"
#elif defined(Q_OS_OPENBSD)
#define XKBD_BASELIST_PATH "/usr/X11R6/share/X11/xkb/rules/base.lst"
#else
#define XKBD_BASELIST_PATH "/usr/local/share/X11/xkb/rules/base.lst"
#endif

#include <QWidget>
#include "keyboardlayoutinfo.h"
#include <QMap>
Expand Down