summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2019-10-23 14:14:54 +0200
committerSimon Rettberg2019-10-23 14:14:54 +0200
commit98ecc8a132becaa4e37939ca5f7fd2031c603565 (patch)
tree32840aba89dc4df38f36d70b3fcad9bb73f3fd31
parentUse execv() to start selected session (diff)
downloadvmchooser2-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.
-rw-r--r--src/dialog.cpp9
-rw-r--r--src/dialog.h2
-rw-r--r--src/windowmanager.cpp46
3 files changed, 44 insertions, 13 deletions
diff --git a/src/dialog.cpp b/src/dialog.cpp
index dbc4b8e..bdeab16 100644
--- a/src/dialog.cpp
+++ b/src/dialog.cpp
@@ -26,11 +26,14 @@
static bool isProcessRunning(const QString &binary);
+QDialog* Dialog::instance = nullptr;
+
static QDomDocument toDomDocument(const QString& what, const QByteArray& data, const QString& backupFile, const QString& mandatoryChild);
Dialog::Dialog(QWidget *parent)
: QDialog(parent), ui(new Ui::Dialog) {
+ instance = this;
model_[TAB_NATIVE] = new SessionTreeModel(parent);
model_[TAB_RECENT_COURSES] = new SessionTreeModel(parent, true);
model_[TAB_ALL_VMS] = new SessionTreeModel(parent);
@@ -110,6 +113,7 @@ Dialog::Dialog(QWidget *parent)
}
Dialog::~Dialog() {
+ instance = nullptr;
delete ui;
}
@@ -821,6 +825,11 @@ void Dialog::showEvent(QShowEvent *e)
});
}
+QDialog* Dialog::getInstance()
+{
+ return instance;
+}
+
static bool isProcessRunning(const QString &binary)
{
bool full = binary.contains('/');
diff --git a/src/dialog.h b/src/dialog.h
index cc7f50e..d9c5d6b 100644
--- a/src/dialog.h
+++ b/src/dialog.h
@@ -41,6 +41,7 @@ class Dialog : public QDialog {
void setTheme();
void startSession(const QString& name);
void downloadData(const QString& locationIds);
+ static QDialog* getInstance();
protected: // Overrides
void changeEvent(QEvent *e);
@@ -50,6 +51,7 @@ class Dialog : public QDialog {
void showEvent(QShowEvent * e) override;
private: // Private vars n methods
+ static QDialog* instance;
Ui::Dialog *ui;
SessionTreeModel *model_[TAB_COUNT];
QPushButton *tabs_[TAB_COUNT];
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";
+ }
+}
+
}