[Keyboard Manager] Enable App-specific shortcuts in the KBM backend (#4628)

* Enable app specific shortcut remapping

* Fixed lowercase function call

* Add test file

* Moved GetForegroundProcess to II and added tests

* Fixed runtime error while testing due to heap allocation across dll boundary

* Renamed function

* Remove unused code

* Changed process checking step to include substrings

* Changed back to exact match included match without file extension
This commit is contained in:
Arjun Balgovind
2020-07-06 16:45:53 -07:00
committed by GitHub
parent 70405045d7
commit 1533c9315f
15 changed files with 241 additions and 52 deletions

View File

@@ -110,6 +110,13 @@ void KeyboardManagerState::ClearSingleKeyRemaps()
singleKeyReMap.clear();
}
// Function to clear the App specific shortcut remapping table
void KeyboardManagerState::ClearAppSpecificShortcuts()
{
std::lock_guard<std::mutex> lock(appSpecificShortcutReMap_mutex);
appSpecificShortcutReMap.clear();
}
// Function to add a new OS level shortcut remapping
bool KeyboardManagerState::AddOSLevelShortcut(const Shortcut& originalSC, const Shortcut& newSC)
{
@@ -142,6 +149,32 @@ bool KeyboardManagerState::AddSingleKeyRemap(const DWORD& originalKey, const DWO
return true;
}
// Function to add a new App specific shortcut remapping
bool KeyboardManagerState::AddAppSpecificShortcut(const std::wstring& app, const Shortcut& originalSC, const Shortcut& newSC)
{
std::lock_guard<std::mutex> lock(appSpecificShortcutReMap_mutex);
// Check if there are any app specific shortcuts for this app
auto appIt = appSpecificShortcutReMap.find(app);
if (appIt != appSpecificShortcutReMap.end())
{
// Check if the shortcut is already remapped
auto shortcutIt = appSpecificShortcutReMap[app].find(originalSC);
if (shortcutIt != appSpecificShortcutReMap[app].end())
{
return false;
}
}
// Convert app name to lower case
std::wstring process_name;
process_name.resize(app.length());
std::transform(app.begin(), app.end(), process_name.begin(), towlower);
appSpecificShortcutReMap[process_name][originalSC] = RemapShortcut(newSC);
return true;
}
// Function to set the textblock of the detect shortcut UI so that it can be accessed by the hook
void KeyboardManagerState::ConfigureDetectShortcutUI(const StackPanel& textBlock1, const StackPanel& textBlock2)
{