mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-01 01:49:06 +08:00
[Keyboard Manager] Cleanup header file references to improve incremental build time (#4880)
* Remove WinUI include in KeyboardManagerState.h * Changed include steps * Clean up headers in KeyboardManagerUI except XamlBridge.h * Cleaned up headers in KeyboardManager common and test * Cleaned up headers in KeyboardManager project * Removed headers from XamlBridge * Removed some headers from kbm common pch * Added MP flag to reduce build time * Added missing include
This commit is contained in:
parent
7db5d6a307
commit
6a9badd31b
@ -1,7 +1,17 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <winrt/Windows.System.h>
|
||||
#include <winrt/Windows.Foundation.h>
|
||||
namespace winrt
|
||||
{
|
||||
struct hstring;
|
||||
namespace Windows::Foundation
|
||||
{
|
||||
struct IInspectable;
|
||||
namespace Collections
|
||||
{
|
||||
template<typename T>
|
||||
struct IVector;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace KeyboardManagerHelper
|
||||
{
|
||||
|
@ -1,6 +1,4 @@
|
||||
#pragma once
|
||||
#include "windows.h"
|
||||
#include <string>
|
||||
|
||||
// Interface used to wrap keyboard input library methods
|
||||
class InputInterface
|
||||
|
@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
#include <interface/lowlevel_keyboard_event_data.h>
|
||||
#include <functional>
|
||||
#include <thread>
|
||||
#include <queue>
|
||||
#include <mutex>
|
||||
#include <interface/lowlevel_keyboard_event_data.h>
|
||||
|
||||
// Available states for the KeyDelay state machine.
|
||||
enum class KeyDelayState
|
||||
|
@ -99,6 +99,8 @@
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">/MP %(AdditionalOptions)</AdditionalOptions>
|
||||
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">/MP %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Lib>
|
||||
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">shlwapi.lib;</AdditionalDependencies>
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "pch.h"
|
||||
#include "KeyboardManagerState.h"
|
||||
#include <../common/settings_helpers.h>
|
||||
#include "KeyDelay.h"
|
||||
|
||||
// Constructor
|
||||
KeyboardManagerState::KeyboardManagerState() :
|
||||
@ -179,15 +181,15 @@ bool KeyboardManagerState::AddAppSpecificShortcut(const std::wstring& app, const
|
||||
void KeyboardManagerState::ConfigureDetectShortcutUI(const StackPanel& textBlock1, const StackPanel& textBlock2)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(currentShortcutUI_mutex);
|
||||
currentShortcutUI1 = textBlock1;
|
||||
currentShortcutUI2 = textBlock2;
|
||||
currentShortcutUI1 = textBlock1.as<winrt::Windows::Foundation::IInspectable>();
|
||||
currentShortcutUI2 = textBlock2.as<winrt::Windows::Foundation::IInspectable>();
|
||||
}
|
||||
|
||||
// Function to set the textblock of the detect remap key UI so that it can be accessed by the hook
|
||||
void KeyboardManagerState::ConfigureDetectSingleKeyRemapUI(const StackPanel& textBlock)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(currentSingleKeyUI_mutex);
|
||||
currentSingleKeyUI = textBlock;
|
||||
currentSingleKeyUI = textBlock.as<winrt::Windows::Foundation::IInspectable>();
|
||||
}
|
||||
|
||||
void KeyboardManagerState::AddKeyToLayout(const StackPanel& panel, const hstring& key)
|
||||
@ -226,34 +228,34 @@ 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.
|
||||
currentShortcutUI1.Dispatcher().RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, [this, detectedShortcutCopy]() {
|
||||
currentShortcutUI1.as<StackPanel>().Dispatcher().RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, [this, detectedShortcutCopy]() {
|
||||
std::vector<hstring> shortcut = detectedShortcutCopy.GetKeyVector(keyboardMap);
|
||||
currentShortcutUI1.Children().Clear();
|
||||
currentShortcutUI2.Children().Clear();
|
||||
currentShortcutUI1.as<StackPanel>().Children().Clear();
|
||||
currentShortcutUI2.as<StackPanel>().Children().Clear();
|
||||
|
||||
// The second row should be hidden if there are 3 keys or lesser to avoid an extra margin
|
||||
if (shortcut.size() > 3)
|
||||
{
|
||||
currentShortcutUI2.Visibility(Visibility::Visible);
|
||||
currentShortcutUI2.as<StackPanel>().Visibility(Visibility::Visible);
|
||||
}
|
||||
else
|
||||
{
|
||||
currentShortcutUI2.Visibility(Visibility::Collapsed);
|
||||
currentShortcutUI2.as<StackPanel>().Visibility(Visibility::Collapsed);
|
||||
}
|
||||
|
||||
for (int i = 0; i < shortcut.size(); i++)
|
||||
{
|
||||
if (i < 3)
|
||||
{
|
||||
AddKeyToLayout(currentShortcutUI1, shortcut[i]);
|
||||
AddKeyToLayout(currentShortcutUI1.as<StackPanel>(), shortcut[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddKeyToLayout(currentShortcutUI2, shortcut[i]);
|
||||
AddKeyToLayout(currentShortcutUI2.as<StackPanel>(), shortcut[i]);
|
||||
}
|
||||
}
|
||||
currentShortcutUI1.UpdateLayout();
|
||||
currentShortcutUI2.UpdateLayout();
|
||||
currentShortcutUI1.as<StackPanel>().UpdateLayout();
|
||||
currentShortcutUI2.as<StackPanel>().UpdateLayout();
|
||||
});
|
||||
}
|
||||
|
||||
@ -265,13 +267,12 @@ void KeyboardManagerState::UpdateDetectSingleKeyRemapUI()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Since this function is invoked from the back-end thread, in order to update the UI the dispatcher must be used.
|
||||
currentSingleKeyUI.Dispatcher().RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, [this]() {
|
||||
currentSingleKeyUI.Children().Clear();
|
||||
currentSingleKeyUI.as<StackPanel>().Dispatcher().RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, [this]() {
|
||||
currentSingleKeyUI.as<StackPanel>().Children().Clear();
|
||||
hstring key = winrt::to_hstring(keyboardMap.GetKeyName(detectedRemapKey).c_str());
|
||||
AddKeyToLayout(currentSingleKeyUI, key);
|
||||
currentSingleKeyUI.UpdateLayout();
|
||||
AddKeyToLayout(currentSingleKeyUI.as<StackPanel>(), key);
|
||||
currentSingleKeyUI.as<StackPanel>().UpdateLayout();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1,16 +1,19 @@
|
||||
#pragma once
|
||||
#include "Helpers.h"
|
||||
#include "../common/keyboard_layout.h"
|
||||
#include "Shortcut.h"
|
||||
#include "RemapShortcut.h"
|
||||
#include "KeyDelay.h"
|
||||
#include "KeyboardManagerConstants.h"
|
||||
#include <interface/lowlevel_keyboard_event_data.h>
|
||||
#include <mutex>
|
||||
#include <winrt/Windows.UI.Xaml.Controls.h>
|
||||
#include <../common/settings_helpers.h>
|
||||
#include "KeyboardManagerConstants.h"
|
||||
#include "../common/keyboard_layout.h"
|
||||
#include <functional>
|
||||
#include <interface/lowlevel_keyboard_event_data.h>
|
||||
|
||||
using namespace winrt::Windows::UI::Xaml::Controls;
|
||||
class KeyDelay;
|
||||
|
||||
namespace winrt::Windows::UI::Xaml::Controls
|
||||
{
|
||||
struct StackPanel;
|
||||
}
|
||||
|
||||
// Enum type to store different states of the UI
|
||||
enum class KeyboardManagerUIState
|
||||
@ -52,12 +55,12 @@ private:
|
||||
std::mutex detectedRemapKey_mutex;
|
||||
|
||||
// Stores the UI element which is to be updated based on the remap key entered.
|
||||
StackPanel currentSingleKeyUI;
|
||||
winrt::Windows::Foundation::IInspectable currentSingleKeyUI;
|
||||
std::mutex currentSingleKeyUI_mutex;
|
||||
|
||||
// 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;
|
||||
winrt::Windows::Foundation::IInspectable currentShortcutUI1;
|
||||
winrt::Windows::Foundation::IInspectable currentShortcutUI2;
|
||||
std::mutex currentShortcutUI_mutex;
|
||||
|
||||
// Stores the current configuration name.
|
||||
@ -75,7 +78,7 @@ private:
|
||||
std::wstring activatedAppSpecificShortcutTarget;
|
||||
|
||||
// Display a key by appending a border Control as a child of the panel.
|
||||
void AddKeyToLayout(const StackPanel& panel, const winrt::hstring& key);
|
||||
void AddKeyToLayout(const winrt::Windows::UI::Xaml::Controls::StackPanel& panel, const winrt::hstring& key);
|
||||
|
||||
public:
|
||||
// The map members and their mutexes are left as public since the maps are used extensively in dllmain.cpp.
|
||||
@ -136,10 +139,10 @@ public:
|
||||
bool AddAppSpecificShortcut(const std::wstring& app, 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& textBlock1, const StackPanel& textBlock2);
|
||||
void ConfigureDetectShortcutUI(const winrt::Windows::UI::Xaml::Controls::StackPanel& textBlock1, const winrt::Windows::UI::Xaml::Controls::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);
|
||||
void ConfigureDetectSingleKeyRemapUI(const winrt::Windows::UI::Xaml::Controls::StackPanel& textBlock);
|
||||
|
||||
// Function to update the detect shortcut UI based on the entered keys
|
||||
void UpdateDetectShortcutUI();
|
||||
|
@ -1,5 +1,22 @@
|
||||
#include "pch.h"
|
||||
#include "Shortcut.h"
|
||||
#include "../common/keyboard_layout.h"
|
||||
#include "../common/shared_constants.h"
|
||||
#include <interface/lowlevel_keyboard_event_data.h>
|
||||
#include "Helpers.h"
|
||||
#include "InputInterface.h"
|
||||
|
||||
// Constructor to initialize Shortcut from it's virtual key code string representation.
|
||||
Shortcut::Shortcut(const std::wstring& shortcutVK) :
|
||||
winKey(ModifierKey::Disabled), ctrlKey(ModifierKey::Disabled), altKey(ModifierKey::Disabled), shiftKey(ModifierKey::Disabled), actionKey(NULL)
|
||||
{
|
||||
auto keys = KeyboardManagerHelper::splitwstring(shortcutVK, ';');
|
||||
for (auto it : keys)
|
||||
{
|
||||
auto vkKeyCode = std::stoul(it);
|
||||
SetKey(vkKeyCode);
|
||||
}
|
||||
}
|
||||
|
||||
// Function to return the number of keys in the shortcut
|
||||
int Shortcut::Size() const
|
||||
|
@ -1,9 +1,11 @@
|
||||
#pragma once
|
||||
#include "Helpers.h"
|
||||
#include "../common/keyboard_layout.h"
|
||||
#include "../common/shared_constants.h"
|
||||
#include <interface/lowlevel_keyboard_event_data.h>
|
||||
#include "InputInterface.h"
|
||||
|
||||
class InputInterface;
|
||||
class LayoutMap;
|
||||
namespace KeyboardManagerHelper
|
||||
{
|
||||
enum class ErrorType;
|
||||
}
|
||||
|
||||
// Enum type to store different states of the win key
|
||||
enum class ModifierKey
|
||||
@ -31,16 +33,7 @@ public:
|
||||
}
|
||||
|
||||
// Constructor to initialize Shortcut from it's virtual key code string representation.
|
||||
Shortcut(const std::wstring& shortcutVK) :
|
||||
winKey(ModifierKey::Disabled), ctrlKey(ModifierKey::Disabled), altKey(ModifierKey::Disabled), shiftKey(ModifierKey::Disabled), actionKey(NULL)
|
||||
{
|
||||
auto keys = KeyboardManagerHelper::splitwstring(shortcutVK, ';');
|
||||
for (auto it : keys)
|
||||
{
|
||||
auto vkKeyCode = std::stoul(it);
|
||||
SetKey(vkKeyCode);
|
||||
}
|
||||
}
|
||||
Shortcut(const std::wstring& shortcutVK);
|
||||
|
||||
// == operator
|
||||
inline bool operator==(const Shortcut& sc) const
|
||||
|
@ -5,22 +5,14 @@
|
||||
#include <winrt/Windows.Foundation.h>
|
||||
#include <winrt/Windows.Graphics.h>
|
||||
#include <winrt/Windows.system.h>
|
||||
#include <winrt/windows.ui.xaml.hosting.h>
|
||||
#include <windows.ui.xaml.hosting.desktopwindowxamlsource.h>
|
||||
#include <winrt/windows.ui.xaml.controls.h>
|
||||
#include <winrt/Windows.ui.xaml.media.h>
|
||||
#include <winrt/Windows.Foundation.Collections.h>
|
||||
#include "winrt/Windows.Foundation.Numerics.h"
|
||||
#include "winrt/Windows.UI.Xaml.Controls.Primitives.h"
|
||||
#include "winrt/Windows.UI.Text.h"
|
||||
#include <winrt/windows.ui.xaml.controls.h>
|
||||
#include "winrt/Windows.UI.Core.h"
|
||||
#include <stdlib.h>
|
||||
#include <ProjectTelemetry.h>
|
||||
|
||||
using namespace winrt;
|
||||
using namespace Windows::UI;
|
||||
using namespace Windows::UI::Composition;
|
||||
using namespace Windows::UI::Xaml::Hosting;
|
||||
using namespace Windows::Foundation::Numerics;
|
||||
using namespace Windows::UI::Xaml;
|
||||
using namespace Windows::UI::Xaml::Controls;
|
@ -1,5 +1,8 @@
|
||||
#include "pch.h"
|
||||
#include "KeyboardEventHandlers.h"
|
||||
#include "../common/shared_constants.h"
|
||||
#include <keyboardmanager/common/KeyboardManagerState.h>
|
||||
#include <keyboardmanager/common/InputInterface.h>
|
||||
|
||||
namespace KeyboardEventHandlers
|
||||
{
|
||||
|
@ -1,7 +1,13 @@
|
||||
#pragma once
|
||||
#include <keyboardmanager/common/KeyboardManagerState.h>
|
||||
#include <keyboardmanager/common/KeyboardManagerConstants.h>
|
||||
#include <keyboardmanager/common/InputInterface.h>
|
||||
#include <interface/lowlevel_keyboard_event_data.h>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include "keyboardmanager/common/KeyboardManagerConstants.h"
|
||||
|
||||
class InputInterface;
|
||||
class KeyboardManagerState;
|
||||
class Shortcut;
|
||||
class RemapShortcut;
|
||||
|
||||
namespace KeyboardEventHandlers
|
||||
{
|
||||
|
@ -108,6 +108,8 @@
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">/MP %(AdditionalOptions)</AdditionalOptions>
|
||||
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">/MP %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
|
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <common/common.h>
|
||||
#include <ProjectTelemetry.h>
|
||||
#include <shlwapi.h>
|
||||
#include <stdexcept>
|
||||
|
@ -99,6 +99,8 @@
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">/MP %(AdditionalOptions)</AdditionalOptions>
|
||||
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">/MP %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <keyboardmanager/common/KeyboardManagerState.h>
|
||||
#include <keyboardmanager/dll/KeyboardEventHandlers.h>
|
||||
#include "TestHelpers.h"
|
||||
#include "../common/shared_constants.h"
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <keyboardmanager/common/KeyboardManagerState.h>
|
||||
#include <keyboardmanager/dll/KeyboardEventHandlers.h>
|
||||
#include "TestHelpers.h"
|
||||
#include "../common/shared_constants.h"
|
||||
|
||||
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "pch.h"
|
||||
#include "TestHelpers.h"
|
||||
#include "MockedInput.h"
|
||||
#include "keyboardmanager/common/KeyboardManagerState.h"
|
||||
|
||||
namespace TestHelpers
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include "MockedInput.h"
|
||||
#include <keyboardmanager/common/KeyboardManagerState.h>
|
||||
class MockedInput;
|
||||
class KeyboardManagerState;
|
||||
|
||||
namespace TestHelpers
|
||||
{
|
||||
|
@ -1,2 +1,8 @@
|
||||
#pragma once
|
||||
#pragma comment(lib, "shlwapi.lib")
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
#include <ProjectTelemetry.h>
|
||||
#include <shlwapi.h>
|
||||
#include <stdexcept>
|
||||
#include <unordered_set>
|
||||
|
@ -1,6 +1,8 @@
|
||||
#include "pch.h"
|
||||
#include "Dialog.h"
|
||||
|
||||
using namespace winrt::Windows::Foundation;
|
||||
|
||||
IAsyncOperation<bool> Dialog::PartialRemappingConfirmationDialog(XamlRoot root, std::wstring dialogTitle)
|
||||
{
|
||||
ContentDialog confirmationDialog;
|
||||
|
@ -3,9 +3,19 @@
|
||||
#include <functional>
|
||||
#include <keyboardmanager/common/Helpers.h>
|
||||
#include <set>
|
||||
#include <winrt/Windows.UI.Xaml.h>
|
||||
|
||||
using namespace winrt::Windows::Foundation;
|
||||
namespace winrt::Windows::UI::Xaml
|
||||
{
|
||||
namespace Foundation
|
||||
{
|
||||
template<typename T>
|
||||
struct IAsyncOperation;
|
||||
}
|
||||
namespace UI::Xaml
|
||||
{
|
||||
struct XamlRoot;
|
||||
}
|
||||
}
|
||||
|
||||
namespace Dialog
|
||||
{
|
||||
@ -37,5 +47,5 @@ namespace Dialog
|
||||
return isSuccess;
|
||||
}
|
||||
|
||||
IAsyncOperation<bool> PartialRemappingConfirmationDialog(winrt::Windows::UI::Xaml::XamlRoot root, std::wstring dialogTitle);
|
||||
winrt::Windows::Foundation::IAsyncOperation<bool> PartialRemappingConfirmationDialog(winrt::Windows::UI::Xaml::XamlRoot root, std::wstring dialogTitle);
|
||||
};
|
||||
|
@ -11,6 +11,8 @@
|
||||
#include "Styles.h"
|
||||
#include "Dialog.h"
|
||||
#include <keyboardmanager/dll/resource.h>
|
||||
#include "../common/shared_constants.h"
|
||||
#include "keyboardmanager/common/KeyboardManagerState.h"
|
||||
|
||||
using namespace winrt::Windows::Foundation;
|
||||
|
||||
@ -397,7 +399,7 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan
|
||||
// Add remap key button
|
||||
Windows::UI::Xaml::Controls::Button addRemapKey;
|
||||
FontIcon plusSymbol;
|
||||
plusSymbol.FontFamily(Xaml::Media::FontFamily(L"Segoe MDL2 Assets"));
|
||||
plusSymbol.FontFamily(Media::FontFamily(L"Segoe MDL2 Assets"));
|
||||
plusSymbol.Glyph(L"\xE109");
|
||||
addRemapKey.Content(plusSymbol);
|
||||
addRemapKey.Margin({ 10, 0, 0, 25 });
|
||||
|
@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include <keyboardmanager/common/KeyboardManagerState.h>
|
||||
class KeyboardManagerState;
|
||||
|
||||
// Function to create the Edit Keyboard Window
|
||||
void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardManagerState);
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "Styles.h"
|
||||
#include "Dialog.h"
|
||||
#include <keyboardmanager/dll/resource.h>
|
||||
#include <keyboardmanager/common/KeyboardManagerState.h>
|
||||
|
||||
using namespace winrt::Windows::Foundation;
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
#pragma once
|
||||
#include "keyboardmanager/common/KeyboardManagerState.h"
|
||||
#include "keyboardmanager/common/Shortcut.h"
|
||||
#include "keyboardmanager/common/Helpers.h"
|
||||
class KeyboardManagerState;
|
||||
|
||||
// Function to create the Edit Shortcuts Window
|
||||
void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardManagerState);
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "pch.h"
|
||||
#include "KeyDropDownControl.h"
|
||||
#include "keyboardmanager/common/Helpers.h"
|
||||
#include <keyboardmanager/common/KeyboardManagerState.h>
|
||||
|
||||
// Initialized to null
|
||||
KeyboardManagerState* KeyDropDownControl::keyboardManagerState = nullptr;
|
||||
@ -8,28 +9,32 @@ KeyboardManagerState* KeyDropDownControl::keyboardManagerState = nullptr;
|
||||
// Function to set properties apart from the SelectionChanged event handler
|
||||
void KeyDropDownControl::SetDefaultProperties(bool isShortcut)
|
||||
{
|
||||
dropDown = ComboBox();
|
||||
warningFlyout = Flyout();
|
||||
warningMessage = TextBlock();
|
||||
|
||||
if (!isShortcut)
|
||||
{
|
||||
dropDown.Width(KeyboardManagerConstants::RemapTableDropDownWidth);
|
||||
dropDown.as<ComboBox>().Width(KeyboardManagerConstants::RemapTableDropDownWidth);
|
||||
}
|
||||
else
|
||||
{
|
||||
dropDown.Width(KeyboardManagerConstants::ShortcutTableDropDownWidth);
|
||||
dropDown.as<ComboBox>().Width(KeyboardManagerConstants::ShortcutTableDropDownWidth);
|
||||
}
|
||||
dropDown.MaxDropDownHeight(KeyboardManagerConstants::TableDropDownHeight);
|
||||
dropDown.as<ComboBox>().MaxDropDownHeight(KeyboardManagerConstants::TableDropDownHeight);
|
||||
// Initialise layout attribute
|
||||
previousLayout = GetKeyboardLayout(0);
|
||||
keyCodeList = keyboardManagerState->keyboardMap.GetKeyCodeList(isShortcut);
|
||||
dropDown.ItemsSource(KeyboardManagerHelper::ToBoxValue(keyboardManagerState->keyboardMap.GetKeyNameList(isShortcut)));
|
||||
dropDown.as<ComboBox>().ItemsSource(KeyboardManagerHelper::ToBoxValue(keyboardManagerState->keyboardMap.GetKeyNameList(isShortcut)));
|
||||
// drop down open handler - to reload the items with the latest layout
|
||||
dropDown.DropDownOpened([&, isShortcut](winrt::Windows::Foundation::IInspectable const& sender, auto args) {
|
||||
dropDown.as<ComboBox>().DropDownOpened([&, isShortcut](winrt::Windows::Foundation::IInspectable const& sender, auto args) {
|
||||
ComboBox currentDropDown = sender.as<ComboBox>();
|
||||
CheckAndUpdateKeyboardLayout(currentDropDown, isShortcut);
|
||||
});
|
||||
|
||||
// Attach flyout to the drop down
|
||||
warningFlyout.Content(warningMessage);
|
||||
dropDown.ContextFlyout().SetAttachedFlyout((FrameworkElement)dropDown, warningFlyout);
|
||||
warningFlyout.as<Flyout>().Content(warningMessage.as<TextBlock>());
|
||||
dropDown.as<ComboBox>().ContextFlyout().SetAttachedFlyout((FrameworkElement)dropDown.as<ComboBox>(), warningFlyout.as<Flyout>());
|
||||
}
|
||||
|
||||
// Function to check if the layout has changed and accordingly update the drop down list
|
||||
@ -48,7 +53,7 @@ void KeyDropDownControl::CheckAndUpdateKeyboardLayout(ComboBox currentDropDown,
|
||||
}
|
||||
|
||||
// Function to set selection handler for single key remap drop down. Needs to be called after the constructor since the singleKeyControl StackPanel is null if called in the constructor
|
||||
void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel& singleKeyControl, int colIndex, std::vector<std::vector<DWORD>>& singleKeyRemapBuffer)
|
||||
void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel singleKeyControl, int colIndex, std::vector<std::vector<DWORD>>& singleKeyRemapBuffer)
|
||||
{
|
||||
// drop down selection handler
|
||||
auto onSelectionChange = [&, table, singleKeyControl, colIndex](winrt::Windows::Foundation::IInspectable const& sender) {
|
||||
@ -111,12 +116,12 @@ void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel& singleKeyC
|
||||
};
|
||||
|
||||
// Rather than on every selection change (which gets triggered on searching as well) we set the handler only when the drop down is closed
|
||||
dropDown.DropDownClosed([onSelectionChange](winrt::Windows::Foundation::IInspectable const& sender, auto const& args) {
|
||||
dropDown.as<ComboBox>().DropDownClosed([onSelectionChange](winrt::Windows::Foundation::IInspectable const& sender, auto const& args) {
|
||||
onSelectionChange(sender);
|
||||
});
|
||||
|
||||
// We check if the selection changed was triggered while the drop down was closed. This is required to handle Type key, initial loading of remaps and if the user just types in the combo box without opening it
|
||||
dropDown.SelectionChanged([onSelectionChange](winrt::Windows::Foundation::IInspectable const& sender, SelectionChangedEventArgs const& args) {
|
||||
dropDown.as<ComboBox>().SelectionChanged([onSelectionChange](winrt::Windows::Foundation::IInspectable const& sender, SelectionChangedEventArgs const& args) {
|
||||
ComboBox currentDropDown = sender.as<ComboBox>();
|
||||
if (!currentDropDown.IsDropDownOpen())
|
||||
{
|
||||
@ -127,7 +132,7 @@ void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel& singleKeyC
|
||||
|
||||
std::pair<KeyboardManagerHelper::ErrorType, int> KeyDropDownControl::ValidateShortcutSelection(Grid table, StackPanel shortcutControl, StackPanel parent, int colIndex, std::vector<std::pair<std::vector<Shortcut>, std::wstring>>& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, TextBox targetApp)
|
||||
{
|
||||
ComboBox currentDropDown = dropDown;
|
||||
ComboBox currentDropDown = dropDown.as<ComboBox>();
|
||||
int selectedKeyIndex = currentDropDown.SelectedIndex();
|
||||
uint32_t dropDownIndex = -1;
|
||||
bool dropDownFound = parent.Children().IndexOf(currentDropDown, dropDownIndex);
|
||||
@ -312,7 +317,7 @@ std::pair<KeyboardManagerHelper::ErrorType, int> KeyDropDownControl::ValidateSho
|
||||
}
|
||||
|
||||
// Function to set selection handler for shortcut drop down. Needs to be called after the constructor since the shortcutControl StackPanel is null if called in the constructor
|
||||
void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel& shortcutControl, StackPanel parent, int colIndex, std::vector<std::pair<std::vector<Shortcut>, std::wstring>>& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, TextBox& targetApp)
|
||||
void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel shortcutControl, StackPanel parent, int colIndex, std::vector<std::pair<std::vector<Shortcut>, std::wstring>>& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, TextBox& targetApp)
|
||||
{
|
||||
auto onSelectionChange = [&, table, shortcutControl, colIndex, parent, targetApp](winrt::Windows::Foundation::IInspectable const& sender) {
|
||||
std::pair<KeyboardManagerHelper::ErrorType, int> validationResult = ValidateShortcutSelection(table, shortcutControl, parent, colIndex, shortcutRemapBuffer, keyDropDownControlObjects, targetApp);
|
||||
@ -357,12 +362,12 @@ void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel& shortcutCo
|
||||
};
|
||||
|
||||
// Rather than on every selection change (which gets triggered on searching as well) we set the handler only when the drop down is closed
|
||||
dropDown.DropDownClosed([onSelectionChange](winrt::Windows::Foundation::IInspectable const& sender, auto const& args) {
|
||||
dropDown.as<ComboBox>().DropDownClosed([onSelectionChange](winrt::Windows::Foundation::IInspectable const& sender, auto const& args) {
|
||||
onSelectionChange(sender);
|
||||
});
|
||||
|
||||
// We check if the selection changed was triggered while the drop down was closed. This is required to handle Type key, initial loading of remaps and if the user just types in the combo box without opening it
|
||||
dropDown.SelectionChanged([onSelectionChange](winrt::Windows::Foundation::IInspectable const& sender, SelectionChangedEventArgs const& args) {
|
||||
dropDown.as<ComboBox>().SelectionChanged([onSelectionChange](winrt::Windows::Foundation::IInspectable const& sender, SelectionChangedEventArgs const& args) {
|
||||
ComboBox currentDropDown = sender.as<ComboBox>();
|
||||
if (!currentDropDown.IsDropDownOpen())
|
||||
{
|
||||
@ -374,13 +379,13 @@ void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel& shortcutCo
|
||||
// Function to set the selected index of the drop down
|
||||
void KeyDropDownControl::SetSelectedIndex(int32_t index)
|
||||
{
|
||||
dropDown.SelectedIndex(index);
|
||||
dropDown.as<ComboBox>().SelectedIndex(index);
|
||||
}
|
||||
|
||||
// Function to return the combo box element of the drop down
|
||||
ComboBox KeyDropDownControl::GetComboBox()
|
||||
{
|
||||
return dropDown;
|
||||
return dropDown.as<ComboBox>();
|
||||
}
|
||||
|
||||
// Function to add a drop down to the shortcut stack panel
|
||||
@ -471,6 +476,6 @@ void KeyDropDownControl::ValidateShortcutFromDropDownList(Grid table, StackPanel
|
||||
void KeyDropDownControl::SetDropDownError(ComboBox currentDropDown, hstring message)
|
||||
{
|
||||
currentDropDown.SelectedIndex(-1);
|
||||
warningMessage.Text(message);
|
||||
currentDropDown.ContextFlyout().ShowAttachedFlyout((FrameworkElement)dropDown);
|
||||
warningMessage.as<TextBlock>().Text(message);
|
||||
currentDropDown.ContextFlyout().ShowAttachedFlyout((FrameworkElement)dropDown.as<ComboBox>());
|
||||
}
|
||||
|
@ -1,20 +1,43 @@
|
||||
#pragma once
|
||||
#include <keyboardmanager/common/KeyboardManagerState.h>
|
||||
class KeyboardManagerState;
|
||||
class Shortcut;
|
||||
|
||||
namespace winrt::Windows
|
||||
{
|
||||
namespace Foundation
|
||||
{
|
||||
struct hstring;
|
||||
}
|
||||
|
||||
namespace UI::Xaml::Controls
|
||||
{
|
||||
struct StackPanel;
|
||||
struct Grid;
|
||||
struct ComboBox;
|
||||
struct Flyout;
|
||||
struct TextBlock;
|
||||
}
|
||||
}
|
||||
|
||||
namespace KeyboardManagerHelper
|
||||
{
|
||||
enum class ErrorType;
|
||||
}
|
||||
|
||||
// Wrapper class for the key drop down menu
|
||||
class KeyDropDownControl
|
||||
{
|
||||
private:
|
||||
// Stores the drop down combo box
|
||||
ComboBox dropDown;
|
||||
winrt::Windows::Foundation::IInspectable dropDown;
|
||||
// Stores the previous layout
|
||||
HKL previousLayout = 0;
|
||||
// Stores the key code list
|
||||
std::vector<DWORD> keyCodeList;
|
||||
// Stores the flyout warning message
|
||||
TextBlock warningMessage;
|
||||
winrt::Windows::Foundation::IInspectable warningMessage;
|
||||
// Stores the flyout attached to the current drop down
|
||||
Flyout warningFlyout;
|
||||
winrt::Windows::Foundation::IInspectable warningFlyout;
|
||||
|
||||
// Function to set properties apart from the SelectionChanged event handler
|
||||
void SetDefaultProperties(bool isShortcut);
|
||||
@ -33,13 +56,13 @@ public:
|
||||
}
|
||||
|
||||
// Function to set selection handler for single key remap drop down. Needs to be called after the constructor since the singleKeyControl StackPanel is null if called in the constructor
|
||||
void SetSelectionHandler(Grid& table, StackPanel& singleKeyControl, int colIndex, std::vector<std::vector<DWORD>>& singleKeyRemapBuffer);
|
||||
void SetSelectionHandler(winrt::Windows::UI::Xaml::Controls::Grid& table, winrt::Windows::UI::Xaml::Controls::StackPanel singleKeyControl, int colIndex, std::vector<std::vector<DWORD>>& singleKeyRemapBuffer);
|
||||
|
||||
// Function for validating the selection of shortcuts for the drop down
|
||||
std::pair<KeyboardManagerHelper::ErrorType, int> ValidateShortcutSelection(Grid table, StackPanel shortcutControl, StackPanel parent, int colIndex, std::vector<std::pair<std::vector<Shortcut>, std::wstring>>& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, TextBox targetApp);
|
||||
std::pair<KeyboardManagerHelper::ErrorType, int> ValidateShortcutSelection(winrt::Windows::UI::Xaml::Controls::Grid table, winrt::Windows::UI::Xaml::Controls::StackPanel shortcutControl, winrt::Windows::UI::Xaml::Controls::StackPanel parent, int colIndex, std::vector<std::pair<std::vector<Shortcut>, std::wstring>>& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, winrt::Windows::UI::Xaml::Controls::TextBox targetApp);
|
||||
|
||||
// Function to set selection handler for shortcut drop down. Needs to be called after the constructor since the shortcutControl StackPanel is null if called in the constructor
|
||||
void SetSelectionHandler(Grid& table, StackPanel& shortcutControl, StackPanel parent, int colIndex, std::vector<std::pair<std::vector<Shortcut>, std::wstring>>& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, TextBox& targetApp);
|
||||
void SetSelectionHandler(winrt::Windows::UI::Xaml::Controls::Grid& table, winrt::Windows::UI::Xaml::Controls::StackPanel shortcutControl, winrt::Windows::UI::Xaml::Controls::StackPanel parent, int colIndex, std::vector<std::pair<std::vector<Shortcut>, std::wstring>>& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, winrt::Windows::UI::Xaml::Controls::TextBox& targetApp);
|
||||
|
||||
// Function to set the selected index of the drop down
|
||||
void SetSelectedIndex(int32_t index);
|
||||
@ -48,17 +71,17 @@ public:
|
||||
ComboBox GetComboBox();
|
||||
|
||||
// Function to add a drop down to the shortcut stack panel
|
||||
static void AddDropDown(Grid table, StackPanel shortcutControl, StackPanel parent, const int colIndex, std::vector<std::pair<std::vector<Shortcut>, std::wstring>>& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, TextBox& targetApp);
|
||||
static void AddDropDown(winrt::Windows::UI::Xaml::Controls::Grid table, winrt::Windows::UI::Xaml::Controls::StackPanel shortcutControl, winrt::Windows::UI::Xaml::Controls::StackPanel parent, const int colIndex, std::vector<std::pair<std::vector<Shortcut>, std::wstring>>& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, winrt::Windows::UI::Xaml::Controls::TextBox& targetApp);
|
||||
|
||||
// Function to get the list of key codes from the shortcut combo box stack panel
|
||||
static std::vector<DWORD> GetKeysFromStackPanel(StackPanel parent);
|
||||
|
||||
// Function to check if a modifier has been repeated in the previous drop downs
|
||||
static bool CheckRepeatedModifier(StackPanel parent, int selectedKeyIndex, const std::vector<DWORD>& keyCodeList);
|
||||
static bool CheckRepeatedModifier(winrt::Windows::UI::Xaml::Controls::StackPanel parent, int selectedKeyIndex, const std::vector<DWORD>& keyCodeList);
|
||||
|
||||
// Function for validating the selection of shortcuts for all the associated drop downs
|
||||
static void ValidateShortcutFromDropDownList(Grid table, StackPanel shortcutControl, StackPanel parent, int colIndex, std::vector<std::pair<std::vector<Shortcut>, std::wstring>>& shortcutRemapBuffer, std::vector<std::unique_ptr<KeyDropDownControl>>& keyDropDownControlObjects, TextBox targetApp);
|
||||
|
||||
// Function to set the warning message
|
||||
void SetDropDownError(ComboBox currentDropDown, hstring message);
|
||||
void SetDropDownError(winrt::Windows::UI::Xaml::Controls::ComboBox currentDropDown, winrt::hstring message);
|
||||
};
|
||||
|
@ -105,6 +105,8 @@
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">/MP %(AdditionalOptions)</AdditionalOptions>
|
||||
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">/MP %(AdditionalOptions)</AdditionalOptions>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "pch.h"
|
||||
#include "ShortcutControl.h"
|
||||
#include "KeyDropDownControl.h"
|
||||
#include "keyboardmanager/common/KeyboardManagerState.h"
|
||||
|
||||
//Both static members are initialized to null
|
||||
HWND ShortcutControl::EditShortcutsWindowHandle = nullptr;
|
||||
@ -8,6 +9,32 @@ KeyboardManagerState* ShortcutControl::keyboardManagerState = nullptr;
|
||||
// Initialized as new vector
|
||||
std::vector<std::pair<std::vector<Shortcut>, std::wstring>> ShortcutControl::shortcutRemapBuffer;
|
||||
|
||||
ShortcutControl::ShortcutControl(Grid table, const int colIndex, TextBox targetApp)
|
||||
{
|
||||
shortcutDropDownStackPanel = StackPanel();
|
||||
typeShortcut = Button();
|
||||
shortcutControlLayout = StackPanel();
|
||||
|
||||
shortcutDropDownStackPanel.as<StackPanel>().Spacing(KeyboardManagerConstants::ShortcutTableDropDownSpacing);
|
||||
shortcutDropDownStackPanel.as<StackPanel>().Orientation(Windows::UI::Xaml::Controls::Orientation::Horizontal);
|
||||
|
||||
typeShortcut.as<Button>().Content(winrt::box_value(L"Type Shortcut"));
|
||||
typeShortcut.as<Button>().Width(KeyboardManagerConstants::ShortcutTableDropDownWidth);
|
||||
typeShortcut.as<Button>().Click([&, table, colIndex, targetApp](winrt::Windows::Foundation::IInspectable const& sender, RoutedEventArgs const&) {
|
||||
keyboardManagerState->SetUIState(KeyboardManagerUIState::DetectShortcutWindowActivated, EditShortcutsWindowHandle);
|
||||
// Using the XamlRoot of the typeShortcut to get the root of the XAML host
|
||||
createDetectShortcutWindow(sender, sender.as<Button>().XamlRoot(), shortcutRemapBuffer, *keyboardManagerState, colIndex, table, targetApp);
|
||||
});
|
||||
|
||||
shortcutControlLayout.as<StackPanel>().Margin({ 0, 0, 0, 10 });
|
||||
shortcutControlLayout.as<StackPanel>().Spacing(KeyboardManagerConstants::ShortcutTableDropDownSpacing);
|
||||
|
||||
shortcutControlLayout.as<StackPanel>().Children().Append(typeShortcut.as<Button>());
|
||||
shortcutControlLayout.as<StackPanel>().Children().Append(shortcutDropDownStackPanel.as<StackPanel>());
|
||||
KeyDropDownControl::AddDropDown(table, shortcutControlLayout.as<StackPanel>(), shortcutDropDownStackPanel.as<StackPanel>(), colIndex, shortcutRemapBuffer, keyDropDownControlObjects, targetApp);
|
||||
shortcutControlLayout.as<StackPanel>().UpdateLayout();
|
||||
}
|
||||
|
||||
// Function to add a new row to the shortcut table. If the originalKeys and newKeys args are provided, then the displayed shortcuts are set to those values.
|
||||
void ShortcutControl::AddNewShortcutControlRow(Grid& parent, std::vector<std::vector<std::unique_ptr<ShortcutControl>>>& keyboardRemapControlObjects, Shortcut originalKeys, Shortcut newKeys, std::wstring targetAppName)
|
||||
{
|
||||
@ -60,12 +87,12 @@ void ShortcutControl::AddNewShortcutControlRow(Grid& parent, std::vector<std::ve
|
||||
int rowIndex = (lastIndexInRow - KeyboardManagerConstants::ShortcutTableHeaderCount) / KeyboardManagerConstants::ShortcutTableColCount;
|
||||
|
||||
// Validate both set of drop downs
|
||||
KeyDropDownControl::ValidateShortcutFromDropDownList(parent, keyboardRemapControlObjects[rowIndex][0]->getShortcutControl(), keyboardRemapControlObjects[rowIndex][0]->shortcutDropDownStackPanel, 0, ShortcutControl::shortcutRemapBuffer, keyboardRemapControlObjects[rowIndex][0]->keyDropDownControlObjects, targetAppTextBox);
|
||||
KeyDropDownControl::ValidateShortcutFromDropDownList(parent, keyboardRemapControlObjects[rowIndex][1]->getShortcutControl(), keyboardRemapControlObjects[rowIndex][1]->shortcutDropDownStackPanel, 1, ShortcutControl::shortcutRemapBuffer, keyboardRemapControlObjects[rowIndex][1]->keyDropDownControlObjects, targetAppTextBox);
|
||||
KeyDropDownControl::ValidateShortcutFromDropDownList(parent, keyboardRemapControlObjects[rowIndex][0]->getShortcutControl(), keyboardRemapControlObjects[rowIndex][0]->shortcutDropDownStackPanel.as<StackPanel>(), 0, ShortcutControl::shortcutRemapBuffer, keyboardRemapControlObjects[rowIndex][0]->keyDropDownControlObjects, targetAppTextBox);
|
||||
KeyDropDownControl::ValidateShortcutFromDropDownList(parent, keyboardRemapControlObjects[rowIndex][1]->getShortcutControl(), keyboardRemapControlObjects[rowIndex][1]->shortcutDropDownStackPanel.as<StackPanel>(), 1, ShortcutControl::shortcutRemapBuffer, keyboardRemapControlObjects[rowIndex][1]->keyDropDownControlObjects, targetAppTextBox);
|
||||
|
||||
// Reset the buffer based on the selected drop down items
|
||||
shortcutRemapBuffer[rowIndex].first[0].SetKeyCodes(KeyDropDownControl::GetKeysFromStackPanel(keyboardRemapControlObjects[rowIndex][0]->shortcutDropDownStackPanel));
|
||||
shortcutRemapBuffer[rowIndex].first[1].SetKeyCodes(KeyDropDownControl::GetKeysFromStackPanel(keyboardRemapControlObjects[rowIndex][1]->shortcutDropDownStackPanel));
|
||||
shortcutRemapBuffer[rowIndex].first[0].SetKeyCodes(KeyDropDownControl::GetKeysFromStackPanel(keyboardRemapControlObjects[rowIndex][0]->shortcutDropDownStackPanel.as<StackPanel>()));
|
||||
shortcutRemapBuffer[rowIndex].first[1].SetKeyCodes(KeyDropDownControl::GetKeysFromStackPanel(keyboardRemapControlObjects[rowIndex][1]->shortcutDropDownStackPanel.as<StackPanel>()));
|
||||
std::wstring newText = targetAppTextBox.Text().c_str();
|
||||
std::wstring lowercaseDefAppName = KeyboardManagerConstants::DefaultAppName;
|
||||
std::transform(newText.begin(), newText.end(), newText.begin(), towlower);
|
||||
@ -130,8 +157,8 @@ void ShortcutControl::AddNewShortcutControlRow(Grid& parent, std::vector<std::ve
|
||||
{
|
||||
// change to load app name
|
||||
shortcutRemapBuffer.push_back(std::make_pair<std::vector<Shortcut>, std::wstring>(std::vector<Shortcut>{ Shortcut(), Shortcut() }, std::wstring(targetAppName)));
|
||||
keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][0]->AddShortcutToControl(originalKeys, parent, keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][0]->shortcutDropDownStackPanel, *keyboardManagerState, 0, targetAppTextBox);
|
||||
keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][1]->AddShortcutToControl(newKeys, parent, keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][1]->shortcutDropDownStackPanel, *keyboardManagerState, 1, targetAppTextBox);
|
||||
keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][0]->AddShortcutToControl(originalKeys, parent, keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][0]->shortcutDropDownStackPanel.as<StackPanel>(), *keyboardManagerState, 0, targetAppTextBox);
|
||||
keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][1]->AddShortcutToControl(newKeys, parent, keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][1]->shortcutDropDownStackPanel.as<StackPanel>(), *keyboardManagerState, 1, targetAppTextBox);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -152,7 +179,7 @@ void ShortcutControl::AddShortcutToControl(Shortcut& shortcut, Grid table, Stack
|
||||
std::vector<DWORD> keyCodeList = keyboardManagerState.keyboardMap.GetKeyCodeList(true);
|
||||
if (shortcutKeyCodes.size() != 0)
|
||||
{
|
||||
KeyDropDownControl::AddDropDown(table, shortcutControlLayout, parent, colIndex, shortcutRemapBuffer, keyDropDownControlObjects, targetApp);
|
||||
KeyDropDownControl::AddDropDown(table, shortcutControlLayout.as<StackPanel>(), parent, colIndex, shortcutRemapBuffer, keyDropDownControlObjects, targetApp);
|
||||
for (int i = 0; i < shortcutKeyCodes.size(); i++)
|
||||
{
|
||||
// New drop down gets added automatically when the SelectedIndex is set
|
||||
@ -173,7 +200,7 @@ void ShortcutControl::AddShortcutToControl(Shortcut& shortcut, Grid table, Stack
|
||||
// Function to return the stack panel element of the ShortcutControl. This is the externally visible UI element which can be used to add it to other layouts
|
||||
StackPanel ShortcutControl::getShortcutControl()
|
||||
{
|
||||
return shortcutControlLayout;
|
||||
return shortcutControlLayout.as<StackPanel>();
|
||||
}
|
||||
|
||||
// Function to create the detect shortcut UI window
|
||||
|
@ -1,20 +1,30 @@
|
||||
#pragma once
|
||||
#include <keyboardmanager/common/KeyboardManagerState.h>
|
||||
#include <keyboardManager/common/Helpers.h>
|
||||
#include <keyboardmanager/common/Shortcut.h>
|
||||
#include "KeyDropDownControl.h"
|
||||
#include "keyboardmanager/common/Shortcut.h"
|
||||
|
||||
class KeyboardManagerState;
|
||||
class KeyDropDownControl;
|
||||
namespace winrt::Windows::UI::Xaml
|
||||
{
|
||||
struct XamlRoot;
|
||||
namespace Controls
|
||||
{
|
||||
struct StackPanel;
|
||||
struct Grid;
|
||||
struct TextBox;
|
||||
}
|
||||
}
|
||||
|
||||
class ShortcutControl
|
||||
{
|
||||
private:
|
||||
// Stack panel for the drop downs to display the selected shortcut
|
||||
StackPanel shortcutDropDownStackPanel;
|
||||
winrt::Windows::Foundation::IInspectable shortcutDropDownStackPanel;
|
||||
|
||||
// Button to type the shortcut
|
||||
Button typeShortcut;
|
||||
winrt::Windows::Foundation::IInspectable typeShortcut;
|
||||
|
||||
// StackPanel to parent the above controls
|
||||
StackPanel shortcutControlLayout;
|
||||
winrt::Windows::Foundation::IInspectable shortcutControlLayout;
|
||||
|
||||
public:
|
||||
// Handle to the current Edit Shortcuts Window
|
||||
@ -26,27 +36,8 @@ public:
|
||||
// Vector to store dynamically allocated KeyDropDownControl objects to avoid early destruction
|
||||
std::vector<std::unique_ptr<KeyDropDownControl>> keyDropDownControlObjects;
|
||||
|
||||
ShortcutControl(Grid table, const int colIndex, TextBox targetApp)
|
||||
{
|
||||
shortcutDropDownStackPanel.Spacing(KeyboardManagerConstants::ShortcutTableDropDownSpacing);
|
||||
shortcutDropDownStackPanel.Orientation(Windows::UI::Xaml::Controls::Orientation::Horizontal);
|
||||
|
||||
typeShortcut.Content(winrt::box_value(L"Type Shortcut"));
|
||||
typeShortcut.Width(KeyboardManagerConstants::ShortcutTableDropDownWidth);
|
||||
typeShortcut.Click([&, table, colIndex, targetApp](winrt::Windows::Foundation::IInspectable const& sender, RoutedEventArgs const&) {
|
||||
keyboardManagerState->SetUIState(KeyboardManagerUIState::DetectShortcutWindowActivated, EditShortcutsWindowHandle);
|
||||
// Using the XamlRoot of the typeShortcut to get the root of the XAML host
|
||||
createDetectShortcutWindow(sender, sender.as<Button>().XamlRoot(), shortcutRemapBuffer, *keyboardManagerState, colIndex, table, targetApp);
|
||||
});
|
||||
|
||||
shortcutControlLayout.Margin({ 0, 0, 0, 10 });
|
||||
shortcutControlLayout.Spacing(KeyboardManagerConstants::ShortcutTableDropDownSpacing);
|
||||
|
||||
shortcutControlLayout.Children().Append(typeShortcut);
|
||||
shortcutControlLayout.Children().Append(shortcutDropDownStackPanel);
|
||||
KeyDropDownControl::AddDropDown(table, shortcutControlLayout, shortcutDropDownStackPanel, colIndex, shortcutRemapBuffer, keyDropDownControlObjects, targetApp);
|
||||
shortcutControlLayout.UpdateLayout();
|
||||
}
|
||||
// constructor
|
||||
ShortcutControl(Grid table, const int colIndex, TextBox targetApp);
|
||||
|
||||
// Function to add a new row to the shortcut table. If the originalKeys and newKeys args are provided, then the displayed shortcuts are set to those values.
|
||||
static void AddNewShortcutControlRow(Grid& parent, std::vector<std::vector<std::unique_ptr<ShortcutControl>>>& keyboardRemapControlObjects, Shortcut originalKeys = Shortcut(), Shortcut newKeys = Shortcut(), std::wstring targetAppName = L"");
|
||||
|
@ -1,6 +1,9 @@
|
||||
#include "pch.h"
|
||||
#include "SingleKeyRemapControl.h"
|
||||
#include "keyboardmanager/common/Helpers.h"
|
||||
#include "keyboardmanager/common/KeyboardManagerConstants.h"
|
||||
#include "keyboardmanager/common/KeyboardManagerState.h"
|
||||
|
||||
|
||||
//Both static members are initialized to null
|
||||
HWND SingleKeyRemapControl::EditKeyboardWindowHandle = nullptr;
|
||||
@ -8,6 +11,29 @@ KeyboardManagerState* SingleKeyRemapControl::keyboardManagerState = nullptr;
|
||||
// Initialized as new vector
|
||||
std::vector<std::vector<DWORD>> SingleKeyRemapControl::singleKeyRemapBuffer;
|
||||
|
||||
SingleKeyRemapControl::SingleKeyRemapControl(Grid table, const int colIndex) :
|
||||
singleKeyRemapDropDown(false)
|
||||
{
|
||||
typeKey = Button();
|
||||
typeKey.as<Button>().Content(winrt::box_value(L"Type Key"));
|
||||
typeKey.as<Button>().Width(KeyboardManagerConstants::RemapTableDropDownWidth);
|
||||
typeKey.as<Button>().Click([&](winrt::Windows::Foundation::IInspectable const& sender, RoutedEventArgs const&) {
|
||||
keyboardManagerState->SetUIState(KeyboardManagerUIState::DetectSingleKeyRemapWindowActivated, EditKeyboardWindowHandle);
|
||||
// Using the XamlRoot of the typeKey to get the root of the XAML host
|
||||
createDetectKeyWindow(sender, sender.as<Button>().XamlRoot(), singleKeyRemapBuffer, *keyboardManagerState);
|
||||
});
|
||||
|
||||
singleKeyRemapControlLayout = StackPanel();
|
||||
singleKeyRemapControlLayout.as<StackPanel>().Margin({ 0, 0, 0, 10 });
|
||||
singleKeyRemapControlLayout.as<StackPanel>().Spacing(10);
|
||||
|
||||
singleKeyRemapControlLayout.as<StackPanel>().Children().Append(typeKey.as<Button>());
|
||||
singleKeyRemapControlLayout.as<StackPanel>().Children().Append(singleKeyRemapDropDown.GetComboBox());
|
||||
// Set selection handler for the drop down
|
||||
singleKeyRemapDropDown.SetSelectionHandler(table, singleKeyRemapControlLayout.as<StackPanel>(), colIndex, singleKeyRemapBuffer);
|
||||
singleKeyRemapControlLayout.as<StackPanel>().UpdateLayout();
|
||||
}
|
||||
|
||||
// Function to add a new row to the remap keys table. If the originalKey and newKey args are provided, then the displayed remap keys are set to those values.
|
||||
void SingleKeyRemapControl::AddNewControlKeyRemapRow(Grid& parent, std::vector<std::vector<std::unique_ptr<SingleKeyRemapControl>>>& keyboardRemapControlObjects, const DWORD originalKey, const DWORD newKey)
|
||||
{
|
||||
@ -28,7 +54,7 @@ void SingleKeyRemapControl::AddNewControlKeyRemapRow(Grid& parent, std::vector<s
|
||||
|
||||
// Arrow icon
|
||||
FontIcon arrowIcon;
|
||||
arrowIcon.FontFamily(Xaml::Media::FontFamily(L"Segoe MDL2 Assets"));
|
||||
arrowIcon.FontFamily(Media::FontFamily(L"Segoe MDL2 Assets"));
|
||||
arrowIcon.Glyph(L"\xE72A");
|
||||
arrowIcon.VerticalAlignment(VerticalAlignment::Center);
|
||||
arrowIcon.HorizontalAlignment(HorizontalAlignment::Center);
|
||||
@ -64,7 +90,7 @@ void SingleKeyRemapControl::AddNewControlKeyRemapRow(Grid& parent, std::vector<s
|
||||
// Delete row button
|
||||
Windows::UI::Xaml::Controls::Button deleteRemapKeys;
|
||||
FontIcon deleteSymbol;
|
||||
deleteSymbol.FontFamily(Xaml::Media::FontFamily(L"Segoe MDL2 Assets"));
|
||||
deleteSymbol.FontFamily(Media::FontFamily(L"Segoe MDL2 Assets"));
|
||||
deleteSymbol.Glyph(L"\xE74D");
|
||||
deleteRemapKeys.Content(deleteSymbol);
|
||||
deleteRemapKeys.Background(Media::SolidColorBrush(Colors::Transparent()));
|
||||
@ -106,7 +132,7 @@ void SingleKeyRemapControl::AddNewControlKeyRemapRow(Grid& parent, std::vector<s
|
||||
// Function to return the stack panel element of the SingleKeyRemapControl. This is the externally visible UI element which can be used to add it to other layouts
|
||||
StackPanel SingleKeyRemapControl::getSingleKeyRemapControl()
|
||||
{
|
||||
return singleKeyRemapControlLayout;
|
||||
return singleKeyRemapControlLayout.as<StackPanel>();
|
||||
}
|
||||
|
||||
// Function to create the detect remap key UI window
|
||||
|
@ -1,7 +1,17 @@
|
||||
#pragma once
|
||||
#include <keyboardmanager/common/KeyboardManagerState.h>
|
||||
#include "KeyDropDownControl.h"
|
||||
|
||||
class KeyboardManagerState;
|
||||
namespace winrt::Windows::UI::Xaml
|
||||
{
|
||||
struct XamlRoot;
|
||||
namespace Controls
|
||||
{
|
||||
struct StackPanel;
|
||||
struct Grid;
|
||||
}
|
||||
}
|
||||
|
||||
class SingleKeyRemapControl
|
||||
{
|
||||
private:
|
||||
@ -9,10 +19,10 @@ private:
|
||||
KeyDropDownControl singleKeyRemapDropDown;
|
||||
|
||||
// Button to type the remap key
|
||||
Button typeKey;
|
||||
winrt::Windows::Foundation::IInspectable typeKey;
|
||||
|
||||
// StackPanel to parent the above controls
|
||||
StackPanel singleKeyRemapControlLayout;
|
||||
winrt::Windows::Foundation::IInspectable singleKeyRemapControlLayout;
|
||||
|
||||
public:
|
||||
// Handle to the current Edit Keyboard Window
|
||||
@ -22,32 +32,14 @@ public:
|
||||
// Stores the current list of remappings
|
||||
static std::vector<std::vector<DWORD>> singleKeyRemapBuffer;
|
||||
|
||||
SingleKeyRemapControl(Grid table, const int colIndex) :
|
||||
singleKeyRemapDropDown(false)
|
||||
{
|
||||
typeKey.Content(winrt::box_value(L"Type Key"));
|
||||
typeKey.Width(KeyboardManagerConstants::RemapTableDropDownWidth);
|
||||
typeKey.Click([&](winrt::Windows::Foundation::IInspectable const& sender, RoutedEventArgs const&) {
|
||||
keyboardManagerState->SetUIState(KeyboardManagerUIState::DetectSingleKeyRemapWindowActivated, EditKeyboardWindowHandle);
|
||||
// Using the XamlRoot of the typeKey to get the root of the XAML host
|
||||
createDetectKeyWindow(sender, sender.as<Button>().XamlRoot(), singleKeyRemapBuffer, *keyboardManagerState);
|
||||
});
|
||||
|
||||
singleKeyRemapControlLayout.Margin({ 0, 0, 0, 10 });
|
||||
singleKeyRemapControlLayout.Spacing(10);
|
||||
|
||||
singleKeyRemapControlLayout.Children().Append(typeKey);
|
||||
singleKeyRemapControlLayout.Children().Append(singleKeyRemapDropDown.GetComboBox());
|
||||
// Set selection handler for the drop down
|
||||
singleKeyRemapDropDown.SetSelectionHandler(table, singleKeyRemapControlLayout, colIndex, singleKeyRemapBuffer);
|
||||
singleKeyRemapControlLayout.UpdateLayout();
|
||||
}
|
||||
// constructor
|
||||
SingleKeyRemapControl(Grid table, const int colIndex);
|
||||
|
||||
// Function to add a new row to the remap keys table. If the originalKey and newKey args are provided, then the displayed remap keys are set to those values.
|
||||
static void AddNewControlKeyRemapRow(Grid& parent, std::vector<std::vector<std::unique_ptr<SingleKeyRemapControl>>>& keyboardRemapControlObjects, const DWORD originalKey = NULL, const DWORD newKey = NULL);
|
||||
static void AddNewControlKeyRemapRow(winrt::Windows::UI::Xaml::Controls::Grid& parent, std::vector<std::vector<std::unique_ptr<SingleKeyRemapControl>>>& keyboardRemapControlObjects, const DWORD originalKey = NULL, const DWORD newKey = NULL);
|
||||
|
||||
// Function to return the stack panel element of the SingleKeyRemapControl. This is the externally visible UI element which can be used to add it to other layouts
|
||||
StackPanel getSingleKeyRemapControl();
|
||||
winrt::Windows::UI::Xaml::Controls::StackPanel getSingleKeyRemapControl();
|
||||
|
||||
// Function to create the detect remap keys UI window
|
||||
void createDetectKeyWindow(winrt::Windows::Foundation::IInspectable const& sender, XamlRoot xamlRoot, std::vector<std::vector<DWORD>>& singleKeyRemapBuffer, KeyboardManagerState& keyboardManagerState);
|
||||
|
@ -1,7 +1,5 @@
|
||||
#include "pch.h"
|
||||
#include "Styles.h"
|
||||
#include <winrt/Windows.Foundation.h>
|
||||
#include <winrt/Windows.UI.Xaml.Interop.h>
|
||||
#include <common/windows_colors.h>
|
||||
|
||||
Style AccentButtonStyle()
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <winrt/Windows.UI.Xaml.h>
|
||||
namespace winrt::Windows::UI::Xaml
|
||||
{
|
||||
struct Style;
|
||||
}
|
||||
|
||||
using namespace winrt::Windows::UI::Xaml;
|
||||
|
||||
Style AccentButtonStyle();
|
||||
winrt::Windows::UI::Xaml::Style AccentButtonStyle();
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "pch.h"
|
||||
|
||||
#include "XamlBridge.h"
|
||||
#include <windowsx.h>
|
||||
|
||||
bool XamlBridge::FilterMessage(const MSG* msg)
|
||||
{
|
||||
|
@ -1,12 +1,5 @@
|
||||
#pragma once
|
||||
#include <unknwn.h> // To enable support for non-WinRT interfaces, unknwn.h must be included before any C++/WinRT headers.
|
||||
#include <winrt/Windows.System.h>
|
||||
#include <winrt/Windows.Foundation.h>
|
||||
#include <winrt/Windows.Foundation.Collections.h>
|
||||
#include <winrt/Windows.UI.Xaml.Hosting.h>
|
||||
#include <winrt/Windows.UI.Xaml.Markup.h>
|
||||
#include <windows.ui.xaml.hosting.desktopwindowxamlsource.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
// This class is used for handling XAML Island operations
|
||||
class XamlBridge
|
||||
|
@ -16,6 +16,8 @@
|
||||
#include "winrt/Windows.UI.Xaml.Controls.Primitives.h"
|
||||
#include "winrt/Windows.UI.Text.h"
|
||||
#include "winrt/Windows.UI.Core.h"
|
||||
#include <winrt/Windows.UI.Xaml.Interop.h>
|
||||
#include <mutex>
|
||||
|
||||
using namespace winrt;
|
||||
using namespace Windows::UI;
|
||||
|
Loading…
Reference in New Issue
Block a user