Fixed overflow in Type Shortcut (#2930)

* Fixed overflow in Type Shortcut

* hide the stackpanel if it is not required

* changed loop
This commit is contained in:
Arjun Balgovind 2020-05-14 09:23:51 -07:00 committed by GitHub
parent 6f38cdec5a
commit 9d5990311f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 23 deletions

View File

@ -181,7 +181,7 @@ void LayoutMap::LayoutMapImpl::UpdateLayout()
keyboardLayoutMap[VK_BROWSER_STOP] = L"Browser Stop";
keyboardLayoutMap[VK_BROWSER_SEARCH] = L"Browser Search";
keyboardLayoutMap[VK_BROWSER_FAVORITES] = L"Browser Favorites";
keyboardLayoutMap[VK_BROWSER_HOME] = L"Browser Start & Home";
keyboardLayoutMap[VK_BROWSER_HOME] = L"Browser Home";
keyboardLayoutMap[VK_VOLUME_MUTE] = L"Volume Mute";
keyboardLayoutMap[VK_VOLUME_DOWN] = L"Volume Down";
keyboardLayoutMap[VK_VOLUME_UP] = L"Volume Up";
@ -191,8 +191,8 @@ void LayoutMap::LayoutMapImpl::UpdateLayout()
keyboardLayoutMap[VK_MEDIA_PLAY_PAUSE] = L"Play/Pause Media";
keyboardLayoutMap[VK_LAUNCH_MAIL] = L"Start Mail";
keyboardLayoutMap[VK_LAUNCH_MEDIA_SELECT] = L"Select Media";
keyboardLayoutMap[VK_LAUNCH_APP1] = L"Start Application 1";
keyboardLayoutMap[VK_LAUNCH_APP2] = L"Start Application 2";
keyboardLayoutMap[VK_LAUNCH_APP1] = L"Start App 1";
keyboardLayoutMap[VK_LAUNCH_APP2] = L"Start App 2";
keyboardLayoutMap[VK_PACKET] = L"Packet";
keyboardLayoutMap[VK_ATTN] = L"Attn";
keyboardLayoutMap[VK_CRSEL] = L"CrSel";

View File

@ -3,7 +3,7 @@
// Constructor
KeyboardManagerState::KeyboardManagerState() :
uiState(KeyboardManagerUIState::Deactivated), currentUIWindow(nullptr), currentShortcutUI(nullptr), currentSingleKeyUI(nullptr), detectedRemapKey(NULL)
uiState(KeyboardManagerUIState::Deactivated), currentUIWindow(nullptr), currentShortcutUI1(nullptr), currentShortcutUI2(nullptr), currentSingleKeyUI(nullptr), detectedRemapKey(NULL)
{
configFile_mutex = CreateMutex(
NULL, // default security descriptor
@ -64,7 +64,8 @@ void KeyboardManagerState::ResetUIState()
// Reset the shortcut UI stored variables
std::unique_lock<std::mutex> currentShortcutUI_lock(currentShortcutUI_mutex);
currentShortcutUI = nullptr;
currentShortcutUI1 = nullptr;
currentShortcutUI2 = nullptr;
currentShortcutUI_lock.unlock();
std::unique_lock<std::mutex> detectedShortcut_lock(detectedShortcut_mutex);
@ -132,10 +133,11 @@ bool KeyboardManagerState::AddSingleKeyRemap(const DWORD& originalKey, const DWO
}
// Function to set the textblock of the detect shortcut UI so that it can be accessed by the hook
void KeyboardManagerState::ConfigureDetectShortcutUI(const StackPanel& textBlock)
void KeyboardManagerState::ConfigureDetectShortcutUI(const StackPanel& textBlock1, const StackPanel& textBlock2)
{
std::lock_guard<std::mutex> lock(currentShortcutUI_mutex);
currentShortcutUI = textBlock;
currentShortcutUI1 = textBlock1;
currentShortcutUI2 = textBlock2;
}
// Function to set the textblock of the detect remap key UI so that it can be accessed by the hook
@ -167,7 +169,7 @@ void KeyboardManagerState::AddKeyToLayout(const StackPanel& panel, const hstring
void KeyboardManagerState::UpdateDetectShortcutUI()
{
std::lock_guard<std::mutex> currentShortcutUI_lock(currentShortcutUI_mutex);
if (currentShortcutUI == nullptr)
if (currentShortcutUI1 == nullptr)
{
return;
}
@ -181,14 +183,36 @@ void KeyboardManagerState::UpdateDetectShortcutUI()
detectedShortcut_lock.unlock();
// Since this function is invoked from the back-end thread, in order to update the UI the dispatcher must be used.
currentShortcutUI.Dispatcher().RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, [this, detectedShortcutCopy]() {
currentShortcutUI1.Dispatcher().RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, [this, detectedShortcutCopy]() {
std::vector<hstring> shortcut = detectedShortcutCopy.GetKeyVector(keyboardMap);
currentShortcutUI.Children().Clear();
for (auto& key : shortcut)
currentShortcutUI1.Children().Clear();
currentShortcutUI2.Children().Clear();
// The second row should be hidden if there are 3 keys or lesser to avoid an extra margin
if (shortcut.size() > 3)
{
AddKeyToLayout(currentShortcutUI, key);
currentShortcutUI2.Visibility(Visibility::Visible);
}
currentShortcutUI.UpdateLayout();
else
{
currentShortcutUI2.Visibility(Visibility::Collapsed);
}
int i = 0;
for (int i = 0; i < shortcut.size(); i++)
{
if (i < 3)
{
AddKeyToLayout(currentShortcutUI1, shortcut[i]);
}
else
{
AddKeyToLayout(currentShortcutUI2, shortcut[i]);
}
i++;
}
currentShortcutUI1.UpdateLayout();
currentShortcutUI2.UpdateLayout();
});
}
@ -381,7 +405,7 @@ bool KeyboardManagerState::SaveConfigToFile()
json::JsonArray inProcessRemapKeysArray;
json::JsonArray globalRemapShortcutsArray;
std::unique_lock<std::mutex> lockSingleKeyReMap(singleKeyReMap_mutex);
for (const auto &it : singleKeyReMap)
for (const auto& it : singleKeyReMap)
{
json::JsonObject keys;
keys.SetNamedValue(KeyboardManagerConstants::OriginalKeysSettingName, json::value(winrt::to_hstring((unsigned int)it.first)));
@ -392,7 +416,7 @@ bool KeyboardManagerState::SaveConfigToFile()
lockSingleKeyReMap.unlock();
std::unique_lock<std::mutex> lockOsLevelShortcutReMap(osLevelShortcutReMap_mutex);
for (const auto &it : osLevelShortcutReMap)
for (const auto& it : osLevelShortcutReMap)
{
json::JsonObject keys;
keys.SetNamedValue(KeyboardManagerConstants::OriginalKeysSettingName, json::value(it.first.ToHstringVK()));

View File

@ -55,8 +55,9 @@ private:
StackPanel currentSingleKeyUI;
std::mutex currentSingleKeyUI_mutex;
// Stores the UI element which is to be updated based on the shortcut entered
StackPanel currentShortcutUI;
// Stores the UI element which is to be updated based on the shortcut entered (each stackpanel represents a row of keys)
StackPanel currentShortcutUI1;
StackPanel currentShortcutUI2;
std::mutex currentShortcutUI_mutex;
// Stores the current configuration name.
@ -126,7 +127,7 @@ public:
bool AddOSLevelShortcut(const Shortcut& originalSC, const Shortcut& newSC);
// Function to set the textblock of the detect shortcut UI so that it can be accessed by the hook
void ConfigureDetectShortcutUI(const StackPanel& textBlock);
void ConfigureDetectShortcutUI(const StackPanel& textBlock1, const StackPanel& textBlock2);
// Function to set the textblock of the detect remap key UI so that it can be accessed by the hook
void ConfigureDetectSingleKeyRemapUI(const StackPanel& textBlock);

View File

@ -265,10 +265,17 @@ void ShortcutControl::createDetectShortcutWindow(winrt::Windows::Foundation::IIn
text.Margin({ 0, 0, 0, 10 });
stackPanel.Children().Append(text);
// Target StackPanel to place the selected key
Windows::UI::Xaml::Controls::StackPanel keyStackPanel;
keyStackPanel.Orientation(Orientation::Horizontal);
stackPanel.Children().Append(keyStackPanel);
// Target StackPanel to place the selected key - first row (for 1-3 keys)
Windows::UI::Xaml::Controls::StackPanel keyStackPanel1;
keyStackPanel1.Orientation(Orientation::Horizontal);
stackPanel.Children().Append(keyStackPanel1);
// Target StackPanel to place the selected key - second row (for 4-5 keys)
Windows::UI::Xaml::Controls::StackPanel keyStackPanel2;
keyStackPanel2.Orientation(Orientation::Horizontal);
keyStackPanel2.Margin({ 0, 20, 0, 0 });
keyStackPanel2.Visibility(Visibility::Collapsed);
stackPanel.Children().Append(keyStackPanel2);
TextBlock holdEscInfo;
holdEscInfo.Text(L"Hold Esc to discard");
@ -300,7 +307,7 @@ void ShortcutControl::createDetectShortcutWindow(winrt::Windows::Foundation::IIn
stackPanel.UpdateLayout();
// Configure the keyboardManagerState to store the UI information.
keyboardManagerState.ConfigureDetectShortcutUI(keyStackPanel);
keyboardManagerState.ConfigureDetectShortcutUI(keyStackPanel1, keyStackPanel2);
// Show the dialog
detectShortcutBox.ShowAsync();