-
Notifications
You must be signed in to change notification settings - Fork 1
/
Tutorial2.hs
38 lines (32 loc) · 1.3 KB
/
Tutorial2.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
-- | https://docs.pipewire.org/tutorial2_8c-example.html
module Main (main) where
import Control.Concurrent (forkIO, threadDelay)
import Pipewire qualified as PW
main :: IO ()
main =
PW.withPipewire $
PW.withMainLoop $ \mainLoop -> do
loop <- PW.pw_main_loop_get_loop mainLoop
PW.withContext loop \context ->
PW.withCore context (go mainLoop)
where
go mainLoop core = do
registry <- PW.pw_core_get_registry core
-- _stopAfterTimeout mainLoop
PW.withSpaHook \registryListener -> do
PW.withRegistryEvents handler removeHandler \registryEvent -> do
PW.pw_registry_add_listener registry registryListener registryEvent
PW.pw_main_loop_run mainLoop
putStrLn "Done!"
removeHandler pwid = do
putStrLn $ "remove: " <> show pwid
handler pwid typ version propsDict = do
props <- PW.spaDictRead propsDict
putStrLn $ "object: id:" <> show pwid <> " type:" <> show typ <> " version:" <> show version
mapM_ print props
_stopAfterTimeout mainLoop =
print =<< forkIO do
putStrLn "Waiting 2sec before stopping the loop"
threadDelay 2_000_000
putStrLn "Quitting the loop"
PW.pw_main_loop_quit mainLoop