HumbleUI / JWM

Cross-platform window management and OS integration library for Java
Apache License 2.0
546 stars 44 forks source link

Windows: get/setWindowSize include drop shadow area #289

Open tonsky opened 4 months ago

tonsky commented 4 months ago

They shouldn’t. We want window bounds excluding the drop shadow, both for getting and setting window position and size.

https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowrect#return-value

Screenshot 2024-02-20 at 22 08 21

Quezion commented 4 months ago

I'm working on this now as part of #286 -- it might take me some days to get the PR ready, but this local code seems to work.

RECT jwm::WindowWin32::_getWindowRectSimple() const {
    RECT rect;
    // TODO: continue using old implementation if "OS major version is < 6" (Vista)
    // GetWindowRect(_hWnd, &rect);
    DwmGetWindowAttribute(_hWnd, DWMWA_EXTENDED_FRAME_BOUNDS, &rect, sizeof(rect));
    return rect;
}

jwm::IRect jwm::WindowWin32::getWindowRect() const {
    RECT rect = _getWindowRectSimple();
    return IRect{rect.left, rect.top, rect.right, rect.bottom};
}

I've replaced all calls to winAPI GetWindowRect with the internal getWindowRectSimple & this is working so far.