REF bracket display lookup

This commit is contained in:
Nathan Dwarshuis 2023-02-16 22:53:00 -05:00
parent 6acd60187e
commit 05ecda045e
1 changed files with 10 additions and 7 deletions

View File

@ -34,18 +34,14 @@ import UnliftIO.Environment
main :: IO ()
main = runSimpleApp $ do
r <- getMonitorName
args <- getArgs
let allArgs = maybe [] (\n -> ["-m", T.unpack n] ++ args) r
c <- proc "/usr/bin/rofi" allArgs runProcess
exitWith c
pre <- maybe [] (\n -> ["-m", T.unpack n]) <$> getMonitorName
exitWith =<< proc "/usr/bin/rofi" (pre ++ args) runProcess
data Coord = Coord Int Int deriving (Eq, Show)
-- TODO bracket this
getMonitorName :: MonadIO m => m (Maybe T.Text)
getMonitorName = liftIO $ do
dpy <- openDisplay ""
getMonitorName = liftIO $ withOpenDisplay $ \dpy -> do
root <- rootWindow dpy $ defaultScreen dpy
index <- getCurrentDesktopIndex dpy root
viewports <- getDesktopViewports dpy root
@ -97,3 +93,10 @@ getAtom32 dpy root str = do
a <- internAtom dpy (T.unpack str) False
p <- getWindowProperty32 dpy a root
return $ maybe [] (fmap fromIntegral) p
withOpenDisplay :: MonadUnliftIO m => (Display -> m a) -> m a
withOpenDisplay = bracket (liftIO $ openDisplay "") cleanup
where
cleanup dpy = liftIO $ do
flush dpy
closeDisplay dpy