From 4951c2a35ed46c2d3b8ed0231e62e471228f2d20 Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Sat, 31 Dec 2022 22:47:36 -0500 Subject: [PATCH] ENH use bracket for request/release busname --- bin/xmonad.hs | 14 +++++++------- lib/XMonad/Internal/DBus/Control.hs | 10 ++++++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/bin/xmonad.hs b/bin/xmonad.hs index b9a525a..5c06402 100644 --- a/bin/xmonad.hs +++ b/bin/xmonad.hs @@ -89,7 +89,7 @@ run = do uninstallSignalHandlers hSetBuffering stdout LineBuffering withCache $ do - withDBusX $ \db -> do + withDBusX_ $ \db -> do let sys = dbSysClient db let fs = features sys startDBusInterfaces db fs @@ -204,12 +204,12 @@ startXmobar = do startChildDaemons :: FeatureSet -> FIO [Process () () ()] startChildDaemons fs = catMaybes <$> mapM executeSometimes (fsDaemons fs) -withDBusX :: (DBusState -> FIO a) -> FIO a -withDBusX = bracket (io connectDBusX) cleanup - where - cleanup db = do - logInfo "unregistering xmonad from DBus" - io $ disconnectDBus db +-- withDBusX :: (DBusState -> FIO a) -> FIO a +-- withDBusX = bracket (io connectDBusX) cleanup +-- where +-- cleanup db = do +-- logInfo "unregistering xmonad from DBus" +-- io $ disconnectDBus db withChildDaemons :: FeatureSet -> ([Process () () ()] -> FIO a) -> FIO a withChildDaemons fs = bracket (startChildDaemons fs) cleanup diff --git a/lib/XMonad/Internal/DBus/Control.hs b/lib/XMonad/Internal/DBus/Control.hs index ac4f892..0013fa7 100644 --- a/lib/XMonad/Internal/DBus/Control.hs +++ b/lib/XMonad/Internal/DBus/Control.hs @@ -6,6 +6,8 @@ module XMonad.Internal.DBus.Control ( Client , DBusState (..) + , withDBusX + , withDBusX_ , withDBus , withDBus_ , connectDBus @@ -36,6 +38,14 @@ data DBusState = DBusState , dbSysClient :: Maybe SysClient } +withDBusX_ :: MonadUnliftIO m => (DBusState -> m a) -> m () +withDBusX_ = void . withDBusX + +withDBusX :: MonadUnliftIO m => (DBusState -> m a) -> m (Maybe a) +withDBusX f = withDBus $ \db -> do + forM (dbSesClient db) $ \ses -> do + bracket_ (requestXMonadName ses) (releaseXMonadName ses) $ f db + withDBus_ :: MonadUnliftIO m => (DBusState -> m a) -> m () withDBus_ = void . withDBus