MappingConfiguration.h
1 #pragma once 2 3 #include <common/utils/json.h> 4 5 #include <keyboardmanager/common/KeyboardManagerConstants.h> 6 #include <keyboardmanager/common/Shortcut.h> 7 #include <keyboardmanager/common/RemapShortcut.h> 8 9 using SingleKeyRemapTable = std::unordered_map<DWORD, KeyShortcutTextUnion>; 10 using SingleKeyToTextRemapTable = SingleKeyRemapTable; 11 using ShortcutRemapTable = std::map<Shortcut, RemapShortcut>; 12 using AppSpecificShortcutRemapTable = std::map<std::wstring, ShortcutRemapTable>; 13 14 class MappingConfiguration 15 { 16 public: 17 ~MappingConfiguration() = default; 18 19 // Load the configuration. 20 bool LoadSettings(); 21 22 // Save the updated configuration. 23 bool SaveSettingsToFile(); 24 25 // Function to clear the OS Level shortcut remapping table 26 void ClearOSLevelShortcuts(); 27 28 // Function to clear the Keys remapping table 29 void ClearSingleKeyRemaps(); 30 31 // Function to clear the Keys to text remapping table 32 void ClearSingleKeyToTextRemaps(); 33 34 // Function to clear the App specific shortcut remapping table 35 void ClearAppSpecificShortcuts(); 36 37 // Function to add a new single key to key remapping 38 bool AddSingleKeyRemap(const DWORD& originalKey, const KeyShortcutTextUnion& newRemapKey); 39 40 // Function to add a new single key to unicode string remapping 41 bool AddSingleKeyToTextRemap(const DWORD originalKey, const std::wstring& text); 42 43 // Function to add a new OS level shortcut remapping 44 bool AddOSLevelShortcut(const Shortcut& originalSC, const KeyShortcutTextUnion& newSC); 45 46 // Function to add a new App specific level shortcut remapping 47 bool AddAppSpecificShortcut(const std::wstring& app, const Shortcut& originalSC, const KeyShortcutTextUnion& newSC); 48 49 // The map members and their mutexes are left as public since the maps are used extensively in dllmain.cpp. 50 // Maps which store the remappings for each of the features. The bool fields should be initialized to false. They are used to check the current state of the shortcut (i.e is that particular shortcut currently pressed down or not). 51 // Stores single key remappings 52 SingleKeyRemapTable singleKeyReMap; 53 54 std::unordered_map<DWORD, DWORD> scanMap; 55 56 std::unordered_map<DWORD, bool> numpadKeyPressed; 57 58 // Stores single key to text remappings 59 SingleKeyToTextRemapTable singleKeyToTextReMap; 60 61 // Stores the os level shortcut remappings 62 ShortcutRemapTable osLevelShortcutReMap; 63 std::vector<Shortcut> osLevelShortcutReMapSortedKeys; 64 65 // Stores the app-specific shortcut remappings. Maps application name to the shortcut map 66 AppSpecificShortcutRemapTable appSpecificShortcutReMap; 67 std::map<std::wstring, std::vector<Shortcut>> appSpecificShortcutReMapSortedKeys; 68 69 // Stores the current configuration name. 70 std::wstring currentConfig = KeyboardManagerConstants::DefaultConfiguration; 71 72 private: 73 bool LoadSingleKeyRemaps(const json::JsonObject& jsonData); 74 bool LoadSingleKeyToTextRemaps(const json::JsonObject& jsonData); 75 bool LoadShortcutRemaps(const json::JsonObject& jsonData, const std::wstring& objectName); 76 bool LoadAppSpecificShortcutRemaps(const json::JsonObject& remapShortcutsData); 77 };