Integrate keyboard manager with settings v2[Part-2] (#2107)

* Added CustomAction Data Models

* Updated data model

* Updated Button command trigger for keyboard manager

* Integerated custom actions in Keyboard manager module backend

* Allow Runner to launch windows on foreground

* Refactor and moved the execution logic to background thread

* Removed non-required unlock calls

* Fixed typo

* Resolve PR comments
This commit is contained in:
udit3333
2020-04-14 09:24:11 -07:00
committed by GitHub
parent 79fcd45d5f
commit a88d66b48b
13 changed files with 292 additions and 40 deletions

View File

@@ -8,6 +8,9 @@ LRESULT CALLBACK EditShortcutsWindowProc(HWND, UINT, WPARAM, LPARAM);
HWND hWndXamlIslandEditShortcutsWindow = nullptr;
// This variable is used to check if window registration has been done to avoid repeated registration leading to an error.
bool isEditShortcutsWindowRegistrationCompleted = false;
// Holds the native window handle of EditShortcuts Window.
HWND hwndEditShortcutsNativeWindow = nullptr;
std::mutex editShortcutsWindowMutex;
// Function to create the Edit Shortcuts Window
void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardManagerState)
@@ -52,6 +55,11 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa
return;
}
// Store the newly created Edit Shortcuts window's handle.
std::unique_lock<std::mutex> hwndLock(editShortcutsWindowMutex);
hwndEditShortcutsNativeWindow = _hWndEditShortcutsWindow;
hwndLock.unlock();
// This DesktopWindowXamlSource is the object that enables a non-UWP desktop application
// to host UWP controls in any UI element that is associated with a window handle (HWND).
DesktopWindowXamlSource desktopSource;
@@ -213,6 +221,10 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa
DispatchMessage(&msg);
}
desktopSource.Close();
hWndXamlIslandEditShortcutsWindow = nullptr;
hwndLock.lock();
hwndEditShortcutsNativeWindow = nullptr;
}
LRESULT CALLBACK EditShortcutsWindowProc(HWND hWnd, UINT messageCode, WPARAM wParam, LPARAM lParam)
@@ -234,3 +246,23 @@ LRESULT CALLBACK EditShortcutsWindowProc(HWND hWnd, UINT messageCode, WPARAM wPa
return 0;
}
bool CheckEditShortcutsWindowActive()
{
bool result = false;
std::unique_lock<std::mutex> hwndLock(editShortcutsWindowMutex);
if (hwndEditShortcutsNativeWindow != nullptr)
{
// Check if the window is minimized if yes then restore the window.
if (IsIconic(hwndEditShortcutsNativeWindow))
{
ShowWindow(hwndEditShortcutsNativeWindow, SW_RESTORE);
}
// If there is an already existing window no need to create a new open bring it on foreground.
SetForegroundWindow(hwndEditShortcutsNativeWindow);
result = true;
}
return result;
}