State.cpp
 1  #include "pch.h"
 2  #include "State.h"
 3  #include <optional>
 4  
 5  // Function to get the iterator of a single key remap given the source key. Returns nullopt if it isn't remapped
 6  std::optional<SingleKeyRemapTable::iterator> State::GetSingleKeyRemap(const DWORD& originalKey)
 7  {
 8      auto it = singleKeyReMap.find(originalKey);
 9      if (it != singleKeyReMap.end())
10      {
11          return it;
12      }
13  
14      return std::nullopt;
15  }
16  
17  std::optional<std::wstring> State::GetSingleKeyToTextRemapEvent(const DWORD originalKey) const
18  {
19      if (auto it = singleKeyToTextReMap.find(originalKey); it != end(singleKeyToTextReMap))
20      {
21          return std::get<std::wstring>(it->second);
22      }
23      else
24      {
25          return std::nullopt;
26      }
27  }
28  
29  bool State::CheckShortcutRemapInvoked(const std::optional<std::wstring>& appName)
30  {
31      // Assumes appName exists in the app-specific remap table
32      ShortcutRemapTable& currentRemapTable = appName ? appSpecificShortcutReMap[*appName] : osLevelShortcutReMap;
33      for (auto& it : currentRemapTable)
34      {
35          if (it.second.isShortcutInvoked)
36          {
37              return true;
38          }
39      }
40  
41      return false;
42  }
43  
44  // Function to get the source and target of a shortcut remap given the source shortcut. Returns nullopt if it isn't remapped
45  ShortcutRemapTable& State::GetShortcutRemapTable(const std::optional<std::wstring>& appName)
46  {
47      if (appName)
48      {
49          auto itTable = appSpecificShortcutReMap.find(*appName);
50          if (itTable != appSpecificShortcutReMap.end())
51          {
52              return itTable->second;
53          }
54      }
55  
56      return osLevelShortcutReMap;
57  }
58  
59  std::vector<Shortcut>& State::GetSortedShortcutRemapVector(const std::optional<std::wstring>& appName)
60  {
61      // Assumes appName exists in the app-specific remap table
62      return appName ? appSpecificShortcutReMapSortedKeys[*appName] : osLevelShortcutReMapSortedKeys;
63  }
64  
65  // Sets the activated target application in app-specific shortcut
66  void State::SetActivatedApp(const std::wstring& appName)
67  {
68      activatedAppSpecificShortcutTarget = appName;
69  }
70  
71  // Gets the activated target application in app-specific shortcut
72  std::wstring State::GetActivatedApp()
73  {
74      return activatedAppSpecificShortcutTarget;
75  }