[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
#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
{

View File

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

View File

@@ -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

View File

@@ -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>

View File

@@ -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();
});
}

View File

@@ -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();

View File

@@ -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

View File

@@ -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

View File

@@ -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;