2021-06-21 23:41:57 -04:00
|
|
|
{-# 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
|
2020-03-28 14:44:50 -04:00
|
|
|
( Client
|
|
|
|
, startXMonadService
|
2020-04-01 20:17:47 -04:00
|
|
|
, stopXMonadService
|
2021-06-21 23:41:57 -04:00
|
|
|
, pathExists
|
|
|
|
, xmonadBus
|
2021-11-07 13:35:08 -05:00
|
|
|
, DBusXMonad(..)
|
2020-04-01 20:17:47 -04:00
|
|
|
) where
|
2020-03-20 00:51:36 -04:00
|
|
|
|
2021-06-21 23:41:57 -04:00
|
|
|
import Data.Either
|
|
|
|
|
|
|
|
import DBus
|
2020-03-28 14:44:50 -04:00
|
|
|
import DBus.Client
|
2020-03-20 00:51:36 -04:00
|
|
|
|
2021-11-07 13:35:08 -05:00
|
|
|
import XMonad.Internal.DBus.Brightness.Common
|
|
|
|
import XMonad.Internal.DBus.Brightness.IntelBacklight
|
2021-06-21 23:41:57 -04:00
|
|
|
import XMonad.Internal.DBus.Common
|
2020-04-01 20:17:47 -04:00
|
|
|
import XMonad.Internal.DBus.Screensaver
|
2021-11-20 01:15:04 -05:00
|
|
|
import XMonad.Internal.Dependency
|
2020-04-01 20:17:47 -04:00
|
|
|
|
2021-06-21 23:41:57 -04:00
|
|
|
introspectInterface :: InterfaceName
|
|
|
|
introspectInterface = interfaceName_ "org.freedesktop.DBus.Introspectable"
|
|
|
|
|
|
|
|
introspectMethod :: MemberName
|
|
|
|
introspectMethod = memberName_ "Introspect"
|
|
|
|
|
2021-11-07 13:35:08 -05:00
|
|
|
data DBusXMonad = DBusXMonad
|
|
|
|
{ dxClient :: Client
|
2021-11-07 18:41:25 -05:00
|
|
|
, dxIntelBacklightCtrl :: BrightnessControls
|
|
|
|
-- , dxClevoBacklightCtrl :: MaybeExe BrightnessControls
|
2021-11-08 00:27:39 -05:00
|
|
|
, dxScreensaverCtrl :: SSControls
|
2021-11-07 13:35:08 -05:00
|
|
|
}
|
|
|
|
|
2021-11-07 18:41:25 -05:00
|
|
|
blankControls :: BrightnessControls
|
|
|
|
blankControls = BrightnessControls
|
2021-11-20 01:15:04 -05:00
|
|
|
{ bctlMax = BlankFeature
|
|
|
|
, bctlMin = BlankFeature
|
|
|
|
, bctlInc = BlankFeature
|
|
|
|
, bctlDec = BlankFeature
|
2021-11-07 18:41:25 -05:00
|
|
|
}
|
|
|
|
|
2021-11-08 00:27:39 -05:00
|
|
|
blankSSToggle :: SSControls
|
2021-11-20 01:15:04 -05:00
|
|
|
blankSSToggle = SSControls { ssToggle = BlankFeature }
|
2021-11-08 00:27:39 -05:00
|
|
|
|
2021-11-07 13:35:08 -05:00
|
|
|
startXMonadService :: IO DBusXMonad
|
2020-03-20 00:51:36 -04:00
|
|
|
startXMonadService = do
|
|
|
|
client <- connectSession
|
2021-06-21 23:41:57 -04:00
|
|
|
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
|
2021-11-07 18:41:25 -05:00
|
|
|
(i, s) <- if requestResult /= NamePrimaryOwner then do
|
2020-03-20 00:51:36 -04:00
|
|
|
putStrLn "Another service owns \"org.xmonad\""
|
2021-11-08 00:27:39 -05:00
|
|
|
return (blankControls, blankSSToggle)
|
2021-11-07 13:35:08 -05:00
|
|
|
else do
|
2020-03-20 00:51:36 -04:00
|
|
|
putStrLn "Started xmonad dbus client"
|
2021-06-20 20:54:23 -04:00
|
|
|
bc <- exportIntelBacklight client
|
2021-06-20 22:26:58 -04:00
|
|
|
sc <- exportScreensaver client
|
2021-11-07 18:41:25 -05:00
|
|
|
return (bc, sc)
|
2021-11-07 13:35:08 -05:00
|
|
|
return $ DBusXMonad
|
|
|
|
{ dxClient = client
|
|
|
|
, dxIntelBacklightCtrl = i
|
2021-11-07 18:41:25 -05:00
|
|
|
-- , dxClevoBacklightCtrl = c
|
2021-11-07 13:35:08 -05:00
|
|
|
, dxScreensaverCtrl = s
|
|
|
|
}
|
2020-03-20 00:51:36 -04:00
|
|
|
|
|
|
|
stopXMonadService :: Client -> IO ()
|
|
|
|
stopXMonadService client = do
|
2021-06-21 23:41:57 -04:00
|
|
|
_ <- releaseName client xmonadBus
|
2020-03-20 00:51:36 -04:00
|
|
|
disconnect client
|
|
|
|
return ()
|
|
|
|
|
2021-06-21 23:41:57 -04:00
|
|
|
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
|