From 3b8c6b0f4f64bcad5c90f8e5d80b27ae797f765b Mon Sep 17 00:00:00 2001 From: ndwarshuis Date: Sat, 31 Dec 2022 22:31:23 -0500 Subject: [PATCH] ENH use dbus bracket for xmobar --- bin/xmobar.hs | 4 +--- lib/XMonad/Internal/DBus/Control.hs | 8 ++++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/bin/xmobar.hs b/bin/xmobar.hs index 45c6c5e..936a01c 100644 --- a/bin/xmobar.hs +++ b/bin/xmobar.hs @@ -50,10 +50,8 @@ parse ["--test"] = void $ withCache . evalConfig =<< connectDBus parse _ = usage run :: IO () -run = withCache $ do - db <- connectDBus +run = withCache $ withDBus_ $ \db -> do c <- evalConfig db - disconnectDBus db liftIO $ do -- this is needed to see any printed messages hFlush stdout diff --git a/lib/XMonad/Internal/DBus/Control.hs b/lib/XMonad/Internal/DBus/Control.hs index 0f43ac4..ac4f892 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 (..) + , withDBus + , withDBus_ , connectDBus , connectDBusX , disconnectDBus @@ -34,6 +36,12 @@ data DBusState = DBusState , dbSysClient :: Maybe SysClient } +withDBus_ :: MonadUnliftIO m => (DBusState -> m a) -> m () +withDBus_ = void . withDBus + +withDBus :: MonadUnliftIO m => (DBusState -> m a) -> m a +withDBus = bracket connectDBus disconnectDBus + -- | Connect to the DBus connectDBus :: MonadUnliftIO m => m DBusState connectDBus = do