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

33 lines
979 B
Haskell
Raw Normal View History

{-# LANGUAGE OverloadedStrings #-}
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
, addMatchCallback
) where
2020-04-01 20:17:47 -04:00
import DBus
import DBus.Client
-- TODO export the bus name (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
-- TODO handle clienterrors here
reply <- call client mc { methodCallDestination = Just "org.xmonad" }
2020-04-01 22:06:00 -04:00
-- TODO not all methods warrent that we wait for a reply?
disconnect client
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