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
|
2021-06-21 23:41:57 -04:00
|
|
|
, callMethod'
|
2020-04-01 20:17:47 -04:00
|
|
|
, addMatchCallback
|
2021-06-21 23:41:57 -04:00
|
|
|
, xmonadBus
|
2021-11-20 19:35:24 -05:00
|
|
|
, xmonadBusName
|
2021-11-20 11:48:05 -05:00
|
|
|
, xDbusDep
|
2021-11-20 19:35:24 -05:00
|
|
|
-- , initControls
|
2020-04-01 20:17:47 -04:00
|
|
|
) where
|
2020-03-20 20:10:15 -04:00
|
|
|
|
2020-04-01 20:17:47 -04:00
|
|
|
import DBus
|
|
|
|
import DBus.Client
|
|
|
|
|
2021-11-11 00:11:15 -05:00
|
|
|
import XMonad.Internal.Dependency
|
|
|
|
|
2021-11-20 19:35:24 -05:00
|
|
|
xmonadBusName :: BusName
|
|
|
|
xmonadBusName = busName_ "org.xmonad"
|
|
|
|
|
|
|
|
xmonadBus :: Bus
|
|
|
|
xmonadBus = Bus False xmonadBusName
|
2020-03-20 20:10:15 -04:00
|
|
|
|
2021-11-20 11:48:05 -05:00
|
|
|
xDbusDep :: ObjectPath -> InterfaceName -> DBusMember -> Dependency
|
2021-11-20 19:35:24 -05:00
|
|
|
xDbusDep o i m = DBusEndpoint xmonadBus $ Endpoint o i m
|
|
|
|
|
|
|
|
-- connectBus :: Bus -> IO (Maybe Client)
|
2021-11-20 11:48:05 -05:00
|
|
|
|
2020-04-01 22:06:00 -04:00
|
|
|
-- | Call a method and return its result if successful
|
2020-03-20 23:47:02 -04:00
|
|
|
callMethod :: MethodCall -> IO (Maybe [Variant])
|
|
|
|
callMethod mc = do
|
|
|
|
client <- connectSession
|
2021-11-20 19:35:24 -05:00
|
|
|
r <- callMethod' client (Just xmonadBusName) mc
|
2021-06-20 22:27:16 -04:00
|
|
|
disconnect client
|
2021-06-21 23:41:57 -04:00
|
|
|
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)
|
2020-03-20 20:10:15 -04:00
|
|
|
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
|
2020-03-20 20:10:15 -04:00
|
|
|
addMatchCallback :: MatchRule -> ([Variant] -> IO ()) -> IO SignalHandler
|
|
|
|
addMatchCallback rule cb = do
|
|
|
|
client <- connectSession
|
2021-06-20 22:27:16 -04:00
|
|
|
addMatch client rule $ cb . signalBody
|
2021-11-11 00:11:15 -05:00
|
|
|
|
2021-11-20 19:35:24 -05:00
|
|
|
-- initControls :: Client -> (Client -> FeatureIO) -> (FeatureIO -> a) -> IO a
|
|
|
|
-- initControls client exporter controls = do
|
|
|
|
-- let x = exporter client
|
|
|
|
-- e <- evalFeature x
|
|
|
|
-- case e of
|
|
|
|
-- (Right c) -> c
|
|
|
|
-- _ -> return ()
|
|
|
|
-- return $ controls x
|