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

58 lines
1.7 KiB
Haskell
Raw Normal View History

{-# LANGUAGE ScopedTypeVariables #-}
2020-03-20 00:51:36 -04:00
2020-04-01 22:06:00 -04:00
--------------------------------------------------------------------------------
-- | High-level interface for managing XMonad's DBus
2020-04-01 20:17:47 -04:00
module XMonad.Internal.DBus.Control
( Client
, startXMonadService
2020-04-01 20:17:47 -04:00
, stopXMonadService
, pathExists
, xmonadBus
2020-04-01 20:17:47 -04:00
) where
2020-03-20 00:51:36 -04:00
import Data.Either
import DBus
import DBus.Client
2020-03-20 00:51:36 -04:00
import XMonad.Internal.DBus.Common
2020-04-01 20:17:47 -04:00
import XMonad.Internal.DBus.IntelBacklight
import XMonad.Internal.DBus.Screensaver
import XMonad.Internal.Shell
2020-04-01 20:17:47 -04:00
introspectInterface :: InterfaceName
introspectInterface = interfaceName_ "org.freedesktop.DBus.Introspectable"
introspectMethod :: MemberName
introspectMethod = memberName_ "Introspect"
startXMonadService :: IO (Client, Maybe BacklightControls, MaybeExe SSControls)
2020-03-20 00:51:36 -04:00
startXMonadService = do
client <- connectSession
requestResult <- requestName client xmonadBus []
2020-03-20 00:51:36 -04:00
-- TODO if the client is not released on shutdown the owner will be
-- different
if requestResult /= NamePrimaryOwner then do
2020-03-20 00:51:36 -04:00
putStrLn "Another service owns \"org.xmonad\""
return (client, Nothing, Ignore)
2020-03-20 00:51:36 -04:00
else do
putStrLn "Started xmonad dbus client"
bc <- exportIntelBacklight client
sc <- exportScreensaver client
return (client, bc, sc)
2020-03-20 00:51:36 -04:00
stopXMonadService :: Client -> IO ()
stopXMonadService client = do
_ <- releaseName client xmonadBus
2020-03-20 00:51:36 -04:00
disconnect client
return ()
pathExists :: Bool -> BusName -> ObjectPath -> IO Bool
pathExists sysbus n p = do
client <- if sysbus then connectSystem else connectSession
r <- call client (methodCall p introspectInterface introspectMethod)
{ methodCallDestination = Just n }
disconnect client
return $ isRight r