Skip to content

Commit

Permalink
Fixed window resizing when toggling HiDPI
Browse files Browse the repository at this point in the history
  • Loading branch information
Aemony committed May 5, 2024
1 parent c31f8ce commit 0e34a45
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 33 deletions.
67 changes: 35 additions & 32 deletions src/SKIF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1941,6 +1941,41 @@ wWinMain ( _In_ HINSTANCE hInstance,
SKIF_vecRegularMode ;
*/

// F6 to toggle DPI scaling
if (changedHiDPIScaling || hotkeyF6)
{
// We only change bDPIScaling if ImGui::Checkbox (settings tab) was not used,
// as otherwise it have already been changed to reflect its new value
if (! changedHiDPIScaling)
_registry.bDPIScaling = ! _registry.bDPIScaling;
_registry.regKVDPIScaling.putData (_registry.bDPIScaling);

changedHiDPIScaling = false;

// Reset reduced height
SKIF_vecAlteredSize.y = 0.0f;

// Take the current display into account
HMONITOR monitor =
::MonitorFromWindow (SKIF_ImGui_hWnd, MONITOR_DEFAULTTONEAREST);

SKIF_ImGui_GlobalDPIScale = (_registry.bDPIScaling) ? ImGui_ImplWin32_GetDpiScaleForMonitor (monitor) : 1.0f;

// Divide the window size with its associated DPI scale to get the base size, then multiply with the new DPI scale
SKIF_vecCurrentModeNext = (SKIF_vecCurrentMode / SKIF_ImGui_GlobalDPIScale_Last) * SKIF_ImGui_GlobalDPIScale;

ImGuiStyle newStyle;
SKIF_ImGui_SetStyle (&newStyle);

SKIF_ImGui_AdjustAppModeSize (monitor);

LONG_PTR lStyle = GetWindowLongPtr (SKIF_ImGui_hWnd, GWL_STYLE);
if (lStyle & WS_MAXIMIZE)
repositionToCenter = true;
else
RespectMonBoundaries = true;
}

static bool
applySizeOnLaunch = true;
if (applySizeOnLaunch)
Expand Down Expand Up @@ -2074,38 +2109,6 @@ wWinMain ( _In_ HINSTANCE hInstance,
}
*/

// F6 to toggle DPI scaling
if (changedHiDPIScaling || hotkeyF6)
{
// We only change bDPIScaling if ImGui::Checkbox (settings tab) was not used,
// as otherwise it have already been changed to reflect its new value
if (! changedHiDPIScaling)
_registry.bDPIScaling = ! _registry.bDPIScaling;
_registry.regKVDPIScaling.putData (_registry.bDPIScaling);

changedHiDPIScaling = false;

// Reset reduced height
SKIF_vecAlteredSize.y = 0.0f;

// Take the current display into account
HMONITOR monitor =
::MonitorFromWindow (SKIF_ImGui_hWnd, MONITOR_DEFAULTTONEAREST);

SKIF_ImGui_GlobalDPIScale = (_registry.bDPIScaling) ? ImGui_ImplWin32_GetDpiScaleForMonitor (monitor) : 1.0f;

ImGuiStyle newStyle;
SKIF_ImGui_SetStyle (&newStyle);

SKIF_ImGui_AdjustAppModeSize (monitor);

LONG_PTR lStyle = GetWindowLongPtr (SKIF_ImGui_hWnd, GWL_STYLE);
if (lStyle & WS_MAXIMIZE)
repositionToCenter = true;
else
RespectMonBoundaries = true;
}

// F8 to toggle UI borders
if (hotkeyF8)
{
Expand Down
2 changes: 1 addition & 1 deletion src/utility/skif_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ SKIF_ImGui_AdjustAppModeSize (HMONITOR monitor)
{
ImVec2 WorkSize =
ImVec2 ( (float)( info.rcWork.right - info.rcWork.left ),
(float)( info.rcWork.bottom - info.rcWork.top ) );
(float)( info.rcWork.bottom - info.rcWork.top ) );

ImVec2 tmpCurrentSize = (_registry.bServiceMode) ? SKIF_vecServiceModeDefault :
(_registry.bHorizonMode) ? SKIF_vecHorizonModeAdjusted :
Expand Down

0 comments on commit 0e34a45

Please sign in to comment.