Skip to content
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

Warn if setxkbmap is not installed #968

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
33 changes: 31 additions & 2 deletions lxqt-config-input/keyboardlayoutconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

#include "keyboardlayoutconfig.h"
#include <QMessageBox>
#include <QProcess>
#include <QFile>
#include <QHash>
Expand Down Expand Up @@ -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<QByteArray> layouts, variants;
Expand Down Expand Up @@ -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("<b>setxkbmap</b> command was not found. Make sure it's installed."));
}

void KeyboardLayoutConfig::reset() {
applyConfig_ = true;
ui.layouts->clear();
Expand All @@ -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;
Expand Down Expand Up @@ -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("<b>setxkbmap</b> error: <br>"
"%1").arg(QString::fromLocal8Bit(setxkbmap.readAllStandardError())));
return;
}

// save to lxqt-session config file.
settings->beginGroup(QStringLiteral("Keyboard"));
Expand Down
3 changes: 3 additions & 0 deletions lxqt-config-input/keyboardlayoutconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public Q_SLOTS:
void loadLists();
void initControls();
void addLayout(QString name, QString variant);
void warnSetXkbMapNotFound();

private:
Ui::KeyboardLayoutConfig ui;
Expand All @@ -74,6 +75,8 @@ public Q_SLOTS:
QMap<QString, KeyboardLayoutInfo> knownLayouts_;
LXQt::Settings* settings;
bool applyConfig_;

static constexpr int TimeoutSetXkbMap_msec = 100;
};

#endif // KEYBOARDLAYOUTCONFIG_H