diff options
| author | Josh Rahm <joshuarahm@gmail.com> | 2026-01-01 23:41:11 -0700 |
|---|---|---|
| committer | Josh Rahm <joshuarahm@gmail.com> | 2026-01-01 23:41:11 -0700 |
| commit | 418d2b2b0829ed17e523867896ea321fc2b3a79b (patch) | |
| tree | da0fad8ae1d46bb30ab2e2ea1fe4fa4f7c51aed6 /plug/src/Montis/Foreign/ForeignInterface.hs | |
| parent | 1df0b552f17f15942a350def6736d5535e545d4c (diff) | |
| download | montis-418d2b2b0829ed17e523867896ea321fc2b3a79b.tar.gz montis-418d2b2b0829ed17e523867896ea321fc2b3a79b.tar.bz2 montis-418d2b2b0829ed17e523867896ea321fc2b3a79b.zip | |
[refactor] Remove the foregin interface.
The plugin will just call c functions through the FFI.
Diffstat (limited to 'plug/src/Montis/Foreign/ForeignInterface.hs')
| -rw-r--r-- | plug/src/Montis/Foreign/ForeignInterface.hs | 61 |
1 files changed, 1 insertions, 60 deletions
diff --git a/plug/src/Montis/Foreign/ForeignInterface.hs b/plug/src/Montis/Foreign/ForeignInterface.hs index c01e6b8..647fb98 100644 --- a/plug/src/Montis/Foreign/ForeignInterface.hs +++ b/plug/src/Montis/Foreign/ForeignInterface.hs @@ -1,20 +1,12 @@ module Montis.Foreign.ForeignInterface - ( getForeignInterface, - ForeignInterface (..), - ForeignDemarshal (..), + ( ForeignDemarshal (..), runForeignDemarshal, demarshal, - doShellExec, ) where import Control.Monad.State (MonadState (get, put), MonadTrans (lift), StateT, evalStateT) -import Data.Void (Void) import Foreign (Ptr, Storable (peek, sizeOf), castPtr, plusPtr) -import Foreign.C (CChar, CInt (..)) -import Foreign.C.String -import GHC.Exts (FunPtr) -import Montis.Foreign.WlRoots newtype ForeignDemarshal a = ForeignDemarshal (StateT (Ptr ()) IO a) deriving (Functor, Monad, Applicative, MonadState (Ptr ())) @@ -28,54 +20,3 @@ demarshal = do val <- ForeignDemarshal $ lift $ peek $ castPtr ptr put (plusPtr ptr (sizeOf val)) return val - -type CtxT = Ptr Void - -type ForeignCallGetPtr = CtxT -> IO (Ptr ()) - -type ForeignCall = CtxT -> IO () - -type ForeignCallStr = CtxT -> CString -> IO () - -type ForeignCallInt = CtxT -> CInt -> IO () - -foreign import ccall "get_foreign_interface" foreignInterfacePtr :: IO (Ptr ()) - -foreign import ccall "dynamic" toForeignCall :: FunPtr ForeignCall -> ForeignCall - -foreign import ccall "dynamic" toForeignCallStr :: FunPtr ForeignCallStr -> ForeignCallStr - -foreign import ccall "dynamic" toForeignCallInt :: FunPtr ForeignCallInt -> ForeignCallInt - -foreign import ccall "dynamic" toForeignCallGetPtr :: FunPtr ForeignCallGetPtr -> ForeignCallGetPtr - -foreign import ccall "shell_exec" shellExec :: Ptr CChar -> IO () - -data ForeignInterface = ForeignInterface - { requestHotReload :: IO (), - requestLog :: String -> IO (), - requestExit :: Int -> IO (), - getSeat :: IO (Ptr WlrSeat) - } - -doShellExec :: String -> IO () -doShellExec str = withCString str shellExec - -getForeignInterface :: IO ForeignInterface -getForeignInterface = do - ptr <- foreignInterfacePtr - runForeignDemarshal ptr $ do - ctx <- demarshal - requestHotReloadFn <- demarshal - doLogFn <- demarshal - doRequestExit <- demarshal - getSeatFn <- demarshal - - return $ - ForeignInterface - { requestHotReload = toForeignCall requestHotReloadFn ctx, - requestLog = \str -> - withCString str $ \cs -> toForeignCallStr doLogFn ctx cs, - requestExit = toForeignCallInt doRequestExit ctx . fromIntegral, - getSeat = castPtr <$> toForeignCallGetPtr getSeatFn ctx - } |