xmonad-config/lib/XMonad/Internal/DBus/Common.hs

39 lines
1.1 KiB
Haskell
Raw Normal View History

2020-04-01 22:06:00 -04:00
--------------------------------------------------------------------------------
-- | Common internal DBus functions
2020-04-01 20:17:47 -04:00
module XMonad.Internal.DBus.Common
( callMethod
, callMethod'
2020-04-01 20:17:47 -04:00
, addMatchCallback
, xmonadBus
2020-04-01 20:17:47 -04:00
) where
2020-04-01 20:17:47 -04:00
import DBus
import DBus.Client
xmonadBus :: BusName
xmonadBus = busName_ "org.xmonad"
2020-04-01 22:06:00 -04:00
-- | Call a method and return its result if successful
callMethod :: MethodCall -> IO (Maybe [Variant])
callMethod mc = do
client <- connectSession
r <- callMethod' client (Just xmonadBus) mc
disconnect client
return r
callMethod' :: Client -> Maybe BusName -> MethodCall -> IO (Maybe [Variant])
callMethod' client bn mc = do
-- TODO handle clienterrors here
reply <- call client mc { methodCallDestination = bn }
-- TODO not all methods warrant that we wait for a reply? (see callNoReply)
return $ case reply of
Left _ -> Nothing
Right ret -> Just $ methodReturnBody ret
2020-04-01 22:06:00 -04:00
-- | Bind a callback to a signal match rule
addMatchCallback :: MatchRule -> ([Variant] -> IO ()) -> IO SignalHandler
addMatchCallback rule cb = do
client <- connectSession
addMatch client rule $ cb . signalBody