[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:
Arjun Balgovind
2020-07-13 11:49:09 -07:00
committed by GitHub
parent 7db5d6a307
commit 6a9badd31b
37 changed files with 291 additions and 180 deletions

View File

@@ -1,7 +1,17 @@
#pragma once #pragma once
#include <vector> namespace winrt
#include <winrt/Windows.System.h> {
#include <winrt/Windows.Foundation.h> struct hstring;
namespace Windows::Foundation
{
struct IInspectable;
namespace Collections
{
template<typename T>
struct IVector;
}
}
}
namespace KeyboardManagerHelper namespace KeyboardManagerHelper
{ {

View File

@@ -1,6 +1,4 @@
#pragma once #pragma once
#include "windows.h"
#include <string>
// Interface used to wrap keyboard input library methods // Interface used to wrap keyboard input library methods
class InputInterface class InputInterface

View File

@@ -1,9 +1,9 @@
#pragma once #pragma once
#include <interface/lowlevel_keyboard_event_data.h>
#include <functional> #include <functional>
#include <thread> #include <thread>
#include <queue> #include <queue>
#include <mutex> #include <mutex>
#include <interface/lowlevel_keyboard_event_data.h>
// Available states for the KeyDelay state machine. // Available states for the KeyDelay state machine.
enum class KeyDelayState enum class KeyDelayState

View File

@@ -99,6 +99,8 @@
<ClCompile> <ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader> <PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">/MP %(AdditionalOptions)</AdditionalOptions>
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">/MP %(AdditionalOptions)</AdditionalOptions>
</ClCompile> </ClCompile>
<Lib> <Lib>
<AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">shlwapi.lib;</AdditionalDependencies> <AdditionalDependencies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">shlwapi.lib;</AdditionalDependencies>

View File

@@ -1,5 +1,7 @@
#include "pch.h" #include "pch.h"
#include "KeyboardManagerState.h" #include "KeyboardManagerState.h"
#include <../common/settings_helpers.h>
#include "KeyDelay.h"
// Constructor // Constructor
KeyboardManagerState::KeyboardManagerState() : KeyboardManagerState::KeyboardManagerState() :
@@ -179,15 +181,15 @@ bool KeyboardManagerState::AddAppSpecificShortcut(const std::wstring& app, const
void KeyboardManagerState::ConfigureDetectShortcutUI(const StackPanel& textBlock1, const StackPanel& textBlock2) 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);
currentShortcutUI1 = textBlock1; currentShortcutUI1 = textBlock1.as<winrt::Windows::Foundation::IInspectable>();
currentShortcutUI2 = textBlock2; 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 // 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) void KeyboardManagerState::ConfigureDetectSingleKeyRemapUI(const StackPanel& textBlock)
{ {
std::lock_guard<std::mutex> lock(currentSingleKeyUI_mutex); 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) void KeyboardManagerState::AddKeyToLayout(const StackPanel& panel, const hstring& key)
@@ -226,34 +228,34 @@ 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.
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); std::vector<hstring> shortcut = detectedShortcutCopy.GetKeyVector(keyboardMap);
currentShortcutUI1.Children().Clear(); currentShortcutUI1.as<StackPanel>().Children().Clear();
currentShortcutUI2.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 // The second row should be hidden if there are 3 keys or lesser to avoid an extra margin
if (shortcut.size() > 3) if (shortcut.size() > 3)
{ {
currentShortcutUI2.Visibility(Visibility::Visible); currentShortcutUI2.as<StackPanel>().Visibility(Visibility::Visible);
} }
else else
{ {
currentShortcutUI2.Visibility(Visibility::Collapsed); currentShortcutUI2.as<StackPanel>().Visibility(Visibility::Collapsed);
} }
for (int i = 0; i < shortcut.size(); i++) for (int i = 0; i < shortcut.size(); i++)
{ {
if (i < 3) if (i < 3)
{ {
AddKeyToLayout(currentShortcutUI1, shortcut[i]); AddKeyToLayout(currentShortcutUI1.as<StackPanel>(), shortcut[i]);
} }
else else
{ {
AddKeyToLayout(currentShortcutUI2, shortcut[i]); AddKeyToLayout(currentShortcutUI2.as<StackPanel>(), shortcut[i]);
} }
} }
currentShortcutUI1.UpdateLayout(); currentShortcutUI1.as<StackPanel>().UpdateLayout();
currentShortcutUI2.UpdateLayout(); currentShortcutUI2.as<StackPanel>().UpdateLayout();
}); });
} }
@@ -265,13 +267,12 @@ void KeyboardManagerState::UpdateDetectSingleKeyRemapUI()
{ {
return; return;
} }
// 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.
currentSingleKeyUI.Dispatcher().RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, [this]() { currentSingleKeyUI.as<StackPanel>().Dispatcher().RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, [this]() {
currentSingleKeyUI.Children().Clear(); currentSingleKeyUI.as<StackPanel>().Children().Clear();
hstring key = winrt::to_hstring(keyboardMap.GetKeyName(detectedRemapKey).c_str()); hstring key = winrt::to_hstring(keyboardMap.GetKeyName(detectedRemapKey).c_str());
AddKeyToLayout(currentSingleKeyUI, key); AddKeyToLayout(currentSingleKeyUI.as<StackPanel>(), key);
currentSingleKeyUI.UpdateLayout(); currentSingleKeyUI.as<StackPanel>().UpdateLayout();
}); });
} }

