From 855827ed4529e564d67dfb337397358613f75e0c Mon Sep 17 00:00:00 2001 From: gfgit Date: Mon, 27 Nov 2023 23:24:56 +0100 Subject: [PATCH] Warn if setxkbmap is not installed Also show command output in case it fails. --- lxqt-config-input/keyboardlayoutconfig.cpp | 33 ++++++++++++++++++++-- lxqt-config-input/keyboardlayoutconfig.h | 3 ++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lxqt-config-input/keyboardlayoutconfig.cpp b/lxqt-config-input/keyboardlayoutconfig.cpp index fe9d1ad65..3bb88cb1e 100644 --- a/lxqt-config-input/keyboardlayoutconfig.cpp +++ b/lxqt-config-input/keyboardlayoutconfig.cpp @@ -19,6 +19,7 @@ */ #include "keyboardlayoutconfig.h" +#include #include #include #include @@ -58,6 +59,13 @@ void KeyboardLayoutConfig::loadSettings() { QProcess setxkbmap; setxkbmap.start(QLatin1String("setxkbmap"), QStringList() << QLatin1String("-query") << QLatin1String("-verbose") << QLatin1String("5")); + + if(!setxkbmap.waitForStarted(TimeoutSetXkbMap_msec) || setxkbmap.error() == QProcess::FailedToStart) + { + warnSetXkbMapNotFound(); + return; + } + setxkbmap.waitForFinished(); if(setxkbmap.exitStatus() == QProcess::NormalExit) { QList layouts, variants; @@ -205,6 +213,12 @@ void KeyboardLayoutConfig::addLayout(QString name, QString variant) { ui.layouts->addTopLevelItem(item); } +void KeyboardLayoutConfig::warnSetXkbMapNotFound() +{ + QMessageBox::warning(this, tr("Command Not Found"), + tr("setxkbmap command was not found. Make sure it's installed.")); +} + void KeyboardLayoutConfig::reset() { applyConfig_ = true; ui.layouts->clear(); @@ -217,14 +231,22 @@ void KeyboardLayoutConfig::applyConfig() { return; applyConfig_ = false; + const QString program = QStringLiteral("setxkbmap"); + // call setxkbmap to apply the changes QProcess setxkbmap; // clear existing options - setxkbmap.start(QStringLiteral("setxkbmap"), QStringList() << QStringLiteral("-option")); + setxkbmap.start(program, QStringList() << QStringLiteral("-option")); + + if(!setxkbmap.waitForStarted(TimeoutSetXkbMap_msec) || setxkbmap.error() == QProcess::FailedToStart) + { + warnSetXkbMapNotFound(); + return; + } + setxkbmap.waitForFinished(); setxkbmap.close(); - const QString program = QStringLiteral("setxkbmap"); QStringList args; // set keyboard model QString model; @@ -277,6 +299,13 @@ void KeyboardLayoutConfig::applyConfig() { // execute the command line setxkbmap.start(program, args); setxkbmap.waitForFinished(); + if(setxkbmap.exitCode() != 0) + { + QMessageBox::warning(this, tr("Command Failed"), + tr("setxkbmap error:
" + "%1").arg(QString::fromLocal8Bit(setxkbmap.readAllStandardError()))); + return; + } // save to lxqt-session config file. settings->beginGroup(QStringLiteral("Keyboard")); diff --git a/lxqt-config-input/keyboardlayoutconfig.h b/lxqt-config-input/keyboardlayoutconfig.h index bfe5a0f55..7f1de21f2 100644 --- a/lxqt-config-input/keyboardlayoutconfig.h +++ b/lxqt-config-input/keyboardlayoutconfig.h @@ -64,6 +64,7 @@ public Q_SLOTS: void loadLists(); void initControls(); void addLayout(QString name, QString variant); + void warnSetXkbMapNotFound(); private: Ui::KeyboardLayoutConfig ui; @@ -74,6 +75,8 @@ public Q_SLOTS: QMap knownLayouts_; LXQt::Settings* settings; bool applyConfig_; + + static constexpr int TimeoutSetXkbMap_msec = 100; }; #endif // KEYBOARDLAYOUTCONFIG_H