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
|
2021-11-21 22:47:43 -05:00
|
|
|
, getDBusClient
|
2021-11-23 18:28:38 -05:00
|
|
|
, withDBusClient
|
|
|
|
, withDBusClient_
|
2020-04-01 20:17:47 -04:00
|
|
|
, stopXMonadService
|
2021-11-21 22:47:43 -05:00
|
|
|
, disconnect
|
2022-06-16 18:50:24 -04:00
|
|
|
, dbusExporters
|
2020-04-01 20:17:47 -04:00
|
|
|
) where
|
2020-03-20 00:51:36 -04:00
|
|
|
|
2021-11-20 15:20:22 -05:00
|
|
|
import Control.Monad (forM_, void)
|
|
|
|
|
2021-06-21 23:41:57 -04:00
|
|
|
import DBus
|
2020-03-28 14:44:50 -04:00
|
|
|
import DBus.Client
|
2021-11-27 01:02:22 -05:00
|
|
|
import DBus.Internal
|
2020-03-20 00:51:36 -04:00
|
|
|
|
2021-11-21 00:42:40 -05:00
|
|
|
import XMonad.Internal.DBus.Brightness.ClevoKeyboard
|
2021-11-20 15:20:22 -05:00
|
|
|
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 15:20:22 -05:00
|
|
|
import XMonad.Internal.Dependency
|
2020-04-01 20:17:47 -04:00
|
|
|
|
2021-11-20 15:20:22 -05:00
|
|
|
startXMonadService :: IO (Maybe Client)
|
2020-03-20 00:51:36 -04:00
|
|
|
startXMonadService = do
|
2021-11-21 22:47:43 -05:00
|
|
|
client <- getDBusClient False
|
|
|
|
forM_ client requestXMonadName
|
2022-06-21 00:56:42 -04:00
|
|
|
mapM_ (\f -> executeSometimes_ $ f client) dbusExporters
|
2021-11-20 12:40:53 -05:00
|
|
|
return client
|
2020-03-20 00:51:36 -04:00
|
|
|
|
|
|
|
stopXMonadService :: Client -> IO ()
|
|
|
|
stopXMonadService client = do
|
2021-11-20 19:35:24 -05:00
|
|
|
void $ releaseName client xmonadBusName
|
2020-03-20 00:51:36 -04:00
|
|
|
disconnect client
|
2021-11-20 15:20:22 -05:00
|
|
|
|
|
|
|
requestXMonadName :: Client -> IO ()
|
|
|
|
requestXMonadName client = do
|
2021-11-20 19:35:24 -05:00
|
|
|
res <- requestName client xmonadBusName []
|
2021-11-21 00:42:40 -05:00
|
|
|
-- TODO if the client is not released on shutdown the owner will be different
|
2021-11-20 15:20:22 -05:00
|
|
|
let msg | res == NamePrimaryOwner = Nothing
|
|
|
|
| res == NameAlreadyOwner = Just $ "this process already owns " ++ xn
|
|
|
|
| res == NameInQueue
|
|
|
|
|| res == NameExists = Just $ "another process owns " ++ xn
|
|
|
|
| otherwise = Just $ "unknown error when requesting " ++ xn
|
|
|
|
forM_ msg putStrLn
|
|
|
|
where
|
2021-11-20 19:35:24 -05:00
|
|
|
xn = "'" ++ formatBusName xmonadBusName ++ "'"
|
2022-06-16 18:50:24 -04:00
|
|
|
|
2022-06-21 00:56:42 -04:00
|
|
|
dbusExporters :: [Maybe Client -> SometimesIO]
|
2022-06-16 18:50:24 -04:00
|
|
|
dbusExporters = [exportScreensaver, exportIntelBacklight, exportClevoKeyboard]
|