adjust nccalcsize window message; we just need to coax windows into doing the copy in order to avoid resize artifacts. still not perfect, can get into a weird state, and we may need to do more full size calculation in some cases

This commit is contained in:
Ryan Fleury
2024-11-19 16:59:20 -08:00
parent a40c26a0eb
commit cb4232469e
2 changed files with 24 additions and 26 deletions
+22 -25
View File
@@ -8,8 +8,10 @@
typedef BOOL w32_SetProcessDpiAwarenessContext_Type(void* value); typedef BOOL w32_SetProcessDpiAwarenessContext_Type(void* value);
typedef UINT w32_GetDpiForWindow_Type(HWND hwnd); typedef UINT w32_GetDpiForWindow_Type(HWND hwnd);
typedef int w32_GetSystemMetricsForDpi_Type(int nIndex, UINT dpi);
#define w32_DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ((void*)-4) #define w32_DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ((void*)-4)
global w32_GetDpiForWindow_Type *w32_GetDpiForWindow_func = 0; global w32_GetDpiForWindow_Type *w32_GetDpiForWindow_func = 0;
global w32_GetSystemMetricsForDpi_Type *w32_GetSystemMetricsForDpi_func = 0;
//////////////////////////////// ////////////////////////////////
//~ rjf: Basic Helpers //~ rjf: Basic Helpers
@@ -559,7 +561,7 @@ os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
//- rjf: [custom border] //- rjf: [custom border]
case WM_NCPAINT: case WM_NCPAINT:
{ {
if(window != 0 && window->custom_border && !window->custom_border_composition_enabled) if(os_w32_new_window_custom_border || (window != 0 && window->custom_border && !window->custom_border_composition_enabled))
{ {
result = 0; result = 0;
} }
@@ -596,7 +598,7 @@ os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
case WM_NCUAHDRAWFRAME: case WM_NCUAHDRAWFRAME:
{ {
// NOTE(rjf): undocumented messages for drawing themed window borders. // NOTE(rjf): undocumented messages for drawing themed window borders.
if(window != 0 && window->custom_border) if(os_w32_new_window_custom_border || (window != 0 && window->custom_border))
{ {
result = 0; result = 0;
} }
@@ -608,7 +610,7 @@ os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
case WM_SETICON: case WM_SETICON:
case WM_SETTEXT: case WM_SETTEXT:
{ {
if(window && window->custom_border && !window->custom_border_composition_enabled) if(os_w32_new_window_custom_border || (window && window->custom_border && !window->custom_border_composition_enabled))
{ {
// NOTE(rjf): // NOTE(rjf):
// https://blogs.msdn.microsoft.com/wpfsdk/2008/09/08/custom-window-chrome-in-wpf/ // https://blogs.msdn.microsoft.com/wpfsdk/2008/09/08/custom-window-chrome-in-wpf/
@@ -626,7 +628,7 @@ os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
//- rjf: [custom border] activation - without this `result`, stuff flickers. //- rjf: [custom border] activation - without this `result`, stuff flickers.
case WM_NCACTIVATE: case WM_NCACTIVATE:
{ {
if(window == 0 || window->custom_border == 0) if(!os_w32_new_window_custom_border && (window == 0 || window->custom_border == 0))
{ {
result = DefWindowProcW(hwnd, uMsg, wParam, lParam); result = DefWindowProcW(hwnd, uMsg, wParam, lParam);
} }
@@ -638,30 +640,18 @@ os_w32_wnd_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
//- rjf: [custom border] client/window size calculation //- rjf: [custom border] client/window size calculation
case WM_NCCALCSIZE: case WM_NCCALCSIZE:
if(window != 0)
{ {
if(window->custom_border == 0) if(os_w32_new_window_custom_border || (window && window->custom_border))
{ {
result = DefWindowProcW(hwnd, uMsg, wParam, lParam); if(wParam == 1)
{
NCCALCSIZE_PARAMS *pncsp = (NCCALCSIZE_PARAMS *)lParam;
pncsp->rgrc[0].right += 1;
}
} }
else else
{ {
MARGINS m = {0, 0, 0, 0}; result = DefWindowProc(hwnd, uMsg, wParam, lParam);
RECT *r = (RECT *)lParam;
DWORD window_style = window ? GetWindowLong(window->hwnd, GWL_STYLE) : 0;
B32 is_fullscreen = !(window_style & WS_OVERLAPPEDWINDOW);
if(IsZoomed(hwnd) && !is_fullscreen)
{
int x_push_in = GetSystemMetrics(SM_CXFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER);
int y_push_in = GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CXPADDEDBORDER);
r->left += x_push_in;
r->top += y_push_in;
r->bottom -= x_push_in;
r->right -= y_push_in;
m.cxLeftWidth = m.cxRightWidth = x_push_in;
m.cyTopHeight = m.cyBottomHeight = y_push_in;
}
DwmExtendFrameIntoClientArea(hwnd, &m);
} }
}break; }break;
@@ -814,6 +804,7 @@ os_gfx_init(void)
(w32_SetProcessDpiAwarenessContext_Type*)GetProcAddress(module, "SetProcessDpiAwarenessContext"); (w32_SetProcessDpiAwarenessContext_Type*)GetProcAddress(module, "SetProcessDpiAwarenessContext");
w32_GetDpiForWindow_func = w32_GetDpiForWindow_func =
(w32_GetDpiForWindow_Type*)GetProcAddress(module, "GetDpiForWindow"); (w32_GetDpiForWindow_Type*)GetProcAddress(module, "GetDpiForWindow");
w32_GetSystemMetricsForDpi_func = (w32_GetSystemMetricsForDpi_Type *)GetProcAddress(module, "GetSystemMetricsForDpi");
FreeLibrary(module); FreeLibrary(module);
} }
if(SetProcessDpiAwarenessContext_func != 0) if(SetProcessDpiAwarenessContext_func != 0)
@@ -1015,11 +1006,14 @@ os_get_clipboard_text(Arena *arena)
internal OS_Handle internal OS_Handle
os_window_open(Vec2F32 resolution, OS_WindowFlags flags, String8 title) os_window_open(Vec2F32 resolution, OS_WindowFlags flags, String8 title)
{ {
B32 custom_border = !!(flags & OS_WindowFlag_CustomBorder);
//- rjf: make hwnd //- rjf: make hwnd
HWND hwnd = 0; HWND hwnd = 0;
{ {
Temp scratch = scratch_begin(0, 0); Temp scratch = scratch_begin(0, 0);
String16 title16 = str16_from_8(scratch.arena, title); String16 title16 = str16_from_8(scratch.arena, title);
os_w32_new_window_custom_border = custom_border;
hwnd = CreateWindowExW(WS_EX_APPWINDOW, hwnd = CreateWindowExW(WS_EX_APPWINDOW,
L"graphical-window", L"graphical-window",
(WCHAR*)title16.str, (WCHAR*)title16.str,
@@ -1031,6 +1025,7 @@ os_window_open(Vec2F32 resolution, OS_WindowFlags flags, String8 title)
os_w32_gfx_state->hInstance, os_w32_gfx_state->hInstance,
0); 0);
DragAcceptFiles(hwnd, 1); DragAcceptFiles(hwnd, 1);
os_w32_new_window_custom_border = 0;
scratch_end(scratch); scratch_end(scratch);
} }
@@ -1038,10 +1033,12 @@ os_window_open(Vec2F32 resolution, OS_WindowFlags flags, String8 title)
OS_W32_Window *window = os_w32_window_alloc(); OS_W32_Window *window = os_w32_window_alloc();
{ {
window->hwnd = hwnd; window->hwnd = hwnd;
if (w32_GetDpiForWindow_func != 0){ if(w32_GetDpiForWindow_func != 0)
{
window->dpi = (F32)w32_GetDpiForWindow_func(hwnd); window->dpi = (F32)w32_GetDpiForWindow_func(hwnd);
} }
else{ else
{
window->dpi = 96.f; window->dpi = 96.f;
} }
} }
+2 -1
View File
@@ -84,7 +84,8 @@ struct OS_W32_GfxState
global OS_W32_GfxState *os_w32_gfx_state = 0; global OS_W32_GfxState *os_w32_gfx_state = 0;
global OS_EventList os_w32_event_list = {0}; global OS_EventList os_w32_event_list = {0};
global Arena *os_w32_event_arena = 0; global Arena *os_w32_event_arena = 0;
B32 os_w32_resizing = 0; global B32 os_w32_resizing = 0;
global B32 os_w32_new_window_custom_border = 0;
//////////////////////////////// ////////////////////////////////
//~ rjf: Basic Helpers //~ rjf: Basic Helpers