diff options
Diffstat (limited to 'src/widget.cpp')
-rw-r--r-- | src/widget.cpp | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/src/widget.cpp b/src/widget.cpp index 85aacea..0d7ddcc 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -81,8 +81,8 @@ Widget::Widget(QWidget *parent) : _popupCount(0), _iProjector(QIcon(":projector")), _iScreen(QIcon(":screen")), - _lastScreenCount(0), - _isDbus(true) + _addEventDbus(false), + _addEventOther(false) { _ui->setupUi(this); // Add refresh button @@ -126,16 +126,24 @@ Widget::Widget(QWidget *parent) : // Timer QTimer *t = new QTimer(this); t->setSingleShot(true); - // Worked fine + // Timeout after screen setup changed -- handle connect(t, &QTimer::timeout, [=]() { + // Query how many screens there are now int currentCount = ScreenSetup::inst()->queryCurrentOutputCount(); - qDebug() << "Timeout. Dbus:" << _isDbus << "old count:" << _lastScreenCount << "new count:" << currentCount; - if (_isDbus && _lastScreenCount >= currentCount) - return; // Ignore dbus events if the screen count didn't change (or decreased) - if (this->isHidden()) { + qDebug() << "Timeout. Dbus:" << _addEventDbus << "X:" << _addEventOther << "old count:" << _lastScreenCount << "new count:" << currentCount; + if ((_addEventDbus && !_addEventOther) && currentCount <= _lastScreenCount) { + // Ignore dbus-only events if the screen count didn't change (or decreased) + } else if (this->isHidden()) { + // GUI is currently hidden ScreenSetup::inst()->initModes(); - _isDbus = true; - this->show(); + if (_addEventDbus && currentCount > _lastScreenCount) { // DBUS event was triggered and screen count increased - auto setup + ScreenSetup::inst()->setDefaultMode(CommandLine::testMode()); + if (!keepResolution()) { + ScreenSetup::inst()->revertChanges(); + } + } else { // Not DBus or screen count decreased - pop up GUI + this->show(); + } } else { if (currentCount > _lastScreenCount) { ScreenSetup::inst()->initModes(); @@ -144,10 +152,12 @@ Widget::Widget(QWidget *parent) : _ui->btnReload->setStyleSheet(resetButtonHotStyle); } } + _addEventDbus = false; + _addEventOther = false; }); auto popupGui = [=]() { if (this->isHidden()) { - t->start(1000); + t->start(1500); } else { _ui->btnReload->setStyleSheet(resetButtonHotStyle); } @@ -159,8 +169,7 @@ Widget::Widget(QWidget *parent) : qDebug() << "QT SEES SCREEN" << scrn->geometry(); _qtScreens.append(scrn); if (CommandLine::backgroundMode()) { - qDebug() << "Qt setting FALSE"; - _isDbus = false; + _addEventOther = true; popupGui(); } }); @@ -180,6 +189,7 @@ Widget::Widget(QWidget *parent) : qDebug() << "\\o/ Received DBus connect notification \\o/"; if (isSession) { // Session bus means user triggered, show immediately this->show(); + this->raise(); } else { // Otherwise, systembus means udev event -- take normal route popupGui(); } @@ -192,11 +202,12 @@ Widget::Widget(QWidget *parent) : _ui->btnReload->setStyleSheet(resetButtonHotStyle); } } else { - _isDbus = false; + _addEventOther = true; popupGui(); } }); } + _lastScreenCount = ScreenSetup::inst()->queryCurrentOutputCount(); } //______________________________________________________________________________ @@ -209,6 +220,7 @@ void Widget::showEvent(QShowEvent *event) QWidget::showEvent(event); initControls(true); updateWindowPlacement(true); + raise(); } static void fillCombo(QComboBox *combo, const ResolutionVector &resolutions, const QSize &preselected, const QSize &preferred = QSize()) @@ -509,7 +521,7 @@ bool Widget::keepResolution() if (skip) continue; // Show a dialog asking if the res should be kept - TimeOutDialog *keepDialog = new TimeOutDialog(15, this); + TimeOutDialog *keepDialog = new TimeOutDialog(15); QSize s = (geo.size() - keepDialog->size()) / 2; QPoint tl = geo.topLeft(); tl.rx() += s.width(); |