View File

@@ -1,16 +1,19 @@
#pragma once #pragma once
#include "Helpers.h" #include "Helpers.h"
#include "../common/keyboard_layout.h"
#include "Shortcut.h" #include "Shortcut.h"
#include "RemapShortcut.h" #include "RemapShortcut.h"
#include "KeyDelay.h"
#include "KeyboardManagerConstants.h"
#include <interface/lowlevel_keyboard_event_data.h>
#include <mutex> #include <mutex>
#include <winrt/Windows.UI.Xaml.Controls.h> #include "KeyboardManagerConstants.h"
#include <../common/settings_helpers.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 type to store different states of the UI
enum class KeyboardManagerUIState enum class KeyboardManagerUIState
@@ -52,12 +55,12 @@ private:
std::mutex detectedRemapKey_mutex; std::mutex detectedRemapKey_mutex;
// Stores the UI element which is to be updated based on the remap key entered. // 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; 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) // Stores the UI element which is to be updated based on the shortcut entered (each stackpanel represents a row of keys)
StackPanel currentShortcutUI1; winrt::Windows::Foundation::IInspectable currentShortcutUI1;
StackPanel currentShortcutUI2; winrt::Windows::Foundation::IInspectable currentShortcutUI2;
std::mutex currentShortcutUI_mutex; std::mutex currentShortcutUI_mutex;
// Stores the current configuration name. // Stores the current configuration name.
@@ -75,7 +78,7 @@ private:
std::wstring activatedAppSpecificShortcutTarget; std::wstring activatedAppSpecificShortcutTarget;
// Display a key by appending a border Control as a child of the panel. // 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: public:
// The map members and their mutexes are left as public since the maps are used extensively in dllmain.cpp. // 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); 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 // 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 // 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 // Function to update the detect shortcut UI based on the entered keys
void UpdateDetectShortcutUI(); void UpdateDetectShortcutUI();

View File

@@ -1,5 +1,22 @@
#include "pch.h" #include "pch.h"
#include "Shortcut.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 // Function to return the number of keys in the shortcut
int Shortcut::Size() const int Shortcut::Size() const

View File

@@ -1,9 +1,11 @@
#pragma once #pragma once
#include "Helpers.h"
#include "../common/keyboard_layout.h" class InputInterface;
#include "../common/shared_constants.h" class LayoutMap;
#include <interface/lowlevel_keyboard_event_data.h> namespace KeyboardManagerHelper
#include "InputInterface.h" {
enum class ErrorType;
}
// Enum type to store different states of the win key // Enum type to store different states of the win key
enum class ModifierKey enum class ModifierKey
@@ -31,16 +33,7 @@ public:
} }
// Constructor to initialize Shortcut from it's virtual key code string representation. // Constructor to initialize Shortcut from it's virtual key code string representation.
Shortcut(const std::wstring& shortcutVK) : 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);
}
}
// == operator // == operator
inline bool operator==(const Shortcut& sc) const inline bool operator==(const Shortcut& sc) const

View File

