[KBM] Open Remap Shortcuts/Remap Keyboard window on the same monitor as Settings. (#8325)

This commit is contained in:
Seraphima Zykova
2020-12-10 18:28:44 +03:00
committed by GitHub
parent 709d42d3e7
commit 8a7824924a
9 changed files with 88 additions and 57 deletions

View File

@@ -118,21 +118,21 @@ void createEditKeyboardWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMan
isEditKeyboardWindowRegistrationCompleted = true;
}
// Find center screen coordinates
RECT desktopRect;
GetClientRect(GetDesktopWindow(), &desktopRect);
// Find coordinates of the screen where the settings window is placed.
RECT desktopRect = UIHelpers::GetForegroundWindowDesktopRect();
// Calculate DPI dependent window size
int windowWidth = KeyboardManagerConstants::DefaultEditKeyboardWindowWidth;
int windowHeight = KeyboardManagerConstants::DefaultEditKeyboardWindowHeight;
DPIAware::Convert(nullptr, windowWidth, windowHeight);
// Window Creation
HWND _hWndEditKeyboardWindow = CreateWindow(
szWindowClass,
GET_RESOURCE_STRING(IDS_EDITKEYBOARD_WINDOWNAME).c_str(),
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MAXIMIZEBOX,
(desktopRect.right / 2) - (windowWidth / 2),
(desktopRect.bottom / 2) - (windowHeight / 2),
((desktopRect.right + desktopRect.left) / 2) - (windowWidth / 2),
((desktopRect.bottom + desktopRect.top) / 2) - (windowHeight / 2),
windowWidth,
windowHeight,
NULL,

View File

@@ -77,9 +77,9 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa
isEditShortcutsWindowRegistrationCompleted = true;
}
// Find center screen coordinates
RECT desktopRect;
GetClientRect(GetDesktopWindow(), &desktopRect);
// Find coordinates of the screen where the settings window is placed.
RECT desktopRect = UIHelpers::GetForegroundWindowDesktopRect();
// Calculate DPI dependent window size
int windowWidth = KeyboardManagerConstants::DefaultEditShortcutsWindowWidth;
int windowHeight = KeyboardManagerConstants::DefaultEditShortcutsWindowHeight;
@@ -90,8 +90,8 @@ void createEditShortcutsWindow(HINSTANCE hInst, KeyboardManagerState& keyboardMa
szWindowClass,
GET_RESOURCE_STRING(IDS_EDITSHORTCUTS_WINDOWNAME).c_str(),
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MAXIMIZEBOX,
(desktopRect.right / 2) - (windowWidth / 2),
(desktopRect.bottom / 2) - (windowHeight / 2),
((desktopRect.right + desktopRect.left) / 2) - (windowWidth / 2),
((desktopRect.bottom + desktopRect.top) / 2) - (windowHeight / 2),
windowWidth,
windowHeight,
NULL,

View File

@@ -1,6 +1,8 @@
#include "pch.h"
#include "UIHelpers.h"
#include <common/monitor_utils.h>
namespace UIHelpers
{
// This method sets focus to the first Type button on the last row of the Grid
@@ -15,4 +17,22 @@ namespace UIHelpers
// Set programmatic focus on the button
firstTypeButtonInLastRow.Focus(FocusState::Programmatic);
}
RECT GetForegroundWindowDesktopRect()
{
HWND window = GetForegroundWindow();
HMONITOR settingsMonitor = MonitorFromWindow(window, MONITOR_DEFAULTTONULL);
RECT desktopRect{};
auto monitors = GetAllMonitorRects<&MONITORINFOEX::rcWork>();
for (const auto& monitor : monitors)
{
if (settingsMonitor == monitor.first)
{
desktopRect = monitor.second;
break;
}
}
return desktopRect;
}
}

View File

@@ -5,4 +5,6 @@ namespace UIHelpers
{
// This method sets focus to the first Type button on the last row of the Grid
void SetFocusOnTypeButtonInLastRow(StackPanel& parent, long colCount);
RECT GetForegroundWindowDesktopRect();
}