mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 11:17:53 +01:00
[KBM] scale editor window size based on DPI (#11006)
This commit is contained in:
@@ -51,6 +51,19 @@ namespace DPIAware
|
||||
}
|
||||
}
|
||||
|
||||
void ConvertByCursorPosition(int& width, int& height)
|
||||
{
|
||||
HMONITOR targetMonitor = nullptr;
|
||||
POINT currentCursorPos{};
|
||||
|
||||
if (GetCursorPos(¤tCursorPos))
|
||||
{
|
||||
targetMonitor = MonitorFromPoint(currentCursorPos, MONITOR_DEFAULTTOPRIMARY);
|
||||
}
|
||||
|
||||
Convert(targetMonitor, width, height);
|
||||
}
|
||||
|
||||
void InverseConvert(HMONITOR monitor_handle, int& width, int& height)
|
||||
{
|
||||
if (monitor_handle == NULL)
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace DPIAware
|
||||
HRESULT GetScreenDPIForWindow(HWND hwnd, UINT& dpi_x, UINT& dpi_y);
|
||||
HRESULT GetScreenDPIForPoint(POINT p, UINT& dpi_x, UINT& dpi_y);
|
||||
void Convert(HMONITOR monitor_handle, int& width, int& height);
|
||||
void ConvertByCursorPosition(int& width, int& height);
|
||||
void InverseConvert(HMONITOR monitor_handle, int& width, int& height);
|
||||
void EnableDPIAwarenessForThisProcess();
|
||||
|
||||
|
||||
@@ -142,7 +142,8 @@ inline void CreateEditKeyboardWindowImpl(HINSTANCE hInst, KeyboardManagerState&
|
||||
// Calculate DPI dependent window size
|
||||
int windowWidth = KeyboardManagerConstants::DefaultEditKeyboardWindowWidth;
|
||||
int windowHeight = KeyboardManagerConstants::DefaultEditKeyboardWindowHeight;
|
||||
DPIAware::Convert(nullptr, windowWidth, windowHeight);
|
||||
|
||||
DPIAware::ConvertByCursorPosition(windowWidth, windowHeight);
|
||||
|
||||
// Window Creation
|
||||
HWND _hWndEditKeyboardWindow = CreateWindow(
|
||||
@@ -422,7 +423,7 @@ LRESULT CALLBACK EditKeyboardWindowProc(HWND hWnd, UINT messageCode, WPARAM wPar
|
||||
LPMINMAXINFO lpMMI = (LPMINMAXINFO)lParam;
|
||||
int minWidth = KeyboardManagerConstants::MinimumEditKeyboardWindowWidth;
|
||||
int minHeight = KeyboardManagerConstants::MinimumEditKeyboardWindowHeight;
|
||||
DPIAware::Convert(nullptr, minWidth, minHeight);
|
||||
DPIAware::Convert(MonitorFromWindow(hWnd, MONITOR_DEFAULTTONULL), minWidth, minHeight);
|
||||
lpMMI->ptMinTrackSize.x = minWidth;
|
||||
lpMMI->ptMinTrackSize.y = minHeight;
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ inline void CreateEditShortcutsWindowImpl(HINSTANCE hInst, KeyboardManagerState&
|
||||
// Calculate DPI dependent window size
|
||||
int windowWidth = KeyboardManagerConstants::DefaultEditShortcutsWindowWidth;
|
||||
int windowHeight = KeyboardManagerConstants::DefaultEditShortcutsWindowHeight;
|
||||
DPIAware::Convert(nullptr, windowWidth, windowHeight);
|
||||
DPIAware::ConvertByCursorPosition(windowWidth, windowHeight);
|
||||
|
||||
// Window Creation
|
||||
HWND _hWndEditShortcutsWindow = CreateWindow(
|
||||
@@ -377,7 +377,7 @@ LRESULT CALLBACK EditShortcutsWindowProc(HWND hWnd, UINT messageCode, WPARAM wPa
|
||||
LPMINMAXINFO lpMMI = (LPMINMAXINFO)lParam;
|
||||
int minWidth = KeyboardManagerConstants::MinimumEditShortcutsWindowWidth;
|
||||
int minHeight = KeyboardManagerConstants::MinimumEditShortcutsWindowHeight;
|
||||
DPIAware::Convert(nullptr, minWidth, minHeight);
|
||||
DPIAware::Convert(MonitorFromWindow(hWnd, MONITOR_DEFAULTTONULL), minWidth, minHeight);
|
||||
lpMMI->ptMinTrackSize.x = minWidth;
|
||||
lpMMI->ptMinTrackSize.y = minHeight;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user