diff options
author | Simon Rettberg | 2018-09-10 13:40:39 +0200 |
---|---|---|
committer | Simon Rettberg | 2018-09-10 13:40:39 +0200 |
commit | 00810fccc19c2becaf07e3275aa5b7f5f18a6437 (patch) | |
tree | 44947177cd6ba4e240427ca8fc243169bde941d8 | |
parent | Fix compilation of xx.cpp (diff) | |
download | beamergui-00810fccc19c2becaf07e3275aa5b7f5f18a6437.tar.gz beamergui-00810fccc19c2becaf07e3275aa5b7f5f18a6437.tar.xz beamergui-00810fccc19c2becaf07e3275aa5b7f5f18a6437.zip |
Change popup logic yet again
-rw-r--r-- | src/widget.cpp | 37 | ||||
-rw-r--r-- | src/widget.h | 1 |
2 files changed, 25 insertions, 13 deletions
diff --git a/src/widget.cpp b/src/widget.cpp index 0d7ddcc..fba46a7 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -68,8 +68,8 @@ static void addBoldListener(QComboBox *combo) }); } -static const QString resetButtonStyle("padding: 2px; margin: 0 0 1px 1px;"); -static const QString resetButtonHotStyle(resetButtonStyle + "background-color: #f99;"); +static const QString STYLE_RELOAD_BUTTON_NORMAL("padding: 2px; margin: 0 0 1px 1px;"); +static const QString STYLE_RELOAD_BUTTON_HOT(STYLE_RELOAD_BUTTON_NORMAL + "background-color: #f99;"); /* * Main widget @@ -86,10 +86,10 @@ Widget::Widget(QWidget *parent) : { _ui->setupUi(this); // Add refresh button - _ui->btnReload->setStyleSheet(resetButtonStyle); + _ui->btnReload->setStyleSheet(STYLE_RELOAD_BUTTON_NORMAL); _ui->tabWidget->setCornerWidget(_ui->btnReload); connect(_ui->btnReload, &QPushButton::clicked, [=](bool) { - _ui->btnReload->setStyleSheet(resetButtonStyle); + _ui->btnReload->setStyleSheet(STYLE_RELOAD_BUTTON_NORMAL); ScreenSetup::inst()->initModes(); initControls(); }); @@ -131,27 +131,32 @@ Widget::Widget(QWidget *parent) : // Query how many screens there are now int currentCount = ScreenSetup::inst()->queryCurrentOutputCount(); 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) + if (_addEventDbus && !_addEventOther) { + // Only dbus reported a change -- wait some more in case we have link flap (don't make it worse than it already is) + t->start(2000); // If no other DBus event fires within 2 secs, we'll continue below next time } else if (this->isHidden()) { // GUI is currently hidden - ScreenSetup::inst()->initModes(); - if (_addEventDbus && currentCount > _lastScreenCount) { // DBUS event was triggered and screen count increased - auto setup + if (currentCount == _lastScreenCount) { + // Nothing seems to have changed. This might happen when another tool changes the screen config. Let's not interfere. + } else if (currentCount > _lastScreenCount) { // Screen count increased - auto setup + ScreenSetup::inst()->initModes(); ScreenSetup::inst()->setDefaultMode(CommandLine::testMode()); if (!keepResolution()) { ScreenSetup::inst()->revertChanges(); } - } else { // Not DBus or screen count decreased - pop up GUI + } else { // Screen count decreased - pop up GUI and don't just deconfig the screen this->show(); } } else { + // GUI currently visible -- highlight refresh button if (currentCount > _lastScreenCount) { ScreenSetup::inst()->initModes(); initControls(); } else { - _ui->btnReload->setStyleSheet(resetButtonHotStyle); + _ui->btnReload->setStyleSheet(STYLE_RELOAD_BUTTON_HOT); } } + // Reset flags (don't use return above!) _addEventDbus = false; _addEventOther = false; }); @@ -159,7 +164,7 @@ Widget::Widget(QWidget *parent) : if (this->isHidden()) { t->start(1500); } else { - _ui->btnReload->setStyleSheet(resetButtonHotStyle); + _ui->btnReload->setStyleSheet(STYLE_RELOAD_BUTTON_HOT); } }; for (auto scrn : QGuiApplication::screens()) { @@ -199,7 +204,7 @@ Widget::Widget(QWidget *parent) : connect(ScreenSetup::inst(), &ScreenSetup::outputConfigChanged, [=](ConnectionEvent type) { if (type == ConnectionEvent::Disconnected) { if (!this->isHidden()) { - _ui->btnReload->setStyleSheet(resetButtonHotStyle); + _ui->btnReload->setStyleSheet(STYLE_RELOAD_BUTTON_HOT); } } else { _addEventOther = true; @@ -223,6 +228,12 @@ void Widget::showEvent(QShowEvent *event) raise(); } +void Widget::hideEvent(QHideEvent *event) +{ + QWidget::hideEvent(event); + _lastScreenCount = ScreenSetup::inst()->getOutputCount(); +} + static void fillCombo(QComboBox *combo, const ResolutionVector &resolutions, const QSize &preselected, const QSize &preferred = QSize()) { combo->clear(); @@ -267,7 +278,7 @@ void Widget::comboBold(int index) void Widget::initControls(bool jumpToTab) { _lastScreenCount = ScreenSetup::inst()->getOutputCount(); - _ui->btnReload->setStyleSheet(resetButtonStyle); + _ui->btnReload->setStyleSheet(STYLE_RELOAD_BUTTON_NORMAL); // ScreenMode currentOpMode = ScreenSetup::inst()->getCurrentMode(); _ui->tabWidget->setTabEnabled(1, CommandLine::testMode() || ScreenSetup::inst()->getOutputCount() == 2 || currentOpMode == ScreenMode::Dual); diff --git a/src/widget.h b/src/widget.h index a91b556..2dc604c 100644 --- a/src/widget.h +++ b/src/widget.h @@ -22,6 +22,7 @@ public: protected: virtual void showEvent(QShowEvent *event) override; + virtual void hideEvent(QHideEvent *event) override; private slots: void comboBold(int index); |