basic functionality on Wayland and X11
This commit is contained in:
87
lib/Lib.hs
Normal file
87
lib/Lib.hs
Normal file
@@ -0,0 +1,87 @@
|
||||
{-# LANGUAGE CApiFFI #-}
|
||||
|
||||
module Lib where
|
||||
|
||||
import Data.Bits (shiftL, (.|.))
|
||||
import Foreign
|
||||
import Foreign.C.String
|
||||
import Foreign.C.Types
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- Haskell-ier abstractions
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
data WindowFlags
|
||||
= WindowNoBorder
|
||||
| WindowNoResize
|
||||
| WindowAllowDND
|
||||
| WindowHideMouse
|
||||
| WindowFullscreen
|
||||
| WindowTransparent
|
||||
| WindowCenter
|
||||
| WindowRawMouse
|
||||
| WindowScaleToMonitor
|
||||
| WindowHide
|
||||
| WindowMaximize
|
||||
| WindowCenterCursor
|
||||
| WindowFloating
|
||||
| WindowFocusOnShow
|
||||
| WindowMinimize
|
||||
| WindowFocus
|
||||
| WindowOpenGL
|
||||
| WindowEGL
|
||||
| WindowedFullscreen
|
||||
|
||||
mkWindowFlags :: [WindowFlags] -> RGFWwindowFlags
|
||||
mkWindowFlags [] = 0
|
||||
mkWindowFlags (flag:flags) =
|
||||
let
|
||||
shift =
|
||||
case flag of
|
||||
WindowNoBorder -> 0
|
||||
WindowNoResize -> 1
|
||||
WindowAllowDND -> 2
|
||||
WindowHideMouse -> 3
|
||||
WindowFullscreen -> 4
|
||||
WindowTransparent -> 5
|
||||
WindowCenter -> 6
|
||||
WindowRawMouse -> 7
|
||||
WindowScaleToMonitor -> 8
|
||||
WindowHide -> 9
|
||||
WindowMaximize -> 10
|
||||
WindowCenterCursor -> 11
|
||||
WindowFloating -> 12
|
||||
WindowFocusOnShow -> 13
|
||||
WindowMinimize -> 14
|
||||
WindowFocus -> 15
|
||||
WindowOpenGL -> 17
|
||||
WindowEGL -> 18
|
||||
_ -> 19 -- TODO fix this silent error, implement windowedFullscreen
|
||||
in
|
||||
(shiftL 1 shift) .|. (mkWindowFlags flags)
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- directly from RFGW.h
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
-- RGFWindow
|
||||
data RGFWwindow
|
||||
-- ptr
|
||||
type RGFWwindowPtr = Ptr RGFWwindow
|
||||
-- flags to create
|
||||
type RGFWwindowFlags = Word32
|
||||
|
||||
type RGFWbool = CUInt
|
||||
|
||||
foreign import capi "RGFW_HS.h RGFW_createWindow" rgfwCreateWindow
|
||||
:: Ptr CChar
|
||||
-> CInt
|
||||
-> CInt
|
||||
-> CInt
|
||||
-> CInt
|
||||
-> RGFWwindowFlags
|
||||
-> IO RGFWwindowPtr
|
||||
|
||||
foreign import capi "RGFW_HS.h RGFW_window_shouldClose" rgfwWindowShouldClose
|
||||
:: RGFWwindowPtr
|
||||
-> IO RGFWbool
|
||||
38
lib/Main.hs
Normal file
38
lib/Main.hs
Normal file
@@ -0,0 +1,38 @@
|
||||
{-# LANGUAGE CApiFFI #-}
|
||||
|
||||
module Main (main) where
|
||||
|
||||
import Data.Bits (shiftL, (.|.))
|
||||
import Foreign
|
||||
import Foreign.C.String
|
||||
import Foreign.C.Types
|
||||
|
||||
import Lib
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
-- main
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
window <- withCString "a window" (\name ->
|
||||
rgfwCreateWindow
|
||||
name
|
||||
0
|
||||
0
|
||||
800
|
||||
600
|
||||
$ mkWindowFlags
|
||||
[ WindowNoResize
|
||||
, WindowOpenGL
|
||||
, WindowFullscreen
|
||||
]
|
||||
)
|
||||
let loop ctr = do
|
||||
shouldClose <- rgfwWindowShouldClose window
|
||||
if 0 /= shouldClose
|
||||
then return shouldClose
|
||||
else loop $ ctr + 1
|
||||
exitCode <- loop 0
|
||||
putStrLn $ show exitCode
|
||||
return ()
|
||||
1
lib/RGFW
1
lib/RGFW
Submodule lib/RGFW deleted from b7bd582eb3
14034
lib/RGFW.h
Normal file
14034
lib/RGFW.h
Normal file
File diff suppressed because it is too large
Load Diff
@@ -10,7 +10,7 @@
|
||||
#define RGFW_OPENGL
|
||||
|
||||
#define Time X11Time // fixes namespace clash with GHC when building with Nix
|
||||
#include "RGFW/RGFW.h"
|
||||
#include "RGFW.h"
|
||||
#undef Time
|
||||
|
||||
#endif RGFW_HS
|
||||
|
||||
Reference in New Issue
Block a user