@@ -5,22 +5,14 @@
#include <winrt/Windows.Foundation.h> #include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Graphics.h> #include <winrt/Windows.Graphics.h>
#include <winrt/Windows.system.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.Collections.h>
#include "winrt/Windows.Foundation.Numerics.h" #include "winrt/Windows.Foundation.Numerics.h"
#include "winrt/Windows.UI.Xaml.Controls.Primitives.h" #include <winrt/windows.ui.xaml.controls.h>
#include "winrt/Windows.UI.Text.h"
#include "winrt/Windows.UI.Core.h" #include "winrt/Windows.UI.Core.h"
#include <stdlib.h> #include <stdlib.h>
#include <ProjectTelemetry.h> #include <ProjectTelemetry.h>
using namespace winrt; 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::Foundation::Numerics;
using namespace Windows::UI::Xaml; using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls; using namespace Windows::UI::Xaml::Controls;

View File

@@ -1,5 +1,8 @@
#include "pch.h" #include "pch.h"
#include "KeyboardEventHandlers.h" #include "KeyboardEventHandlers.h"
#include "../common/shared_constants.h"
#include <keyboardmanager/common/KeyboardManagerState.h>
#include <keyboardmanager/common/InputInterface.h>
namespace KeyboardEventHandlers namespace KeyboardEventHandlers
{ {

View File

@@ -1,7 +1,13 @@
#pragma once #pragma once
#include <keyboardmanager/common/KeyboardManagerState.h> #include <interface/lowlevel_keyboard_event_data.h>
#include <keyboardmanager/common/KeyboardManagerConstants.h> #include <map>
#include <keyboardmanager/common/InputInterface.h> #include <mutex>
#include "keyboardmanager/common/KeyboardManagerConstants.h"
class InputInterface;
class KeyboardManagerState;
class Shortcut;
class RemapShortcut;
namespace KeyboardEventHandlers namespace KeyboardEventHandlers
{ {

View File

@@ -108,6 +108,8 @@
<ClCompile> <ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader> <PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">/MP %(AdditionalOptions)</AdditionalOptions>
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">/MP %(AdditionalOptions)</AdditionalOptions>
</ClCompile> </ClCompile>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>

View File

@@ -1,7 +1,6 @@
#pragma once #pragma once
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <windows.h> #include <windows.h>
#include <common/common.h>
#include <ProjectTelemetry.h> #include <ProjectTelemetry.h>
#include <shlwapi.h> #include <shlwapi.h>
#include <stdexcept> #include <stdexcept>

View File

@@ -99,6 +99,8 @@
<ClCompile> <ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader> <PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">/MP %(AdditionalOptions)</AdditionalOptions>
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">/MP %(AdditionalOptions)</AdditionalOptions>
</ClCompile> </ClCompile>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>

View File

@@ -4,6 +4,7 @@
#include <keyboardmanager/common/KeyboardManagerState.h> #include <keyboardmanager/common/KeyboardManagerState.h>
#include <keyboardmanager/dll/KeyboardEventHandlers.h> #include <keyboardmanager/dll/KeyboardEventHandlers.h>
#include "TestHelpers.h" #include "TestHelpers.h"
#include "../common/shared_constants.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace Microsoft::VisualStudio::CppUnitTestFramework;

View File

@@ -4,6 +4,7 @@
#include <keyboardmanager/common/KeyboardManagerState.h> #include <keyboardmanager/common/KeyboardManagerState.h>
#include <keyboardmanager/dll/KeyboardEventHandlers.h> #include <keyboardmanager/dll/KeyboardEventHandlers.h>
#include "TestHelpers.h" #include "TestHelpers.h"
#include "../common/shared_constants.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework; using namespace Microsoft::VisualStudio::CppUnitTestFramework;

View File

@@ -1,5 +1,7 @@
#include "pch.h" #include "pch.h"
#include "TestHelpers.h" #include "TestHelpers.h"
#include "MockedInput.h"
#include "keyboardmanager/common/KeyboardManagerState.h"
namespace TestHelpers namespace TestHelpers
{ {

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include "MockedInput.h" class MockedInput;
#include <keyboardmanager/common/KeyboardManagerState.h> class KeyboardManagerState;
namespace TestHelpers namespace TestHelpers
{ {

View File

@@ -1,2 +1,8 @@
#pragma once #pragma once
#pragma comment(lib, "shlwapi.lib") #pragma comment(lib, "shlwapi.lib")
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <ProjectTelemetry.h>
#include <shlwapi.h>
#include <stdexcept>
#include <unordered_set>

View File

@@ -1,6 +1,8 @@
#include "pch.h" #include "pch.h"
#include "Dialog.h" #include "Dialog.h"
using namespace winrt::Windows::Foundation;
IAsyncOperation<bool> Dialog::PartialRemappingConfirmationDialog(XamlRoot root, std::wstring dialogTitle) IAsyncOperation<bool> Dialog::PartialRemappingConfirmationDialog(XamlRoot root, std::wstring dialogTitle)
{ {
ContentDialog confirmationDialog; ContentDialog confirmationDialog;

View File

@@ -3,9 +3,19 @@
#include <functional> #include <functional>
#include <keyboardmanager/common/Helpers.h> #include <keyboardmanager/common/Helpers.h>
#include <set> #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 namespace Dialog
{ {
@@ -37,5 +47,5 @@ namespace Dialog
return isSuccess; 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);
}; };

View File

@@ -11,6 +11,8 @@
#include "Styles.h" #include "Styles.h"
#include "Dialog.h" #include "Dialog.h"
#include <keyboardmanager/dll/resource.h> #include <keyboardmanager/dll/resource.h>
#include "../common/shared_constants.h"
#include "keyboardmanager/common/KeyboardManagerState.h"
using namespace winrt::Windows::Foundation; using namespace winrt::Windows::Foundation;
@@ -397,7 +399,7 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan
// Add remap key button // Add remap key button
Windows::UI::Xaml::Controls::Button addRemapKey; Windows::UI::Xaml::Controls::Button addRemapKey;
FontIcon plusSymbol; FontIcon plusSymbol;
plusSymbol.FontFamily(Xaml::Media::FontFamily(L"Segoe MDL2 Assets")); plusSymbol.FontFamily(Media::FontFamily(L"Segoe MDL2 Assets"));
plusSymbol.Glyph(L"\xE109"); plusSymbol.Glyph(L"\xE109");
addRemapKey.Content(plusSymbol); addRemapKey.Content(plusSymbol);
addRemapKey.Margin({ 10, 0, 0, 25 }); addRemapKey.Margin({ 10, 0, 0, 25 });

View File

@@ -1,5 +1,5 @@
#pragma once #pragma once
#include <keyboardmanager/common/KeyboardManagerState.h> class KeyboardManagerState;
// Function to create the Edit Keyboard Window // Function to create the Edit Keyboard Window
void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardManagerState); void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardManagerState);

View File

@@ -10,6 +10,7 @@
#include "Styles.h" #include "Styles.h"
#include "Dialog.h" #include "Dialog.h"
#include <keyboardmanager/dll/resource.h> #include <keyboardmanager/dll/resource.h>
#include <keyboardmanager/common/KeyboardManagerState.h>
using namespace winrt::Windows::Foundation; using namespace winrt::Windows::Foundation;

View File

@@ -1,7 +1,5 @@
#pragma once #pragma once
#include "keyboardmanager/common/KeyboardManagerState.h" class KeyboardManagerState;
#include "keyboardmanager/common/Shortcut.h"
#include "keyboardmanager/common/Helpers.h"
// Function to create the Edit Shortcuts Window // Function to create the Edit Shortcuts Window
void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardManagerState); void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardManagerState);

View File

@@ -1,6 +1,7 @@
#include "pch.h" #include "pch.h"
#include "KeyDropDownControl.h" #include "KeyDropDownControl.h"
#include "keyboardmanager/common/Helpers.h" #include "keyboardmanager/common/Helpers.h"
#include <keyboardmanager/common/KeyboardManagerState.h>
// Initialized to null // Initialized to null
KeyboardManagerState* KeyDropDownControl::keyboardManagerState = nullptr; KeyboardManagerState* KeyDropDownControl::keyboardManagerState = nullptr;
@@ -8,28 +9,32 @@ KeyboardManagerState* KeyDropDownControl::keyboardManagerState = nullptr;
// Function to set properties apart from the SelectionChanged event handler // Function to set properties apart from the SelectionChanged event handler
void KeyDropDownControl::SetDefaultProperties(bool isShortcut) void KeyDropDownControl::SetDefaultProperties(bool isShortcut)
{ {
dropDown = ComboBox();
warningFlyout = Flyout();
warningMessage = TextBlock();
if (!isShortcut) if (!isShortcut)
{ {
dropDown.Width(KeyboardManagerConstants::RemapTableDropDownWidth); dropDown.as<ComboBox>().Width(KeyboardManagerConstants::RemapTableDropDownWidth);
} }
else else
{ {
dropDown.Width(KeyboardManagerConstants::ShortcutTableDropDownWidth); dropDown.as<ComboBox>().Width(KeyboardManagerConstants::ShortcutTableDropDownWidth);
} }
dropDown.MaxDropDownHeight(KeyboardManagerConstants::TableDropDownHeight); dropDown.as<ComboBox>().MaxDropDownHeight(KeyboardManagerConstants::TableDropDownHeight);
// Initialise layout attribute // Initialise layout attribute
previousLayout = GetKeyboardLayout(0); previousLayout = GetKeyboardLayout(0);
keyCodeList = keyboardManagerState->keyboardMap.GetKeyCodeList(isShortcut); 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 // 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>(); ComboBox currentDropDown = sender.as<ComboBox>();
CheckAndUpdateKeyboardLayout(currentDropDown, isShortcut); CheckAndUpdateKeyboardLayout(currentDropDown, isShortcut);
}); });
// Attach flyout to the drop down // Attach flyout to the drop down
warningFlyout.Content(warningMessage); warningFlyout.as<Flyout>().Content(warningMessage.as<TextBlock>());
dropDown.ContextFlyout().SetAttachedFlyout((FrameworkElement)dropDown, warningFlyout); 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 // 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 // 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 // drop down selection handler
auto onSelectionChange = [&, table, singleKeyControl, colIndex](winrt::Windows::Foundation::IInspectable const& sender) { 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 // 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); 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 // 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>(); ComboBox currentDropDown = sender.as<ComboBox>();
if (!currentDropDown.IsDropDownOpen()) 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) 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(); int selectedKeyIndex = currentDropDown.SelectedIndex();
uint32_t dropDownIndex = -1; uint32_t dropDownIndex = -1;
bool dropDownFound = parent.Children().IndexOf(currentDropDown, dropDownIndex); 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 // 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) { 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); 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 // 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); 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 // 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>(); ComboBox currentDropDown = sender.as<ComboBox>();
if (!currentDropDown.IsDropDownOpen()) if (!currentDropDown.IsDropDownOpen())
{ {
@@ -374,13 +379,13 @@ void KeyDropDownControl::SetSelectionHandler(Grid& table, StackPanel& shortcutCo
// Function to set the selected index of the drop down // Function to set the selected index of the drop down
void KeyDropDownControl::SetSelectedIndex(int32_t index) 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 // Function to return the combo box element of the drop down
ComboBox KeyDropDownControl::GetComboBox() ComboBox KeyDropDownControl::GetComboBox()
{ {
return dropDown; return dropDown.as<ComboBox>();
} }
// Function to add a drop down to the shortcut stack panel // 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) void KeyDropDownControl::SetDropDownError(ComboBox currentDropDown, hstring message)
{ {
currentDropDown.SelectedIndex(-1); currentDropDown.SelectedIndex(-1);
warningMessage.Text(message); warningMessage.as<TextBlock>().Text(message);
currentDropDown.ContextFlyout().ShowAttachedFlyout((FrameworkElement)dropDown); currentDropDown.ContextFlyout().ShowAttachedFlyout((FrameworkElement)dropDown.as<ComboBox>());
} }

View File

@@ -1,20 +1,43 @@
#pragma once #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 // Wrapper class for the key drop down menu
class KeyDropDownControl class KeyDropDownControl
{ {
private: private:
// Stores the drop down combo box // Stores the drop down combo box
ComboBox dropDown; winrt::Windows::Foundation::IInspectable dropDown;
// Stores the previous layout // Stores the previous layout
HKL previousLayout = 0; HKL previousLayout = 0;
// Stores the key code list // Stores the key code list
std::vector<DWORD> keyCodeList; std::vector<DWORD> keyCodeList;
// Stores the flyout warning message // Stores the flyout warning message
TextBlock warningMessage; winrt::Windows::Foundation::IInspectable warningMessage;
// Stores the flyout attached to the current drop down // 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 // Function to set properties apart from the SelectionChanged event handler
void SetDefaultProperties(bool isShortcut); 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 // 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 // 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 // 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 // Function to set the selected index of the drop down
void SetSelectedIndex(int32_t index); void SetSelectedIndex(int32_t index);
@@ -48,17 +71,17 @@ public:
ComboBox GetComboBox(); ComboBox GetComboBox();
// Function to add a drop down to the shortcut stack panel // 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 // Function to get the list of key codes from the shortcut combo box stack panel
static std::vector<DWORD> GetKeysFromStackPanel(StackPanel parent); static std::vector<DWORD> GetKeysFromStackPanel(StackPanel parent);
// Function to check if a modifier has been repeated in the previous drop downs // 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 // 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); 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 // Function to set the warning message
void SetDropDownError(ComboBox currentDropDown, hstring message); void SetDropDownError(winrt::Windows::UI::Xaml::Controls::ComboBox currentDropDown, winrt::hstring message);
}; };

View File

@@ -105,6 +105,8 @@
<ClCompile> <ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader> <PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile> <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">/MP %(AdditionalOptions)</AdditionalOptions>
<AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Release|x64'">/MP %(AdditionalOptions)</AdditionalOptions>
</ClCompile> </ClCompile>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>

View File

@@ -1,6 +1,7 @@
#include "pch.h" #include "pch.h"
#include "ShortcutControl.h" #include "ShortcutControl.h"
#include "KeyDropDownControl.h" #include "KeyDropDownControl.h"
#include "keyboardmanager/common/KeyboardManagerState.h"
//Both static members are initialized to null //Both static members are initialized to null
HWND ShortcutControl::EditShortcutsWindowHandle = nullptr; HWND ShortcutControl::EditShortcutsWindowHandle = nullptr;
@@ -8,6 +9,32 @@ KeyboardManagerState* ShortcutControl::keyboardManagerState = nullptr;
// Initialized as new vector // Initialized as new vector
std::vector<std::pair<std::vector<Shortcut>, std::wstring>> ShortcutControl::shortcutRemapBuffer; 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. // 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) 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; int rowIndex = (lastIndexInRow - KeyboardManagerConstants::ShortcutTableHeaderCount) / KeyboardManagerConstants::ShortcutTableColCount;
// Validate both set of drop downs // 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][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, 1, ShortcutControl::shortcutRemapBuffer, keyboardRemapControlObjects[rowIndex][1]->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 // Reset the buffer based on the selected drop down items
shortcutRemapBuffer[rowIndex].first[0].SetKeyCodes(KeyDropDownControl::GetKeysFromStackPanel(keyboardRemapControlObjects[rowIndex][0]->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)); shortcutRemapBuffer[rowIndex].first[1].SetKeyCodes(KeyDropDownControl::GetKeysFromStackPanel(keyboardRemapControlObjects[rowIndex][1]->shortcutDropDownStackPanel.as<StackPanel>()));
std::wstring newText = targetAppTextBox.Text().c_str(); std::wstring newText = targetAppTextBox.Text().c_str();
std::wstring lowercaseDefAppName = KeyboardManagerConstants::DefaultAppName; std::wstring lowercaseDefAppName = KeyboardManagerConstants::DefaultAppName;
std::transform(newText.begin(), newText.end(), newText.begin(), towlower); 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 // change to load app name
shortcutRemapBuffer.push_back(std::make_pair<std::vector<Shortcut>, std::wstring>(std::vector<Shortcut>{ Shortcut(), Shortcut() }, std::wstring(targetAppName))); 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][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, *keyboardManagerState, 1, targetAppTextBox); keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][1]->AddShortcutToControl(newKeys, parent, keyboardRemapControlObjects[keyboardRemapControlObjects.size() - 1][1]->shortcutDropDownStackPanel.as<StackPanel>(), *keyboardManagerState, 1, targetAppTextBox);
} }
else else
{ {
@@ -152,7 +179,7 @@ void ShortcutControl::AddShortcutToControl(Shortcut& shortcut, Grid table, Stack
std::vector<DWORD> keyCodeList = keyboardManagerState.keyboardMap.GetKeyCodeList(true); std::vector<DWORD> keyCodeList = keyboardManagerState.keyboardMap.GetKeyCodeList(true);
if (shortcutKeyCodes.size() != 0) 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++) for (int i = 0; i < shortcutKeyCodes.size(); i++)
{ {
// New drop down gets added automatically when the SelectedIndex is set // 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 // 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() StackPanel ShortcutControl::getShortcutControl()
{ {
return shortcutControlLayout; return shortcutControlLayout.as<StackPanel>();
} }
// Function to create the detect shortcut UI window // Function to create the detect shortcut UI window

View File

@@ -1,20 +1,30 @@
#pragma once #pragma once
#include <keyboardmanager/common/KeyboardManagerState.h> #include "keyboardmanager/common/Shortcut.h"
#include <keyboardManager/common/Helpers.h>
#include <keyboardmanager/common/Shortcut.h> class KeyboardManagerState;
#include "KeyDropDownControl.h" class KeyDropDownControl;
namespace winrt::Windows::UI::Xaml
{
struct XamlRoot;
namespace Controls
{
struct StackPanel;
struct Grid;
struct TextBox;
}
}
class ShortcutControl class ShortcutControl
{ {
private: private:
// Stack panel for the drop downs to display the selected shortcut // Stack panel for the drop downs to display the selected shortcut
StackPanel shortcutDropDownStackPanel; winrt::Windows::Foundation::IInspectable shortcutDropDownStackPanel;
// Button to type the shortcut // Button to type the shortcut
Button typeShortcut; winrt::Windows::Foundation::IInspectable typeShortcut;
// StackPanel to parent the above controls // StackPanel to parent the above controls
StackPanel shortcutControlLayout; winrt::Windows::Foundation::IInspectable shortcutControlLayout;
public: public:
// Handle to the current Edit Shortcuts Window // Handle to the current Edit Shortcuts Window
@@ -26,27 +36,8 @@ public:
// Vector to store dynamically allocated KeyDropDownControl objects to avoid early destruction // Vector to store dynamically allocated KeyDropDownControl objects to avoid early destruction
std::vector<std::unique_ptr<KeyDropDownControl>> keyDropDownControlObjects; std::vector<std::unique_ptr<KeyDropDownControl>> keyDropDownControlObjects;
ShortcutControl(Grid table, const int colIndex, TextBox targetApp) // constructor
{ 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();
}
// 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. // 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""); static void AddNewShortcutControlRow(Grid& parent, std::vector<std::vector<std::unique_ptr<ShortcutControl>>>& keyboardRemapControlObjects, Shortcut originalKeys = Shortcut(), Shortcut newKeys = Shortcut(), std::wstring targetAppName = L"");

View File

@@ -1,6 +1,9 @@
#include "pch.h" #include "pch.h"
#include "SingleKeyRemapControl.h" #include "SingleKeyRemapControl.h"
#include "keyboardmanager/common/Helpers.h" #include "keyboardmanager/common/Helpers.h"
#include "keyboardmanager/common/KeyboardManagerConstants.h"
#include "keyboardmanager/common/KeyboardManagerState.h"
//Both static members are initialized to null //Both static members are initialized to null
HWND SingleKeyRemapControl::EditKeyboardWindowHandle = nullptr; HWND SingleKeyRemapControl::EditKeyboardWindowHandle = nullptr;
@@ -8,6 +11,29 @@ KeyboardManagerState* SingleKeyRemapControl::keyboardManagerState = nullptr;
// Initialized as new vector // Initialized as new vector
std::vector<std::vector<DWORD>> SingleKeyRemapControl::singleKeyRemapBuffer; 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. // 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) 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 // Arrow icon
FontIcon arrowIcon; FontIcon arrowIcon;
arrowIcon.FontFamily(Xaml::Media::FontFamily(L"Segoe MDL2 Assets")); arrowIcon.FontFamily(Media::FontFamily(L"Segoe MDL2 Assets"));
arrowIcon.Glyph(L"\xE72A"); arrowIcon.Glyph(L"\xE72A");
arrowIcon.VerticalAlignment(VerticalAlignment::Center); arrowIcon.VerticalAlignment(VerticalAlignment::Center);
arrowIcon.HorizontalAlignment(HorizontalAlignment::Center); arrowIcon.HorizontalAlignment(HorizontalAlignment::Center);
@@ -64,7 +90,7 @@ void SingleKeyRemapControl::AddNewControlKeyRemapRow(Grid& parent, std::vector<s
// Delete row button // Delete row button
Windows::UI::Xaml::Controls::Button deleteRemapKeys; Windows::UI::Xaml::Controls::Button deleteRemapKeys;
FontIcon deleteSymbol; FontIcon deleteSymbol;
deleteSymbol.FontFamily(Xaml::Media::FontFamily(L"Segoe MDL2 Assets")); deleteSymbol.FontFamily(Media::FontFamily(L"Segoe MDL2 Assets"));
deleteSymbol.Glyph(L"\xE74D"); deleteSymbol.Glyph(L"\xE74D");
deleteRemapKeys.Content(deleteSymbol); deleteRemapKeys.Content(deleteSymbol);
deleteRemapKeys.Background(Media::SolidColorBrush(Colors::Transparent())); 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 // 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() StackPanel SingleKeyRemapControl::getSingleKeyRemapControl()
{ {
return singleKeyRemapControlLayout; return singleKeyRemapControlLayout.as<StackPanel>();
} }
// Function to create the detect remap key UI window // Function to create the detect remap key UI window

View File

@@ -1,7 +1,17 @@
#pragma once #pragma once
#include <keyboardmanager/common/KeyboardManagerState.h>
#include "KeyDropDownControl.h" #include "KeyDropDownControl.h"
class KeyboardManagerState;
namespace winrt::Windows::UI::Xaml
{
struct XamlRoot;
namespace Controls
{
struct StackPanel;
struct Grid;
}
}
class SingleKeyRemapControl class SingleKeyRemapControl
{ {
private: private:
@@ -9,10 +19,10 @@ private:
KeyDropDownControl singleKeyRemapDropDown; KeyDropDownControl singleKeyRemapDropDown;
// Button to type the remap key // Button to type the remap key
Button typeKey; winrt::Windows::Foundation::IInspectable typeKey;
// StackPanel to parent the above controls // StackPanel to parent the above controls
StackPanel singleKeyRemapControlLayout; winrt::Windows::Foundation::IInspectable singleKeyRemapControlLayout;
public: public:
// Handle to the current Edit Keyboard Window // Handle to the current Edit Keyboard Window
@@ -22,32 +32,14 @@ public:
// Stores the current list of remappings // Stores the current list of remappings
static std::vector<std::vector<DWORD>> singleKeyRemapBuffer; static std::vector<std::vector<DWORD>> singleKeyRemapBuffer;
SingleKeyRemapControl(Grid table, const int colIndex) : // constructor
singleKeyRemapDropDown(false) SingleKeyRemapControl(Grid table, const int colIndex);
{
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();
}
// 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. // 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 // 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 // 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); void createDetectKeyWindow(winrt::Windows::Foundation::IInspectable const& sender, XamlRoot xamlRoot, std::vector<std::vector<DWORD>>& singleKeyRemapBuffer, KeyboardManagerState& keyboardManagerState);

View File

@@ -1,7 +1,5 @@
#include "pch.h" #include "pch.h"
#include "Styles.h" #include "Styles.h"
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.UI.Xaml.Interop.h>
#include <common/windows_colors.h> #include <common/windows_colors.h>
Style AccentButtonStyle() Style AccentButtonStyle()

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include <winrt/Windows.UI.Xaml.h> namespace winrt::Windows::UI::Xaml
{
struct Style;
}
using namespace winrt::Windows::UI::Xaml; winrt::Windows::UI::Xaml::Style AccentButtonStyle();
Style AccentButtonStyle();

View File

@@ -1,6 +1,6 @@
#include "pch.h" #include "pch.h"
#include "XamlBridge.h" #include "XamlBridge.h"
#include <windowsx.h>
bool XamlBridge::FilterMessage(const MSG* msg) bool XamlBridge::FilterMessage(const MSG* msg)
{ {

View File

@@ -1,12 +1,5 @@
#pragma once #pragma once
#include <unknwn.h> // To enable support for non-WinRT interfaces, unknwn.h must be included before any C++/WinRT headers. #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 // This class is used for handling XAML Island operations
class XamlBridge class XamlBridge

View File

@@ -16,6 +16,8 @@
#include "winrt/Windows.UI.Xaml.Controls.Primitives.h" #include "winrt/Windows.UI.Xaml.Controls.Primitives.h"
#include "winrt/Windows.UI.Text.h" #include "winrt/Windows.UI.Text.h"
#include "winrt/Windows.UI.Core.h" #include "winrt/Windows.UI.Core.h"
#include <winrt/Windows.UI.Xaml.Interop.h>
#include <mutex>
using namespace winrt; using namespace winrt;
using namespace Windows::UI; using namespace Windows::UI;