mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02:00
Fix inconsistent landing page remap list (#2866)
* Added pre-processing code * Refactored code on c++ side to match * Fixed comment
This commit is contained in:
@@ -106,6 +106,32 @@ static IAsyncAction OnClickAccept(KeyboardManagerState& keyboardManagerState, Xa
|
||||
}
|
||||
ApplyRemappings();
|
||||
}
|
||||
|
||||
// Function to combine remappings if the L and R version of the modifier is mapped to the same key
|
||||
void CombineRemappings(std::unordered_map<DWORD, DWORD>& table, DWORD leftKey, DWORD rightKey, DWORD combinedKey)
|
||||
{
|
||||
if (table.find(leftKey) != table.end() && table.find(rightKey) != table.end())
|
||||
{
|
||||
// If they are mapped to the same key, delete those entries and set the common version
|
||||
if (table[leftKey] == table[rightKey])
|
||||
{
|
||||
table[combinedKey] = table[leftKey];
|
||||
table.erase(leftKey);
|
||||
table.erase(rightKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Function to pre process the remap table before loading it into the UI
|
||||
void PreProcessRemapTable(std::unordered_map<DWORD, DWORD>& table)
|
||||
{
|
||||
// Pre process the table to combine L and R versions of Ctrl/Alt/Shift/Win that are mapped to the same key
|
||||
CombineRemappings(table, VK_LCONTROL, VK_RCONTROL, VK_CONTROL);
|
||||
CombineRemappings(table, VK_LMENU, VK_RMENU, VK_MENU);
|
||||
CombineRemappings(table, VK_LSHIFT, VK_RSHIFT, VK_SHIFT);
|
||||
CombineRemappings(table, VK_LWIN, VK_RWIN, CommonSharedConstants::VK_WIN_BOTH);
|
||||
}
|
||||
|
||||
// Function to create the Edit Keyboard Window
|
||||
void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardManagerState)
|
||||
{
|
||||
@@ -265,48 +291,7 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan
|
||||
std::unique_lock<std::mutex> lock(keyboardManagerState.singleKeyReMap_mutex);
|
||||
std::unordered_map<DWORD, DWORD> singleKeyRemapCopy = keyboardManagerState.singleKeyReMap;
|
||||
lock.unlock();
|
||||
|
||||
// Pre process the table to combine L and R versions of Ctrl/Alt/Shift/Win that are mapped to the same key
|
||||
if (singleKeyRemapCopy.find(VK_LCONTROL) != singleKeyRemapCopy.end() && singleKeyRemapCopy.find(VK_RCONTROL) != singleKeyRemapCopy.end())
|
||||
{
|
||||
// If they are mapped to the same key, delete those entries and set the common version
|
||||
if (singleKeyRemapCopy[VK_LCONTROL] == singleKeyRemapCopy[VK_RCONTROL])
|
||||
{
|
||||
singleKeyRemapCopy[VK_CONTROL] = singleKeyRemapCopy[VK_LCONTROL];
|
||||
singleKeyRemapCopy.erase(VK_LCONTROL);
|
||||
singleKeyRemapCopy.erase(VK_RCONTROL);
|
||||
}
|
||||
}
|
||||
if (singleKeyRemapCopy.find(VK_LMENU) != singleKeyRemapCopy.end() && singleKeyRemapCopy.find(VK_RMENU) != singleKeyRemapCopy.end())
|
||||
{
|
||||
// If they are mapped to the same key, delete those entries and set the common version
|
||||
if (singleKeyRemapCopy[VK_LMENU] == singleKeyRemapCopy[VK_RMENU])
|
||||
{
|
||||
singleKeyRemapCopy[VK_MENU] = singleKeyRemapCopy[VK_LMENU];
|
||||
singleKeyRemapCopy.erase(VK_LMENU);
|
||||
singleKeyRemapCopy.erase(VK_RMENU);
|
||||
}
|
||||
}
|
||||
if (singleKeyRemapCopy.find(VK_LSHIFT) != singleKeyRemapCopy.end() && singleKeyRemapCopy.find(VK_RSHIFT) != singleKeyRemapCopy.end())
|
||||
{
|
||||
// If they are mapped to the same key, delete those entries and set the common version
|
||||
if (singleKeyRemapCopy[VK_LSHIFT] == singleKeyRemapCopy[VK_RSHIFT])
|
||||
{
|
||||
singleKeyRemapCopy[VK_SHIFT] = singleKeyRemapCopy[VK_LSHIFT];
|
||||
singleKeyRemapCopy.erase(VK_LSHIFT);
|
||||
singleKeyRemapCopy.erase(VK_RSHIFT);
|
||||
}
|
||||
}
|
||||
if (singleKeyRemapCopy.find(VK_LWIN) != singleKeyRemapCopy.end() && singleKeyRemapCopy.find(VK_RWIN) != singleKeyRemapCopy.end())
|
||||
{
|
||||
// If they are mapped to the same key, delete those entries and set the common version
|
||||
if (singleKeyRemapCopy[VK_LWIN] == singleKeyRemapCopy[VK_RWIN])
|
||||
{
|
||||
singleKeyRemapCopy[CommonSharedConstants::VK_WIN_BOTH] = singleKeyRemapCopy[VK_LWIN];
|
||||
singleKeyRemapCopy.erase(VK_LWIN);
|
||||
singleKeyRemapCopy.erase(VK_RWIN);
|
||||
}
|
||||
}
|
||||
PreProcessRemapTable(singleKeyRemapCopy);
|
||||
|
||||
for (const auto& it : singleKeyRemapCopy)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user