Fix hotkey condition evaluating to true if macro was paused

The condition check now also takes the time during which the macro was
paused into consideration
This commit is contained in:
WarmUpTill 2024-01-24 17:40:00 +01:00 committed by WarmUpTill
parent 0c97b3be4a
commit aeb0e7f8ad
2 changed files with 11 additions and 3 deletions

View File

@ -48,7 +48,8 @@ EXPORT int64_t MillisecondsSinceMacroConditionCheck(Macro *);
EXPORT bool MacroIsStopped(Macro *);
EXPORT bool MacroIsPaused(Macro *);
EXPORT bool
MacroWasPausedSince(Macro *, const std::chrono::high_resolution_clock::time_point &);
MacroWasPausedSince(Macro *,
const std::chrono::high_resolution_clock::time_point &);
EXPORT void AddMacroHelperThread(Macro *, std::thread &&);

View File

@ -1,5 +1,6 @@
#include "macro-condition-hotkey.hpp"
#include "layout-helpers.hpp"
#include "macro-helpers.hpp"
namespace advss {
@ -22,8 +23,14 @@ MacroConditionHotkey::MacroConditionHotkey(Macro *m) : MacroCondition(m)
bool MacroConditionHotkey::CheckCondition()
{
bool ret = _hotkey->GetPressed() ||
_hotkey->GetLastPressed() > _lastCheck;
const bool hotkeyIsCurrentlyPressed = _hotkey->GetPressed();
const bool hotkeyWasPressedSinceLastCheck = _hotkey->GetLastPressed() >
_lastCheck;
const bool macroWasPausedSinceLastCheck =
MacroWasPausedSince(GetMacro(), _lastCheck);
bool ret = hotkeyIsCurrentlyPressed ||
(hotkeyWasPressedSinceLastCheck &&
!macroWasPausedSinceLastCheck);
_lastCheck = std::chrono::high_resolution_clock::now();
return ret;
}