-
Notifications
You must be signed in to change notification settings - Fork 6.9k
/
Copy pathState.cpp
102 lines (88 loc) · 2.95 KB
/
State.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "pch.h"
#include "State.h"
#include <optional>
// Function to get the iterator of a single key remap given the source key. Returns nullopt if it isn't remapped
std::optional<SingleKeyRemapTable::iterator> State::GetSingleKeyRemap(const DWORD& originalKey)
{
auto it = singleKeyReMap.find(originalKey);
if (it != singleKeyReMap.end())
{
return it;
}
return std::nullopt;
}
std::optional<std::wstring> State::GetSingleKeyToTextRemapEvent(const DWORD originalKey) const
{
if (auto it = singleKeyToTextReMap.find(originalKey); it != end(singleKeyToTextReMap))
{
return std::get<std::wstring>(it->second);
}
else
{
return std::nullopt;
}
}
bool State::CheckShortcutRemapInvoked(const std::optional<std::wstring>& appName)
{
// Assumes appName exists in the app-specific remap table
ShortcutRemapTable& currentRemapTable = appName ? appSpecificShortcutReMap[*appName] : osLevelShortcutReMap;
for (auto& it : currentRemapTable)
{
if (it.second.isShortcutInvoked)
{
return true;
}
}
return false;
}
// Function to get the source and target of a shortcut remap given the source shortcut. Returns nullopt if it isn't remapped
ShortcutRemapTable& State::GetShortcutRemapTable(const std::optional<std::wstring>& appName)
{
if (appName)
{
auto itTable = appSpecificShortcutReMap.find(*appName);
if (itTable != appSpecificShortcutReMap.end())
{
return itTable->second;
}
}
return osLevelShortcutReMap;
}
std::vector<Shortcut>& State::GetSortedShortcutRemapVector(const std::optional<std::wstring>& appName)
{
// Assumes appName exists in the app-specific remap table
return appName ? appSpecificShortcutReMapSortedKeys[*appName] : osLevelShortcutReMapSortedKeys;
}
// Sets the activated target application in app-specific shortcut
void State::SetActivatedApp(const std::wstring& appName)
{
activatedAppSpecificShortcutTarget = appName;
}
// Gets the activated target application in app-specific shortcut
std::wstring State::GetActivatedApp()
{
return activatedAppSpecificShortcutTarget;
}
// Sets the previous modifier key to check in another shortcut
void State::SetPreviousModifierKey(const DWORD prevKey)
{
if (!FindPreviousModifierKey(prevKey))
{
previousModifierKey.emplace_back(prevKey);
}
}
// Gets the previous modifier key
std::vector<DWORD> State::GetPreviousModifierKey()
{
return previousModifierKey;
}
// Check if a key exists in the previousModifierKey vector
bool State::FindPreviousModifierKey(const DWORD prevKey)
{
return std::find(previousModifierKey.begin(), previousModifierKey.end(), prevKey) != previousModifierKey.end();
}
// Resets the previous modifier key
void State::ResetPreviousModifierKey(const DWORD prevKey)
{
previousModifierKey.erase(std::remove(previousModifierKey.begin(), previousModifierKey.end(), prevKey), previousModifierKey.end());
}