Skip to content
Snippets Groups Projects
Commit c4f50632 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Fix pervasive fencepost error calculating width and height.

Basically everywhere was off by one.

Also, fix the get dpi size thingie to correct for window decorations.
We never actually use the result of this, but Windows might for
outline dragging or something... you can never know.
parent 0416b59b
No related branches found
No related tags found
No related merge requests found
Pipeline #5858 passed
......@@ -192,7 +192,7 @@ sp_to_codepoint(uint16_t high, uint16_t low)
}
static BOOL
gdiAdjustWindowRect(LPRECT r, DWORD style, BOOL menu)
gdiAdjustWindowRect(LPRECT r, DWORD style, BOOL menu, UINT dpi)
{
static bool gotPtr = false;
static BOOL (*AWREFD)(LPRECT, DWORD, BOOL, DWORD, UINT);
......@@ -212,11 +212,12 @@ gdiAdjustWindowRect(LPRECT r, DWORD style, BOOL menu)
}
if (win && AWREFD && GDFW && GDFS) {
UINT dpi;
if (win == NULL)
dpi = GDFS();
else
dpi = GDFW(win);
if (dpi == 0) {
if (win == NULL)
dpi = GDFS();
else
dpi = GDFW(win);
}
return AWREFD(r, style, menu, 0, dpi);
}
return AdjustWindowRect(r, style, menu);
......@@ -230,10 +231,10 @@ UnadjustWindowSize(int *w, int *h)
if (fullscreen)
return true;
ret = gdiAdjustWindowRect(&r, STYLE, FALSE);
ret = gdiAdjustWindowRect(&r, STYLE, FALSE, 0);
if (ret) {
*w += r.left - r.right;
*h += r.top - r.bottom;
*w += r.right - r.left + 1;
*h += r.bottom - r.top + 1;
}
return ret;
}
......@@ -280,21 +281,21 @@ gdi_handle_wm_sizing(WPARAM wParam, RECT *rect)
case WMSZ_BOTTOM:
case WMSZ_BOTTOMLEFT:
case WMSZ_LEFT:
rect->bottom = rect->top + h;
rect->left = rect->right - w;
rect->bottom = rect->top + h - 1;
rect->left = rect->right - w + 1;
break;
case WMSZ_BOTTOMRIGHT:
case WMSZ_RIGHT:
rect->bottom = rect->top + h;
rect->right = rect->left + w;
rect->bottom = rect->top + h - 1;
rect->right = rect->left + w - 1;
break;
case WMSZ_TOP:
case WMSZ_TOPLEFT:
rect->top = rect->bottom - h;
rect->left = rect->right - w;
rect->top = rect->bottom - h + 1;
rect->left = rect->right - w + 1;
break;
case WMSZ_TOPRIGHT:
rect->right = rect->left + w;
rect->right = rect->left + w - 1;
break;
}
return TRUE;
......@@ -550,9 +551,9 @@ get_monitor_size_pos(int *w, int *h, int *xpos, int *ypos)
if (ret) {
if (fullscreen) {
if (w)
*w = mi.rcMonitor.right - mi.rcMonitor.left;
*w = mi.rcMonitor.right - mi.rcMonitor.left + 1;
if (h)
*h = mi.rcMonitor.bottom - mi.rcMonitor.top;
*h = mi.rcMonitor.bottom - mi.rcMonitor.top + 1;
if (xpos)
*xpos = mi.rcMonitor.left;
if (ypos)
......@@ -560,9 +561,9 @@ get_monitor_size_pos(int *w, int *h, int *xpos, int *ypos)
}
else {
if (w)
*w = mi.rcWork.right - mi.rcWork.left;
*w = mi.rcWork.right - mi.rcWork.left + 1;
if (h)
*h = mi.rcWork.bottom - mi.rcWork.top;
*h = mi.rcWork.bottom - mi.rcWork.top + 1;
if (xpos)
*xpos = mi.rcWork.left;
if (ypos)
......@@ -596,9 +597,9 @@ handle_wm_getminmaxinfo(MINMAXINFO *inf)
r.left = 0;
r.right = maxw;
r.bottom = maxh;
gdiAdjustWindowRect(&r, STYLE, FALSE);
inf->ptMaxTrackSize.x = r.right - r.left;
inf->ptMaxTrackSize.y = r.bottom - r.top;
gdiAdjustWindowRect(&r, STYLE, FALSE, 0);
inf->ptMaxTrackSize.x = r.right - r.left + 1;
inf->ptMaxTrackSize.y = r.bottom - r.top + 1;
inf->ptMaxSize.x = inf->ptMaxTrackSize.x;
inf->ptMaxSize.y = inf->ptMaxTrackSize.y;
inf->ptMaxPosition.x = (monw - inf->ptMaxTrackSize.x) / 2;
......@@ -608,9 +609,9 @@ handle_wm_getminmaxinfo(MINMAXINFO *inf)
r.left = 0;
r.right = minw;
r.bottom = minh;
gdiAdjustWindowRect(&r, STYLE, FALSE);
inf->ptMinTrackSize.x = r.right - r.left;
inf->ptMinTrackSize.y = r.bottom - r.top;
gdiAdjustWindowRect(&r, STYLE, FALSE, 0);
inf->ptMinTrackSize.x = r.right - r.left + 1;
inf->ptMinTrackSize.y = r.bottom - r.top + 1;
return 0;
}
......@@ -618,9 +619,16 @@ handle_wm_getminmaxinfo(MINMAXINFO *inf)
static LRESULT
gdi_handle_getdpiscaledsize(WPARAM wParam, LPSIZE sz)
{
RECT r;
pthread_mutex_lock(&vstatlock);
sz->cx = vstat.winwidth;
sz->cy = vstat.winheight;
// Now make the inside of the window the size we want (sigh)
r.left = r.top = 0;
r.right = vstat.scrnwidth;
r.bottom = vstat.scrnheight;
pthread_mutex_unlock(&vstatlock);
gdiAdjustWindowRect(&r, STYLE, FALSE, HIWORD(wParam));
sz->cx = r.right - r.left + 1;
sz->cy = r.bottom - r.top + 1;
pthread_mutex_unlock(&vstatlock);
return 0;
}
......@@ -694,7 +702,7 @@ gdi_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
break;
if (!ScreenToClient(hwnd, &p))
break;
if (p.x < 0 || p.y < 0 || p.x > (r.right - r.left) || p.y > (r.bottom - r.top))
if (p.x < 0 || p.y < 0 || p.x > (r.right - r.left + 1) || p.y > (r.bottom - r.top + 1))
break;
SetCursor(cursor);
break;
......@@ -708,8 +716,8 @@ gdi_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
r.right = wParam;
r.bottom = lParam;
pthread_mutex_unlock(&vstatlock);
gdiAdjustWindowRect(&r, STYLE, FALSE);
SetWindowPos(win, NULL, 0, 0, r.right - r.left, r.bottom - r.top, SWP_NOMOVE|SWP_NOOWNERZORDER|SWP_NOZORDER);
gdiAdjustWindowRect(&r, STYLE, FALSE, 0);
SetWindowPos(win, NULL, 0, 0, r.right - r.left + 1, r.bottom - r.top + 1, SWP_NOMOVE|SWP_NOOWNERZORDER|SWP_NOZORDER);
return true;
case WM_USER_SETPOS:
SetWindowPos(win, NULL, wParam, lParam, 0, 0, SWP_NOSIZE|SWP_NOOWNERZORDER|SWP_NOZORDER);
......@@ -814,7 +822,7 @@ magic_message(MSG msg)
pthread_mutex_unlock(&vstatlock);
SetWindowLongPtr(win, GWL_STYLE, STYLE);
PostMessageW(win, WM_USER_SETPOS, mi.rcMonitor.left, mi.rcMonitor.top);
PostMessageW(win, WM_USER_SETSIZE, mi.rcMonitor.right - mi.rcMonitor.left, mi.rcMonitor.bottom - mi.rcMonitor.top);
PostMessageW(win, WM_USER_SETSIZE, mi.rcMonitor.right - mi.rcMonitor.left + 1, mi.rcMonitor.bottom - mi.rcMonitor.top + 1);
}
else
fullscreen = false;
......@@ -926,8 +934,8 @@ gdi_thread(void *arg)
r.right = vstat.winwidth;
r.bottom = vstat.winheight;
pthread_mutex_unlock(&vstatlock);
gdiAdjustWindowRect(&r, STYLE, FALSE);
win = CreateWindowW(wc.lpszClassName, L"SyncConsole", STYLE, wx, wy, r.right - r.left, r.bottom - r.top, NULL, NULL, NULL, NULL);
gdiAdjustWindowRect(&r, STYLE, FALSE, 0);
win = CreateWindowW(wc.lpszClassName, L"SyncConsole", STYLE, wx, wy, r.right - r.left + 1, r.bottom - r.top + 1, NULL, NULL, NULL, NULL);
if (win == NULL)
goto fail;
if (cio_api.options & CONIO_OPT_DISABLE_CLOSE)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment