diff options
author | Simon Rettberg | 2019-10-18 19:33:20 +0200 |
---|---|---|
committer | Simon Rettberg | 2019-10-18 19:33:20 +0200 |
commit | 31777a980e0f4b1b258713158524c0cd9a1dc30f (patch) | |
tree | 459c5bff4bcb2ff5c8c4d7b40f47bbcaf5d59f54 /src/xsession.cpp | |
parent | Properly handle key press events; prevent double-execution (diff) | |
download | vmchooser2-31777a980e0f4b1b258713158524c0cd9a1dc30f.tar.gz vmchooser2-31777a980e0f4b1b258713158524c0cd9a1dc30f.tar.xz vmchooser2-31777a980e0f4b1b258713158524c0cd9a1dc30f.zip |
Use execv() to start selected session
Prevent vmchooser from lingering in the background, like a zombie,
haunting you with invisible windows. Also seems to be notably faster
when launching the openbox session.
Diffstat (limited to 'src/xsession.cpp')
-rw-r--r-- | src/xsession.cpp | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/src/xsession.cpp b/src/xsession.cpp index 05f4d38..5db3b11 100644 --- a/src/xsession.cpp +++ b/src/xsession.cpp @@ -2,8 +2,8 @@ #include <QSettings> #include <QLocale> #include <QApplication> -#include <QProcess> #include <QStandardPaths> +#include "unistd.h" #include "xsession.h" #include "globals.h" @@ -18,10 +18,11 @@ struct DisplayConfig { static QList< DisplayConfig > priorityList; -void XSession::init(const QString& name, const QString& exec, +void XSession::init(const QString& name, const QString& exec, const QString& tryExec, const QString& comment, const QString& icon) { this->name_ = name; this->exec_ = exec; + this->tryExec_ = tryExec; this->comment_ = comment; this->icon_ = icon; this->priority_ = 0; @@ -43,6 +44,7 @@ bool XSession::init(const QString& filename) { return false; } QString exec(settings.value("Exec").toString()); + QString tryExec(settings.value("TryExec").toString()); QString locale(QLocale::system().name()); QString language(locale.split("_").at(0)); QString defaultName(""); @@ -100,11 +102,10 @@ bool XSession::init(const QString& filename) { this->name_ = name; this->exec_ = exec; + this->tryExec_ = tryExec; this->comment_ = comment; this->icon_ = icon; - _process = new QProcess(); - return true; } @@ -113,7 +114,12 @@ bool XSession::isActive() const { } QString XSession::checkCanRunInternal() const { - QString exe = this->exec_.left(this->exec_.indexOf(' ')); // -1 means entire string + QString exe; + if (this->tryExec_.isEmpty()) { + exe = this->exec_.left(this->exec_.indexOf(' ')); // -1 means entire string + } else { + exe = this->tryExec_; + } QFileInfo fi(exe); if (!fi.isAbsolute()) { if (!QStandardPaths::findExecutable(exe).isEmpty()) @@ -156,10 +162,21 @@ QIcon XSession::icon() const { return retIcon; } -bool XSession::run() const { - _process->start(this->exec_); - QObject::connect(_process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), QApplication::instance(), &QCoreApplication::quit); - return _process->state() == QProcess::Starting || _process->state() == QProcess::Running; +bool XSession::prepareRun() const { + return canRun(true); +} + +void XSession::run() const { + QString command; + QString firstToken = this->exec_.left(this->exec_.indexOf(' ')); + if (!firstToken.contains('=')) { // First token doesn't appear to be environment modification, try to prefix with exec + command += "exec "; + } + command += exec_; + qDebug() << "Running via /bin/sh:" << command; + QByteArray cmdbin = command.toUtf8(); + char *argv[4] = { "/bin/sh", "-c", cmdbin.data(), nullptr }; + execv("/bin/sh", argv); } int XSession::type() const { |