Skip to content

Commit b006fa7

Browse files
TristanCacqueraydpwiz
authored andcommitted
Add binding for getWindowBordersSize
This change enables more accurate window position management by taking into account the display server decoration.
1 parent 9b23751 commit b006fa7

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/SDL/Raw/Video.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ module SDL.Raw.Video (
3737
getNumVideoDisplays,
3838
getNumVideoDrivers,
3939
getVideoDriver,
40+
getWindowBordersSize,
4041
getWindowBrightness,
4142
getWindowData,
4243
getWindowDisplayIndex,
@@ -252,6 +253,7 @@ foreign import ccall "SDL.h SDL_GetNumDisplayModes" getNumDisplayModesFFI :: CIn
252253
foreign import ccall "SDL.h SDL_GetNumVideoDisplays" getNumVideoDisplaysFFI :: IO CInt
253254
foreign import ccall "SDL.h SDL_GetNumVideoDrivers" getNumVideoDriversFFI :: IO CInt
254255
foreign import ccall "SDL.h SDL_GetVideoDriver" getVideoDriverFFI :: CInt -> IO CString
256+
foreign import ccall "SDL.h SDL_GetWindowBordersSize" getWindowBordersSize :: Window -> Ptr CInt -> Ptr CInt -> Ptr CInt -> Ptr CInt -> IO CInt
255257
foreign import ccall "SDL.h SDL_GetWindowBrightness" getWindowBrightnessFFI :: Window -> IO CFloat
256258
foreign import ccall "SDL.h SDL_GetWindowData" getWindowDataFFI :: Window -> CString -> IO (Ptr ())
257259
foreign import ccall "SDL.h SDL_GetWindowDisplayIndex" getWindowDisplayIndexFFI :: Window -> IO CInt

src/SDL/Video.hs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module SDL.Video
3232
, windowGrab
3333
, setWindowMode
3434
, getWindowAbsolutePosition
35+
, getWindowBordersSize
3536
, setWindowPosition
3637
, windowTitle
3738
, windowData
@@ -311,6 +312,21 @@ getWindowAbsolutePosition (Window w) =
311312
Raw.getWindowPosition w wPtr hPtr
312313
V2 <$> peek wPtr <*> peek hPtr
313314

315+
-- | Get the size of a window's borders (decorations) around the client area (top, left, bottom, right).
316+
--
317+
-- See @<https://wiki.libsdl.org/SDL_GetWindowBordersSize SDL_GetWindowBordersSize>@ for C documentation.
318+
getWindowBordersSize :: MonadIO m => Window -> m (Maybe (V4 CInt))
319+
getWindowBordersSize (Window win) =
320+
liftIO $
321+
alloca $ \tPtr ->
322+
alloca $ \lPtr ->
323+
alloca $ \bPtr ->
324+
alloca $ \rPtr -> do
325+
n <- Raw.getWindowBordersSize win tPtr lPtr bPtr rPtr
326+
if n /= 0
327+
then return Nothing
328+
else fmap Just $ V4 <$> peek tPtr <*> peek lPtr <*> peek bPtr <*> peek rPtr
329+
314330
-- | Get or set the size of a window's client area. Values beyond the maximum supported size are clamped.
315331
--
316332
-- If window was created with 'windowHighDPI' flag, this size may differ from the size in pixels.

0 commit comments

Comments
 (0)