mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-18 14:41:21 +08:00
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:
parent
6f38cdec5a
commit
9d5990311f
@ -181,7 +181,7 @@ void LayoutMap::LayoutMapImpl::UpdateLayout()
|
|||||||
keyboardLayoutMap[VK_BROWSER_STOP] = L"Browser Stop";
|
keyboardLayoutMap[VK_BROWSER_STOP] = L"Browser Stop";
|
||||||
keyboardLayoutMap[VK_BROWSER_SEARCH] = L"Browser Search";
|
keyboardLayoutMap[VK_BROWSER_SEARCH] = L"Browser Search";
|
||||||
keyboardLayoutMap[VK_BROWSER_FAVORITES] = L"Browser Favorites";
|
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_MUTE] = L"Volume Mute";
|
||||||
keyboardLayoutMap[VK_VOLUME_DOWN] = L"Volume Down";
|
keyboardLayoutMap[VK_VOLUME_DOWN] = L"Volume Down";
|
||||||
keyboardLayoutMap[VK_VOLUME_UP] = L"Volume Up";
|
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_MEDIA_PLAY_PAUSE] = L"Play/Pause Media";
|
||||||
keyboardLayoutMap[VK_LAUNCH_MAIL] = L"Start Mail";
|
keyboardLayoutMap[VK_LAUNCH_MAIL] = L"Start Mail";
|
||||||
keyboardLayoutMap[VK_LAUNCH_MEDIA_SELECT] = L"Select Media";
|
keyboardLayoutMap[VK_LAUNCH_MEDIA_SELECT] = L"Select Media";
|
||||||
keyboardLayoutMap[VK_LAUNCH_APP1] = L"Start Application 1";
|
keyboardLayoutMap[VK_LAUNCH_APP1] = L"Start App 1";
|
||||||
keyboardLayoutMap[VK_LAUNCH_APP2] = L"Start Application 2";
|
keyboardLayoutMap[VK_LAUNCH_APP2] = L"Start App 2";
|
||||||
keyboardLayoutMap[VK_PACKET] = L"Packet";
|
keyboardLayoutMap[VK_PACKET] = L"Packet";
|
||||||
keyboardLayoutMap[VK_ATTN] = L"Attn";
|
keyboardLayoutMap[VK_ATTN] = L"Attn";
|
||||||
keyboardLayoutMap[VK_CRSEL] = L"CrSel";
|
keyboardLayoutMap[VK_CRSEL] = L"CrSel";
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
KeyboardManagerState::KeyboardManagerState() :
|
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(
|
configFile_mutex = CreateMutex(
|
||||||
NULL, // default security descriptor
|
NULL, // default security descriptor
|
||||||
@ -64,7 +64,8 @@ void KeyboardManagerState::ResetUIState()
|
|||||||
|
|
||||||
// Reset the shortcut UI stored variables
|
// Reset the shortcut UI stored variables
|
||||||
std::unique_lock<std::mutex> currentShortcutUI_lock(currentShortcutUI_mutex);
|
std::unique_lock<std::mutex> currentShortcutUI_lock(currentShortcutUI_mutex);
|
||||||
currentShortcutUI = nullptr;
|
currentShortcutUI1 = nullptr;
|
||||||
|
currentShortcutUI2 = nullptr;
|
||||||
currentShortcutUI_lock.unlock();
|
currentShortcutUI_lock.unlock();
|
||||||
|
|
||||||
std::unique_lock<std::mutex> detectedShortcut_lock(detectedShortcut_mutex);
|
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
|
// 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);
|
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
|
// 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()
|
void KeyboardManagerState::UpdateDetectShortcutUI()
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> currentShortcutUI_lock(currentShortcutUI_mutex);
|
std::lock_guard<std::mutex> currentShortcutUI_lock(currentShortcutUI_mutex);
|
||||||
if (currentShortcutUI == nullptr)
|
if (currentShortcutUI1 == nullptr)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -181,14 +183,36 @@ void KeyboardManagerState::UpdateDetectShortcutUI()
|
|||||||
detectedShortcut_lock.unlock();
|
detectedShortcut_lock.unlock();
|
||||||
|
|
||||||
// Since this function is invoked from the back-end thread, in order to update the UI the dispatcher must be used.
|
// 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);
|
std::vector<hstring> shortcut = detectedShortcutCopy.GetKeyVector(keyboardMap);
|
||||||
currentShortcutUI.Children().Clear();
|
currentShortcutUI1.Children().Clear();
|
||||||
for (auto& key : shortcut)
|
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 inProcessRemapKeysArray;
|
||||||
json::JsonArray globalRemapShortcutsArray;
|
json::JsonArray globalRemapShortcutsArray;
|
||||||
std::unique_lock<std::mutex> lockSingleKeyReMap(singleKeyReMap_mutex);
|
std::unique_lock<std::mutex> lockSingleKeyReMap(singleKeyReMap_mutex);
|
||||||
for (const auto &it : singleKeyReMap)
|
for (const auto& it : singleKeyReMap)
|
||||||
{
|
{
|
||||||
json::JsonObject keys;
|
json::JsonObject keys;
|
||||||
keys.SetNamedValue(KeyboardManagerConstants::OriginalKeysSettingName, json::value(winrt::to_hstring((unsigned int)it.first)));
|
keys.SetNamedValue(KeyboardManagerConstants::OriginalKeysSettingName, json::value(winrt::to_hstring((unsigned int)it.first)));
|
||||||
@ -392,7 +416,7 @@ bool KeyboardManagerState::SaveConfigToFile()
|
|||||||
lockSingleKeyReMap.unlock();
|
lockSingleKeyReMap.unlock();
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lockOsLevelShortcutReMap(osLevelShortcutReMap_mutex);
|
std::unique_lock<std::mutex> lockOsLevelShortcutReMap(osLevelShortcutReMap_mutex);
|
||||||
for (const auto &it : osLevelShortcutReMap)
|
for (const auto& it : osLevelShortcutReMap)
|
||||||
{
|
{
|
||||||
json::JsonObject keys;
|
json::JsonObject keys;
|
||||||
keys.SetNamedValue(KeyboardManagerConstants::OriginalKeysSettingName, json::value(it.first.ToHstringVK()));
|
keys.SetNamedValue(KeyboardManagerConstants::OriginalKeysSettingName, json::value(it.first.ToHstringVK()));
|
||||||
|
@ -55,8 +55,9 @@ private:
|
|||||||
StackPanel currentSingleKeyUI;
|
StackPanel currentSingleKeyUI;
|
||||||
std::mutex currentSingleKeyUI_mutex;
|
std::mutex currentSingleKeyUI_mutex;
|
||||||
|
|
||||||
// Stores the UI element which is to be updated based on the shortcut entered
|
// Stores the UI element which is to be updated based on the shortcut entered (each stackpanel represents a row of keys)
|
||||||
StackPanel currentShortcutUI;
|
StackPanel currentShortcutUI1;
|
||||||
|
StackPanel currentShortcutUI2;
|
||||||
std::mutex currentShortcutUI_mutex;
|
std::mutex currentShortcutUI_mutex;
|
||||||
|
|
||||||
// Stores the current configuration name.
|
// Stores the current configuration name.
|
||||||
@ -126,7 +127,7 @@ public:
|
|||||||
bool AddOSLevelShortcut(const Shortcut& originalSC, const Shortcut& newSC);
|
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
|
// 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
|
// 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);
|
void ConfigureDetectSingleKeyRemapUI(const StackPanel& textBlock);
|
||||||
|
@ -265,10 +265,17 @@ void ShortcutControl::createDetectShortcutWindow(winrt::Windows::Foundation::IIn
|
|||||||
text.Margin({ 0, 0, 0, 10 });
|
text.Margin({ 0, 0, 0, 10 });
|
||||||
stackPanel.Children().Append(text);
|
stackPanel.Children().Append(text);
|
||||||
|
|
||||||
// Target StackPanel to place the selected key
|
// Target StackPanel to place the selected key - first row (for 1-3 keys)
|
||||||
Windows::UI::Xaml::Controls::StackPanel keyStackPanel;
|
Windows::UI::Xaml::Controls::StackPanel keyStackPanel1;
|
||||||
keyStackPanel.Orientation(Orientation::Horizontal);
|
keyStackPanel1.Orientation(Orientation::Horizontal);
|
||||||
stackPanel.Children().Append(keyStackPanel);
|
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;
|
TextBlock holdEscInfo;
|
||||||
holdEscInfo.Text(L"Hold Esc to discard");
|
holdEscInfo.Text(L"Hold Esc to discard");
|
||||||
@ -300,7 +307,7 @@ void ShortcutControl::createDetectShortcutWindow(winrt::Windows::Foundation::IIn
|
|||||||
stackPanel.UpdateLayout();
|
stackPanel.UpdateLayout();
|
||||||
|
|
||||||
// Configure the keyboardManagerState to store the UI information.
|
// Configure the keyboardManagerState to store the UI information.
|
||||||
keyboardManagerState.ConfigureDetectShortcutUI(keyStackPanel);
|
keyboardManagerState.ConfigureDetectShortcutUI(keyStackPanel1, keyStackPanel2);
|
||||||
|
|
||||||
// Show the dialog
|
// Show the dialog
|
||||||
detectShortcutBox.ShowAsync();
|
detectShortcutBox.ShowAsync();
|
||||||
|
Loading…
Reference in New Issue
Block a user