aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2024-02-11 19:11:21 -0700
committerJosh Rahm <joshuarahm@gmail.com>2024-02-11 19:11:21 -0700
commit2d530e35ee67126c83afb89ed7a3066b65782f57 (patch)
tree00f2e411ed5ee19f1810a4fb58585cc3e91f8841 /src
parentd5d8526cfa80b17bd2562fda06614659fc42a20a (diff)
downloadmontis-2d530e35ee67126c83afb89ed7a3066b65782f57.tar.gz
montis-2d530e35ee67126c83afb89ed7a3066b65782f57.tar.bz2
montis-2d530e35ee67126c83afb89ed7a3066b65782f57.zip
Import tinywl into the project, starting the compositor phase.
Right now nothing interesting is happening, but the new tinywl implementation is successfully loading a plugin and calling a handler for 'handle keybinding', which is pretty slick.
Diffstat (limited to 'src')
-rw-r--r--src/Main.hs8
-rw-r--r--src/Wetterhorn/Core.hs4
-rw-r--r--src/Wetterhorn/FFI.hs14
3 files changed, 20 insertions, 6 deletions
diff --git a/src/Main.hs b/src/Main.hs
index bdffd6f..75e21bd 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -3,6 +3,7 @@
module Main (main) where
import Control.Monad.Writer (MonadWriter (tell), execWriter)
+import Text.Printf
import Wetterhorn.Core
foreign export ccall wetterhorn :: IO Wetterhorn
@@ -12,10 +13,9 @@ wetterhorn =
initWetterhorn $
WConfig
"This is a string"
- ( do
- (WState str i) <- getWState
- wio $ putStrLn $ "Handle something!!! :) " ++ str ++ " " ++ show i
- incrementState
+ ( \sym -> do
+ wio $
+ printf "Got Key: %x\n" sym
)
main :: IO ()
diff --git a/src/Wetterhorn/Core.hs b/src/Wetterhorn/Core.hs
index e04cb49..7b5690f 100644
--- a/src/Wetterhorn/Core.hs
+++ b/src/Wetterhorn/Core.hs
@@ -19,7 +19,7 @@ import Control.Arrow (first)
import Control.Exception
import Data.ByteString (ByteString)
import qualified Data.ByteString.Char8 as CH
-import Foreign (StablePtr, newStablePtr)
+import Foreign (StablePtr, Word32, newStablePtr)
-- This is this opaque state presented to the harness.
type Wetterhorn = StablePtr (WConfig, WState)
@@ -36,7 +36,7 @@ data WState = WState
data WConfig = WConfig
{ someConfig :: String,
- handleSomething :: W ()
+ keybindingHandler :: Word32 -> W ()
}
readWState :: ByteString -> IO WState
diff --git a/src/Wetterhorn/FFI.hs b/src/Wetterhorn/FFI.hs
index bfb3cbd..d941493 100644
--- a/src/Wetterhorn/FFI.hs
+++ b/src/Wetterhorn/FFI.hs
@@ -18,6 +18,13 @@ import Foreign
import Foreign.C (CChar)
import Wetterhorn.Core
+runForeign :: (WConfig -> W ()) -> Wetterhorn -> IO Wetterhorn
+runForeign fn stblptr = do
+ (conf, st) <- deRefStablePtr stblptr
+ freeStablePtr stblptr
+ (_, state') <- runW (fn conf) (conf, st)
+ newStablePtr (conf, state')
+
-- | This function should be defined somewhere in the code. This is kind of like
-- the "main" function in XMonad.
foreign import ccall wetterhorn :: IO Wetterhorn
@@ -59,3 +66,10 @@ pluginMarshalState stblptr outlen = do
forM_ (zip [0 ..] (BS.unpack bs)) $ \(off, w8) -> do
pokeByteOff ret off w8
return ret
+
+foreign export ccall "plugin_handle_keybinding"
+ pluginHandleKeybinding ::
+ Word32 -> Wetterhorn -> IO Wetterhorn
+
+pluginHandleKeybinding :: Word32 -> Wetterhorn -> IO Wetterhorn
+pluginHandleKeybinding sym = runForeign (`keybindingHandler` sym)