From 63550cc81ef6ef632887822592709db7f281e226 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Wed, 16 Aug 2023 14:27:07 -0600 Subject: [PATCH] app: [Windows] make custom decorated windows behave like regular windows Signed-off-by: Elias Naur --- app/internal/windows/windows.go | 1 + app/os_windows.go | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/app/internal/windows/windows.go b/app/internal/windows/windows.go index 3c99d3d0..7a639746 100644 --- a/app/internal/windows/windows.go +++ b/app/internal/windows/windows.go @@ -245,6 +245,7 @@ const ( WM_MOUSEHWHEEL = 0x020E WM_NCACTIVATE = 0x0086 WM_NCHITTEST = 0x0084 + WM_NCCALCSIZE = 0x0083 WM_PAINT = 0x000F WM_QUIT = 0x0012 WM_SETCURSOR = 0x0020 diff --git a/app/os_windows.go b/app/os_windows.go index fbf2422d..a22a892f 100644 --- a/app/os_windows.go +++ b/app/os_windows.go @@ -325,6 +325,11 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr // The system destroys the HWND for us. w.hwnd = 0 windows.PostQuitMessage(0) + case windows.WM_NCCALCSIZE: + if !w.config.Decorated { + // No client areas; we draw decorations ourselves. + return 0 + } case windows.WM_PAINT: w.draw(true) case windows.WM_SIZE: @@ -669,9 +674,6 @@ func (w *window) Configure(options []Option) { swpStyle := uintptr(windows.SWP_NOZORDER | windows.SWP_FRAMECHANGED) winStyle := uintptr(windows.WS_OVERLAPPEDWINDOW) style &^= winStyle - if !w.config.Decorated { - winStyle = 0 - } switch w.config.Mode { case Minimized: style |= winStyle @@ -695,9 +697,12 @@ func (w *window) Configure(options []Option) { // Set desired window size. wr.Right = wr.Left + width wr.Bottom = wr.Top + height - // Convert from client size to window size. + // Compute client size and position. Note that the client size is + // equal to the window size when we are in control of decorations. r := wr - windows.AdjustWindowRectEx(&r, uint32(style), 0, dwExStyle) + if w.config.Decorated { + windows.AdjustWindowRectEx(&r, uint32(style), 0, dwExStyle) + } // Calculate difference between client and full window sizes. w.deltas.width = r.Right - wr.Right + wr.Left - r.Left w.deltas.height = r.Bottom - wr.Bottom + wr.Top - r.Top