summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2019-07-02 15:55:51 +0200
committerSimon Rettberg2019-07-02 15:55:51 +0200
commitd6651f307d896848372ac696e8335ac47eac8888 (patch)
tree8dc41bd8b108026620b6a40786dac919bb685c63
parentDon't bail out if default config doesn't exist (diff)
downloadvmchooser2-d6651f307d896848372ac696e8335ac47eac8888.tar.gz
vmchooser2-d6651f307d896848372ac696e8335ac47eac8888.tar.xz
vmchooser2-d6651f307d896848372ac696e8335ac47eac8888.zip
Temporarily spawn openbox if no WM is running
-rw-r--r--src/dialog.cpp6
-rw-r--r--src/windowmanager.cpp43
-rw-r--r--src/windowmanager.h22
3 files changed, 71 insertions, 0 deletions
diff --git a/src/dialog.cpp b/src/dialog.cpp
index a23e3ce..932f28c 100644
--- a/src/dialog.cpp
+++ b/src/dialog.cpp
@@ -22,11 +22,16 @@
#include "vsession.h"
#include "userconfig.h"
#include "filedownloader.h"
+#include "windowmanager.h"
static bool isProcessRunning(const QString &binary);
Dialog::Dialog(QWidget *parent)
: QDialog(parent), ui(new Ui::Dialog) {
+
+ // Make sure a window manager is running, so any modals or other popups work properly
+ WindowManager::ensureRunning();
+
model_[TAB_NATIVE] = new SessionTreeModel(parent);
model_[TAB_RECENT_COURSES] = new SessionTreeModel(parent, true);
model_[TAB_ALL_VMS] = new SessionTreeModel(parent);
@@ -153,6 +158,7 @@ void Dialog::on_treeView_doubleClicked(const QModelIndex& index)
// Run session
if (s->run()) {
+ WindowManager::stopOwnInstance();
// Run session start script if the session could be initialized successfully
if (QFile::exists(SESSION_START_SCRIPT)) {
// Use the current environment variables and add the necessary
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();
+ }
+ });
+ }
+}
+
+}
diff --git a/src/windowmanager.h b/src/windowmanager.h
new file mode 100644
index 0000000..c89f983
--- /dev/null
+++ b/src/windowmanager.h
@@ -0,0 +1,22 @@
+#ifndef _WINDOWSMANAGER_H_
+#define _WINDOWSMANAGER_H_
+
+namespace WindowManager
+{
+
+/**
+ * Make sure a window manager is running.
+ * If none is running, start openbox.
+ */
+void ensureRunning();
+
+/**
+ * If we started openbox as the window manager,
+ * terminate it, otherwise leave the current
+ * one running.
+ */
+void stopOwnInstance();
+
+}
+
+#endif