summaryrefslogtreecommitdiffstats
path: root/src/windowmanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/windowmanager.cpp')
-rw-r--r--src/windowmanager.cpp46
1 files changed, 33 insertions, 13 deletions
diff --git a/src/windowmanager.cpp b/src/windowmanager.cpp
index c05e234..74b1dad 100644
--- a/src/windowmanager.cpp
+++ b/src/windowmanager.cpp
@@ -1,4 +1,5 @@
#include "windowmanager.h"
+#include "dialog.h"
#include <QProcess>
#include <QTimer>
@@ -10,8 +11,12 @@ namespace WindowManager {
static QProcess wm;
+static int topCounter;
+
static void killInstance();
+static void forceChooserToTop();
+
void ensureRunning()
{
static bool once = false;
@@ -23,19 +28,11 @@ void ensureRunning()
wm.closeReadChannel(QProcess::StandardOutput);
wm.closeWriteChannel();
wm.waitForStarted(500);
- QTimer::singleShot(500, []() {
- if (wm.state() == QProcess::Running) {
- qDebug() << "- Spawned openbox";
- QObject::connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, killInstance);
- // Try to make vmchooser the foreground window again, since starting the WM after
- // vmchooser makes it lose focus
- QProcess::startDetached("wmctrl", QStringList() << "-a" << "vmchooser" << "-F");
- } else if (wm.exitCode() == 0) {
- qDebug() << "- A WM is already running";
- } else {
- qDebug() << "- openbox binary not in $PATH";
- }
- });
+ if (wm.state() == QProcess::Running) {
+ QObject::connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, killInstance);
+ }
+ topCounter = 0;
+ QTimer::singleShot(100, forceChooserToTop);
}
void stopOwnInstance(bool waitSync)
@@ -65,4 +62,27 @@ void killInstance()
}
}
+void forceChooserToTop()
+{
+ if (wm.state() == QProcess::Running) {
+ // Try to make vmchooser the foreground window again, since starting the WM after
+ // vmchooser makes it lose focus
+ QProcess::startDetached("wmctrl", QStringList() << "-a" << "vmchooser" << "-F");
+ QDialog* d = Dialog::getInstance();
+ if (d != nullptr) {
+ d->raise();
+ d->activateWindow();
+ }
+ if (++topCounter >= 13) {
+ qDebug() << "- Spawned openbox";
+ } else {
+ QTimer::singleShot(100, forceChooserToTop);
+ }
+ } else if (wm.exitCode() == 0) {
+ qDebug() << "- A WM is already running";
+ } else {
+ qDebug() << "- openbox binary not in $PATH";
+ }
+}
+
}