diff options
author | Simon Rettberg | 2019-07-02 15:55:51 +0200 |
---|---|---|
committer | Simon Rettberg | 2019-07-02 15:55:51 +0200 |
commit | d6651f307d896848372ac696e8335ac47eac8888 (patch) | |
tree | 8dc41bd8b108026620b6a40786dac919bb685c63 /src/windowmanager.cpp | |
parent | Don't bail out if default config doesn't exist (diff) | |
download | vmchooser2-d6651f307d896848372ac696e8335ac47eac8888.tar.gz vmchooser2-d6651f307d896848372ac696e8335ac47eac8888.tar.xz vmchooser2-d6651f307d896848372ac696e8335ac47eac8888.zip |
Temporarily spawn openbox if no WM is running
Diffstat (limited to 'src/windowmanager.cpp')
-rw-r--r-- | src/windowmanager.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/windowmanager.cpp b/src/windowmanager.cpp new file mode 100644 index 0000000..e5e14a3 --- /dev/null +++ b/src/windowmanager.cpp @@ -0,0 +1,43 @@ +#include "windowmanager.h" + +#include <QProcess> +#include <QTimer> +#include <QDebug> + +namespace WindowManager { + +static QProcess wm; + +void ensureRunning() +{ + wm.start(QLatin1String("openbox")); + wm.closeReadChannel(QProcess::StandardError); + wm.closeReadChannel(QProcess::StandardOutput); + wm.closeWriteChannel(); + wm.waitForStarted(1000); + QTimer::singleShot(200, []() { + if (wm.state() == QProcess::Running) { + qDebug() << "- Spawned openbox"; + } else if (wm.exitCode() == 0) { + qDebug() << "- A WM is already running"; + } else { + qDebug() << "- openbox binary not in $PATH"; + } + }); +} + +void stopOwnInstance() +{ + if (wm.state() == QProcess::Running) { + qDebug() << "- Politely terminating spawned WM"; + wm.terminate(); + QTimer::singleShot(1000, []() { + if (wm.state() == QProcess::Running) { + qDebug() << "- Forcefully killing spawned WM"; + wm.kill(); + } + }); + } +} + +} |