diff --git a/src/modules/keyboardmanager/common/KeyboardManagerConstants.h b/src/modules/keyboardmanager/common/KeyboardManagerConstants.h index 0d65519111..261d74ae4f 100644 --- a/src/modules/keyboardmanager/common/KeyboardManagerConstants.h +++ b/src/modules/keyboardmanager/common/KeyboardManagerConstants.h @@ -56,7 +56,7 @@ namespace KeyboardManagerConstants inline const long RemapTableArrowColIndex = 1; inline const long RemapTableNewColIndex = 2; inline const long RemapTableRemoveColIndex = 3; - inline const long RemapTableDropDownWidth = 110; + inline const DWORD RemapTableDropDownWidth = 110; // Shortcut table constants inline const long ShortcutTableColCount = 4; @@ -65,14 +65,14 @@ namespace KeyboardManagerConstants inline const long ShortcutTableArrowColIndex = 1; inline const long ShortcutTableNewColIndex = 2; inline const long ShortcutTableRemoveColIndex = 3; - inline const long ShortcutTableDropDownWidth = 110; - inline const long ShortcutTableDropDownSpacing = 10; + inline const DWORD ShortcutTableDropDownWidth = 110; + inline const DWORD ShortcutTableDropDownSpacing = 10; // Drop down height used for both Edit Keyboard and Edit Shortcuts - inline const long TableDropDownHeight = 200; - inline const long TableArrowColWidth = 20; - inline const long TableRemoveColWidth = 20; - inline const long TableWarningColWidth = 20; + inline const DWORD TableDropDownHeight = 200; + inline const DWORD TableArrowColWidth = 20; + inline const DWORD TableRemoveColWidth = 20; + inline const DWORD TableWarningColWidth = 20; // Shared style constants for both Remap Table and Shortcut Table inline const double HeaderButtonWidth = 100; diff --git a/src/modules/keyboardmanager/dll/dllmain.cpp b/src/modules/keyboardmanager/dll/dllmain.cpp index 06d0545969..4089ca7c69 100644 --- a/src/modules/keyboardmanager/dll/dllmain.cpp +++ b/src/modules/keyboardmanager/dll/dllmain.cpp @@ -279,6 +279,9 @@ public: m_enabled = false; // Log telemetry Trace::EnableKeyboardManager(false); + // Close active windows + CloseActiveEditKeyboardWindow(); + CloseActiveEditShortcutsWindow(); // Stop keyboard hook stop_lowlevel_keyboard_hook(); } diff --git a/src/modules/keyboardmanager/ui/EditKeyboardWindow.cpp b/src/modules/keyboardmanager/ui/EditKeyboardWindow.cpp index 9c86cf35d8..80664f7edc 100644 --- a/src/modules/keyboardmanager/ui/EditKeyboardWindow.cpp +++ b/src/modules/keyboardmanager/ui/EditKeyboardWindow.cpp @@ -147,12 +147,12 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan windowClass.hInstance = hInst; windowClass.lpszClassName = szWindowClass; windowClass.hbrBackground = (HBRUSH)(COLOR_WINDOW); - windowClass.hIcon = (HICON) LoadImageW( - windowClass.hInstance, - MAKEINTRESOURCE(IDS_KEYBOARDMANAGER_ICON), - IMAGE_ICON, - 48, - 48, + windowClass.hIcon = (HICON)LoadImageW( + windowClass.hInstance, + MAKEINTRESOURCE(IDS_KEYBOARDMANAGER_ICON), + IMAGE_ICON, + 48, + 48, LR_DEFAULTCOLOR); if (RegisterClassEx(&windowClass) == NULL) { @@ -175,7 +175,7 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan HWND _hWndEditKeyboardWindow = CreateWindow( szWindowClass, L"Remap Keyboard", - WS_OVERLAPPEDWINDOW | WS_VISIBLE, + WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MAXIMIZEBOX, (desktopRect.right / 2) - (windowWidth / 2), (desktopRect.bottom / 2) - (windowHeight / 2), windowWidth, @@ -493,3 +493,13 @@ bool CheckEditKeyboardWindowActive() return result; } + +// Function to close any active Edit Keyboard window +void CloseActiveEditKeyboardWindow() +{ + std::unique_lock hwndLock(editKeyboardWindowMutex); + if (hwndEditKeyboardNativeWindow != nullptr) + { + PostMessage(hwndEditKeyboardNativeWindow, WM_CLOSE, 0, 0); + } +} diff --git a/src/modules/keyboardmanager/ui/EditKeyboardWindow.h b/src/modules/keyboardmanager/ui/EditKeyboardWindow.h index 090c6c49b8..08533244d6 100644 --- a/src/modules/keyboardmanager/ui/EditKeyboardWindow.h +++ b/src/modules/keyboardmanager/ui/EditKeyboardWindow.h @@ -5,4 +5,7 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardManagerState); // Function to check if there is already a window active if yes bring to foreground -bool CheckEditKeyboardWindowActive(); \ No newline at end of file +bool CheckEditKeyboardWindowActive(); + +// Function to close any active Edit Keyboard window +void CloseActiveEditKeyboardWindow(); \ No newline at end of file diff --git a/src/modules/keyboardmanager/ui/EditShortcutsWindow.cpp b/src/modules/keyboardmanager/ui/EditShortcutsWindow.cpp index 5e0b4f3ce6..57695764f6 100644 --- a/src/modules/keyboardmanager/ui/EditShortcutsWindow.cpp +++ b/src/modules/keyboardmanager/ui/EditShortcutsWindow.cpp @@ -61,10 +61,10 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa windowClass.hbrBackground = (HBRUSH)(COLOR_WINDOW); windowClass.hIcon = (HICON)LoadImageW( windowClass.hInstance, - MAKEINTRESOURCE(IDS_KEYBOARDMANAGER_ICON), - IMAGE_ICON, - 48, - 48, + MAKEINTRESOURCE(IDS_KEYBOARDMANAGER_ICON), + IMAGE_ICON, + 48, + 48, LR_DEFAULTCOLOR); if (RegisterClassEx(&windowClass) == NULL) { @@ -87,7 +87,7 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa HWND _hWndEditShortcutsWindow = CreateWindow( szWindowClass, L"Remap Shortcuts", - WS_OVERLAPPEDWINDOW | WS_VISIBLE, + WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MAXIMIZEBOX, (desktopRect.right / 2) - (windowWidth / 2), (desktopRect.bottom / 2) - (windowHeight / 2), windowWidth, @@ -377,3 +377,13 @@ bool CheckEditShortcutsWindowActive() return result; } + +// Function to close any active Edit Shortcuts window +void CloseActiveEditShortcutsWindow() +{ + std::unique_lock hwndLock(editShortcutsWindowMutex); + if (hwndEditShortcutsNativeWindow != nullptr) + { + PostMessage(hwndEditShortcutsNativeWindow, WM_CLOSE, 0, 0); + } +} diff --git a/src/modules/keyboardmanager/ui/EditShortcutsWindow.h b/src/modules/keyboardmanager/ui/EditShortcutsWindow.h index 3520b3fc1f..beead96101 100644 --- a/src/modules/keyboardmanager/ui/EditShortcutsWindow.h +++ b/src/modules/keyboardmanager/ui/EditShortcutsWindow.h @@ -7,4 +7,7 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardManagerState); // Function to check if there is already a window active if yes bring to foreground -bool CheckEditShortcutsWindowActive(); \ No newline at end of file +bool CheckEditShortcutsWindowActive(); + +// Function to close any active Edit Shortcuts window +void CloseActiveEditShortcutsWindow(); \ No newline at end of file