REF bracket display lookup
This commit is contained in:
parent
6acd60187e
commit
05ecda045e
17
app/rofi.hs
17
app/rofi.hs
|
@ -34,18 +34,14 @@ import UnliftIO.Environment
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = runSimpleApp $ do
|
main = runSimpleApp $ do
|
||||||
r <- getMonitorName
|
|
||||||
args <- getArgs
|
args <- getArgs
|
||||||
let allArgs = maybe [] (\n -> ["-m", T.unpack n] ++ args) r
|
pre <- maybe [] (\n -> ["-m", T.unpack n]) <$> getMonitorName
|
||||||
c <- proc "/usr/bin/rofi" allArgs runProcess
|
exitWith =<< proc "/usr/bin/rofi" (pre ++ args) runProcess
|
||||||
exitWith c
|
|
||||||
|
|
||||||
data Coord = Coord Int Int deriving (Eq, Show)
|
data Coord = Coord Int Int deriving (Eq, Show)
|
||||||
|
|
||||||
-- TODO bracket this
|
|
||||||
getMonitorName :: MonadIO m => m (Maybe T.Text)
|
getMonitorName :: MonadIO m => m (Maybe T.Text)
|
||||||
getMonitorName = liftIO $ do
|
getMonitorName = liftIO $ withOpenDisplay $ \dpy -> do
|
||||||
dpy <- openDisplay ""
|
|
||||||
root <- rootWindow dpy $ defaultScreen dpy
|
root <- rootWindow dpy $ defaultScreen dpy
|
||||||
index <- getCurrentDesktopIndex dpy root
|
index <- getCurrentDesktopIndex dpy root
|
||||||
viewports <- getDesktopViewports dpy root
|
viewports <- getDesktopViewports dpy root
|
||||||
|
@ -97,3 +93,10 @@ getAtom32 dpy root str = do
|
||||||
a <- internAtom dpy (T.unpack str) False
|
a <- internAtom dpy (T.unpack str) False
|
||||||
p <- getWindowProperty32 dpy a root
|
p <- getWindowProperty32 dpy a root
|
||||||
return $ maybe [] (fmap fromIntegral) p
|
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
|
||||||
|
|
Loading…
Reference in New Issue