summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2019-07-04 15:04:58 +0200
committerSimon Rettberg2019-07-04 15:04:58 +0200
commit65a4fff11c84c886bce97e103f6177becd34c879 (patch)
treefd0e639b21c1663f73db05b683b192ac2d6cc7b5 /src
parentGive 'last lectures' a section as it's expected everywhere (diff)
downloadvmchooser2-65a4fff11c84c886bce97e103f6177becd34c879.tar.gz
vmchooser2-65a4fff11c84c886bce97e103f6177becd34c879.tar.xz
vmchooser2-65a4fff11c84c886bce97e103f6177becd34c879.zip
Change WM spawning once again to hopefully fix invisible chooser
Now we wait until the chooser window is actually visible and only then try to spawn openbox. This leads to the problem of vmchooser not having focus in case we really didn't have a WM before. For that reason, try to give focus to vmchooser again by calling wmctrl...........
Diffstat (limited to 'src')
-rw-r--r--src/dialog.cpp15
-rw-r--r--src/dialog.h1
-rw-r--r--src/windowmanager.cpp28
3 files changed, 27 insertions, 17 deletions
diff --git a/src/dialog.cpp b/src/dialog.cpp
index 56860f2..a0b9a47 100644
--- a/src/dialog.cpp
+++ b/src/dialog.cpp
@@ -29,9 +29,6 @@ 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);
@@ -732,7 +729,7 @@ void Dialog::onTabButtonChanged(int tab) {
}
// Update pressed status of buttons
- for (int i = 0; i < 3; ++i) {
+ for (int i = 0; i < TAB_COUNT; ++i) {
tabs_[i]->setChecked(tab == i);
}
@@ -871,6 +868,7 @@ void Dialog::selectFirstElement() {
QModelIndex newIndex = QModelIndex(model_[activeTab_]->index(0, 0, section));
ui->treeView->selectionModel()->setCurrentIndex(newIndex, QItemSelectionModel::Select);
+
ui->treeView->setFocus();
}
@@ -917,6 +915,15 @@ void Dialog::checkAutostart() {
}
}
+void Dialog::showEvent(QShowEvent *e)
+{
+ QDialog::showEvent(e);
+ // Make sure a window manager is running, so any modals or other popups work properly
+ QTimer::singleShot(10, []() {
+ WindowManager::ensureRunning();
+ });
+}
+
static bool isProcessRunning(const QString &binary)
{
bool full = binary.contains('/');
diff --git a/src/dialog.h b/src/dialog.h
index 5c3af17..cc7f50e 100644
--- a/src/dialog.h
+++ b/src/dialog.h
@@ -47,6 +47,7 @@ class Dialog : public QDialog {
void mousePressEvent(QMouseEvent *event);
bool eventFilter(QObject *target, QEvent *event);
void keyPressEvent(QKeyEvent * e);
+ void showEvent(QShowEvent * e) override;
private: // Private vars n methods
Ui::Dialog *ui;
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()