diff options
Diffstat (limited to 'src/windowmanager.cpp')
-rw-r--r-- | src/windowmanager.cpp | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/windowmanager.cpp b/src/windowmanager.cpp index e85a08e..077801e 100644 --- a/src/windowmanager.cpp +++ b/src/windowmanager.cpp @@ -14,24 +14,26 @@ static void killInstance(); void ensureRunning() { + static bool once = false; + if (once) + return; + once = true; wm.start(QLatin1String("openbox")); wm.closeReadChannel(QProcess::StandardError); wm.closeReadChannel(QProcess::StandardOutput); wm.closeWriteChannel(); wm.waitForStarted(500); - // Ugly, but if openbox initializes just as we map - // the main window, it might become invisible - for (int i = 0; i < 10 && wm.state() == QProcess::Running; ++i) { - QThread::msleep(25); - } - if (wm.state() == QProcess::Running) { - qDebug() << "- Spawned openbox"; - QObject::connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, killInstance); - } else if (wm.exitCode() == 0) { - qDebug() << "- A WM is already running"; - } else { - qDebug() << "- openbox binary not in $PATH"; - } + QTimer::singleShot(100, []() { + if (wm.state() == QProcess::Running) { + qDebug() << "- Spawned openbox"; + QObject::connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, killInstance); + 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"; + } + }); } void stopOwnInstance() |