diff --git a/lib/macro/macro-tab.cpp b/lib/macro/macro-tab.cpp index 4a8b8ce9..00d1e4ad 100644 --- a/lib/macro/macro-tab.cpp +++ b/lib/macro/macro-tab.cpp @@ -25,6 +25,8 @@ namespace advss { static QObject *addPulse = nullptr; static QTimer onChangeHighlightTimer; +static std::chrono::high_resolution_clock::time_point + lastOnChangeHighlightCheckTime{}; static void disableAddButtonHighlight() { @@ -550,10 +552,14 @@ void AdvSceneSwitcher::HighlightOnChange() const return; } - if (macro->OnChangePreventedActionsRecently()) { + if (macro->OnChangePreventedActionsSince( + lastOnChangeHighlightCheckTime)) { HighlightWidget(ui->runMacroOnChange, Qt::yellow, Qt::transparent, true); } + + lastOnChangeHighlightCheckTime = + std::chrono::high_resolution_clock::now(); } void AdvSceneSwitcher::on_macroSettings_clicked() @@ -652,6 +658,8 @@ void AdvSceneSwitcher::SetupMacroTab() ui->macroPriorityWarning->setVisible( switcher->functionNamesByPriority[0] != macro_func); + lastOnChangeHighlightCheckTime = + std::chrono::high_resolution_clock::now(); onChangeHighlightTimer.setInterval(1500); connect(&onChangeHighlightTimer, SIGNAL(timeout()), this, SLOT(HighlightOnChange())); diff --git a/lib/macro/macro-tree.cpp b/lib/macro/macro-tree.cpp index 278e85ad..ed780822 100644 --- a/lib/macro/macro-tree.cpp +++ b/lib/macro/macro-tree.cpp @@ -187,10 +187,19 @@ void MacroTreeItem::HighlightIfExecuted() return; } + bool wasHighlighted = false; if (_lastHighlightCheckTime.time_since_epoch().count() != 0 && _macro->WasExecutedSince(_lastHighlightCheckTime)) { HighlightWidget(this, Qt::green, QColor(0, 0, 0, 0), true); + wasHighlighted = true; } + + if (!wasHighlighted && + _lastHighlightCheckTime.time_since_epoch().count() != 0 && + _macro->OnChangePreventedActionsSince(_lastHighlightCheckTime)) { + HighlightWidget(this, Qt::yellow, QColor(0, 0, 0, 0), true); + } + _lastHighlightCheckTime = std::chrono::high_resolution_clock::now(); } diff --git a/lib/macro/macro.cpp b/lib/macro/macro.cpp index a1018edf..f772c1aa 100644 --- a/lib/macro/macro.cpp +++ b/lib/macro/macro.cpp @@ -242,8 +242,12 @@ bool Macro::CheckConditions(bool ignorePause) vblog(LOG_INFO, "Macro %s returned %d", _name.c_str(), _matched); _conditionSateChanged = _lastMatched != _matched; - if (!_conditionSateChanged && _performActionsOnChange) { - _onPreventedActionExecution = true; + const bool hasActionsToExecute = _matched ? (_actions.size() > 0) + : (_elseActions.size() > 0); + if (!_conditionSateChanged && _performActionsOnChange && + hasActionsToExecute) { + _lastOnChangeActionsPreventedTime = + std::chrono::high_resolution_clock::now(); } _lastMatched = _matched; @@ -302,6 +306,11 @@ bool Macro::WasExecutedSince(const TimePoint &time) const return _lastExecutionTime > time; } +bool Macro::OnChangePreventedActionsSince(const TimePoint &time) const +{ + return _lastOnChangeActionsPreventedTime > time; +} + bool Macro::ConditionsShouldBeChecked() const { if (!_useCustomConditionCheckInterval) { @@ -986,18 +995,8 @@ bool Macro::HasValidSplitterPositions() const !_elseActionSplitterPosition.empty(); } -bool Macro::OnChangePreventedActionsRecently() -{ - if (_onPreventedActionExecution) { - _onPreventedActionExecution = false; - return _matched ? _actions.size() > 0 : _elseActions.size() > 0; - } - return false; -} - void Macro::ResetUIHelpers() { - _onPreventedActionExecution = false; for (auto c : _conditions) { c->GetHighlightAndReset(); } diff --git a/lib/macro/macro.hpp b/lib/macro/macro.hpp index d3dc04bf..352d86c3 100644 --- a/lib/macro/macro.hpp +++ b/lib/macro/macro.hpp @@ -137,7 +137,7 @@ public: const QList &GetElseActionSplitterPosition() const; bool HasValidSplitterPositions() const; bool WasExecutedSince(const TimePoint &) const; - bool OnChangePreventedActionsRecently(); + bool OnChangePreventedActionsSince(const TimePoint &) const; void ResetUIHelpers(); // Hotkeys @@ -168,6 +168,7 @@ private: TimePoint _lastCheckTime{}; TimePoint _lastUnpauseTime{}; TimePoint _lastExecutionTime{}; + TimePoint _lastOnChangeActionsPreventedTime{}; std::vector _helperThreads; std::deque> _conditions; @@ -204,9 +205,6 @@ private: MacroInputVariables _inputVariables; - // UI helpers - bool _onPreventedActionExecution = false; - QList _actionConditionSplitterPosition; QList _elseActionSplitterPosition;