From 7d9fde6c5e5199b033e23b7e91f535f36f0026f5 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 7 Mar 2026 11:01:31 -0800 Subject: Use framebuffer size for initial resize --- Spear/App.hs | 2 +- Spear/Window.hs | 62 ++++++++++++++++++++++++++++++--------------------------- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/Spear/App.hs b/Spear/App.hs index e85c46b..6473e1b 100644 --- a/Spear/App.hs +++ b/Spear/App.hs @@ -175,7 +175,7 @@ loop :: App s -> Window -> Game (AppState s) () loop app window = do -- For convenience, trigger an initial resize followed by a render of the -- application's initial state. - (width, height) <- getWindowSize window + (width, height) <- getFramebufferSize window resizeApp app (ResizeEvent width height) renderApp app diff --git a/Spear/Window.hs b/Spear/Window.hs index a873362..2e30c0b 100644 --- a/Spear/Window.hs +++ b/Spear/Window.hs @@ -1,32 +1,32 @@ module Spear.Window - ( -- * Setup - Dimensions, - WindowTitle, - - -- * Window - Window, - Width, - Height, - WindowEvent(..), - withWindow, - pollWindowEvents, - shouldWindowClose, - swapBuffers, - getWindowSize, - - -- * Input - pollInputEvents, - whenKeyDown, - whenKeyUp, - processKeys, - processButtons, - InputEvent(..), - Key(..), - MouseButton(..), - MouseProp(..), - MousePos, - MouseDelta, - ) +( +-- * Setup + Dimensions +, WindowTitle +-- * Window +, Window +, Width +, Height +, WindowEvent(..) +, withWindow +, pollWindowEvents +, shouldWindowClose +, swapBuffers +, getWindowSize +, getFramebufferSize +-- * Input +, pollInputEvents +, whenKeyDown +, whenKeyUp +, processKeys +, processButtons +, InputEvent(..) +, Key(..) +, MouseButton(..) +, MouseProp(..) +, MousePos +, MouseDelta +) where import Spear.Game @@ -78,7 +78,7 @@ data Window = Window withWindow :: MonadIO io => Dimensions -> WindowTitle -> (Window -> IO a) -> io a -withWindow dim@(w, h) windowTitle run = liftIO $ do +withWindow dim windowTitle run = liftIO $ do window <- do success <- GLFW.init unless success $ throw (WindowException "GLFW.initialize failed") @@ -149,6 +149,10 @@ swapBuffers = liftIO . GLFW.swapBuffers . glfwWindow getWindowSize :: MonadIO io => Window -> io (Width, Height) getWindowSize = liftIO . GLFW.getWindowSize . glfwWindow +-- | Get the window's framebuffer size. +getFramebufferSize :: MonadIO io => Window -> io (Width, Height) +getFramebufferSize = liftIO . GLFW.getFramebufferSize . glfwWindow + getRequest :: MVar Bool -> IO Bool getRequest mvar = tryTakeMVar mvar >>= \x -> return $ fromMaybe False x -- cgit v1.2.3