# HG changeset patch # User Sam # Date 1683119476 -25200 # Node ID d52094e438c2fd790b47470be557dda9a5859de2 # Parent 20c95d964018999e7fe4fca49a4ed90de7ac81ce add: fullscreen switching for windows, untested diff -r 20c95d964018 -r d52094e438c2 src/semicongine/platform/windows/window.nim --- a/src/semicongine/platform/windows/window.nim Wed May 03 19:49:32 2023 +0700 +++ b/src/semicongine/platform/windows/window.nim Wed May 03 20:11:16 2023 +0700 @@ -9,6 +9,8 @@ NativeWindow* = object hinstance*: HINSTANCE hwnd*: HWND + g_wpPrev: WINDOWPLACEMENT + # sorry, have to use module-global variable to capture windows events var currentEvents: seq[Event] @@ -87,9 +89,19 @@ discard ShowWindow(result.hwnd, SW_SHOW) +# inspired by the one and only, Raymond Chen +# https://devblogs.microsoft.com/oldnewthing/20100412-00/?p=14353 proc fullscreen*(window: NativeWindow, enable: bool) = - discard - # from the oneandonly: https://devblogs.microsoft.com/oldnewthing/20100412-00/?p=14353 + let dwStyle: DWORD = GetWindowLong(window.hwnd, GWL_STYLE) + if (dwStyle and WS_OVERLAPPEDWINDOW): + var mi: MONITORINFO + if GetWindowPlacement(window.hwnd, unsafeAddr window.g_wpPrev) and GetMonitorInfo(MonitorFromWindow(window.hwnd, MONITOR_DEFAULTTOPRIMARY), addr mi): + SetWindowLong(window.hwnd, GWL_STYLE, dwStyle and (not WS_OVERLAPPEDWINDOW)) + SetWindowPos(window.hwnd, HWND_TOP, mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right - mi.rcMonitor.left, mi.rcMonitor.bottom - mi.rcMonitor.top, SWP_NOOWNERZORDER or SWP_FRAMECHANGED) + else: + SetWindowLong(window.hwnd, GWL_STYLE, dwStyle or WS_OVERLAPPEDWINDOW) + SetWindowPlacement(window.hwnd, unsafeAddr window.g_wpPrev) + SetWindowPos(window.hwnd, HWND(0), 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOZORDER or SWP_NOOWNERZORDER or SWP_FRAMECHANGED) proc hideSystemCursor*(window: NativeWindow) = discard ShowCursor(false)