Refactor Shortcut remaps to distinguish modifiers and action keys (#1927)

* Added unique lock mutexes for thread safety

* Fixed a bug in detect key logic

* Changed dword to word

* Added early unlock statements to fix issue with shortcut guide

* Fixed type conversion warnings

* Migrated detect shortcut window to use Shortcut class

* made changes in Apply button logic

* Revert thread safety changes

* refactored code works on the UI side

* Refactored remapping code to use new Shortcut class

* Refactored to SetKeyEvent function

* Moved function to cpp file and added more comments

* Refactored map variable and handled common Win key

* Remove debug code

* Change arguments to const references
This commit is contained in:
Arjun Balgovind
2020-04-08 09:11:58 -07:00
committed by Udit Singh
parent cf54a4919b
commit 52c12731cb
14 changed files with 1261 additions and 304 deletions

View File

@@ -133,17 +133,17 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa
for (unsigned int i = 1; i < shortcutTable.Children().Size(); i++)
{
StackPanel currentRow = shortcutTable.Children().GetAt(i).as<StackPanel>();
hstring originalShortcut = currentRow.Children().GetAt(0).as<StackPanel>().Children().GetAt(1).as<TextBlock>().Text();
hstring newShortcut = currentRow.Children().GetAt(1).as<StackPanel>().Children().GetAt(1).as<TextBlock>().Text();
if (!originalShortcut.empty() && !newShortcut.empty())
hstring originalShortcutText = currentRow.Children().GetAt(0).as<StackPanel>().Children().GetAt(1).as<TextBlock>().Text();
hstring newShortcutText = currentRow.Children().GetAt(1).as<StackPanel>().Children().GetAt(1).as<TextBlock>().Text();
if (!originalShortcutText.empty() && !newShortcutText.empty())
{
std::vector<DWORD> originalKeys = convertWStringVectorToIntegerVector<DWORD>(splitwstring(originalShortcut.c_str(), L' '));
std::vector<WORD> newKeys = convertWStringVectorToIntegerVector<WORD>(splitwstring(newShortcut.c_str(), L' '));
Shortcut originalShortcut = Shortcut::CreateShortcut(originalShortcutText);
Shortcut newShortcut = Shortcut::CreateShortcut(newShortcutText);
// Shortcut should consist of atleast two keys
if (originalKeys.size() > 1 && newKeys.size() > 1)
// Shortcut should be valid
if (originalShortcut.IsValidShortcut() && originalShortcut.IsValidShortcut())
{
bool result = keyboardManagerState.AddOSLevelShortcut(originalKeys, newKeys);
bool result = keyboardManagerState.AddOSLevelShortcut(originalShortcut, newShortcut);
if (!result)
{
isSuccess = false;
@@ -186,7 +186,7 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa
std::unique_lock<std::mutex> lock(keyboardManagerState.osLevelShortcutReMap_mutex);
for (const auto& it : keyboardManagerState.osLevelShortcutReMap)
{
ShortcutControl::AddNewShortcutControlRow(shortcutTable, it.first, it.second.first);
ShortcutControl::AddNewShortcutControlRow(shortcutTable, it.first, it.second.targetShortcut);
}
lock.unlock();