Skip to content

Commit

Permalink
Merge pull request #49 from zao/fix/check-cfg-window-size
Browse files Browse the repository at this point in the history
fix: clamp saved window size to minimum size
  • Loading branch information
Wires77 authored Mar 27, 2024
2 parents 6f8c80b + f32d325 commit 5602a6d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 3 additions & 0 deletions engine/core/core_video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ void core_video_c::Apply(bool shown)
set.flags|= VID_MAXIMIZE;
} else if (vid_resizable->intVal == 3) {
if (sscanf(vid_last->strVal.c_str(), "%d,%d,%d,%d,%d", set.save.size + 0, set.save.size + 1, set.save.pos + 0, set.save.pos + 1, (int*)&set.save.maximised) == 5) {
// Clamp saved window size as it may be persisted as zero before.
set.save.size[0] = (std::max)(CFG_VID_MINWIDTH, set.save.size[0]);
set.save.size[1] = (std::max)(CFG_VID_MINHEIGHT, set.save.size[1]);
set.flags|= VID_USESAVED;
} else {
set.flags|= VID_MAXIMIZE;
Expand Down
16 changes: 11 additions & 5 deletions engine/system/win/sys_video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,15 +604,21 @@ void sys_video_c::FramebufferSizeChanged(int width, int height) {

void sys_video_c::SizeChanged(int width, int height, bool max)
{
vid.size[0] = width;
vid.size[1] = height;
vid.maximised = max;
// Avoid persisting an invalid window size from being minimized.
if (!glfwGetWindowAttrib(wnd, GLFW_ICONIFIED)) {
vid.size[0] = width;
vid.size[1] = height;
vid.maximised = max;
}
}

void sys_video_c::PosChanged(int x, int y)
{
vid.pos[0] = x;
vid.pos[1] = y;
// Avoid persisting an invalid window location from being minimized.
if (!glfwGetWindowAttrib(wnd, GLFW_ICONIFIED)) {
vid.pos[0] = x;
vid.pos[1] = y;
}
}

void sys_video_c::GetMinSize(int& width, int& height)
Expand Down

0 comments on commit 5602a6d

Please sign in to comment.