diff options
author | Simon Rettberg | 2019-10-23 14:14:54 +0200 |
---|---|---|
committer | Simon Rettberg | 2019-10-23 14:14:54 +0200 |
commit | 98ecc8a132becaa4e37939ca5f7fd2031c603565 (patch) | |
tree | 32840aba89dc4df38f36d70b3fcad9bb73f3fd31 /src/windowmanager.cpp | |
parent | Use execv() to start selected session (diff) | |
download | vmchooser2-98ecc8a132becaa4e37939ca5f7fd2031c603565.tar.gz vmchooser2-98ecc8a132becaa4e37939ca5f7fd2031c603565.tar.xz vmchooser2-98ecc8a132becaa4e37939ca5f7fd2031c603565.zip |
Try even harder to restore focus after spawning openbox
I just need a bigger hammer.
Diffstat (limited to 'src/windowmanager.cpp')
-rw-r--r-- | src/windowmanager.cpp | 46 |
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"; + } +} + } |