REF make this function not hurt to look at

This commit is contained in:
Nathan Dwarshuis 2020-03-17 23:24:44 -04:00
parent 5b572277ae
commit 3b9b98a1f6
1 changed files with 26 additions and 26 deletions

View File

@ -7,11 +7,11 @@ import ACPI
import SendXMsg import SendXMsg
import qualified Theme as T import qualified Theme as T
import Control.Monad (foldM, mapM_, forM_, void, when) import Control.Monad (mapM_, forM, forM_, void, when)
import Data.List (find, sortBy, sortOn) import Data.List (find, sortBy, sortOn)
import qualified Data.Map.Lazy as M import qualified Data.Map.Lazy as M
import Data.Maybe (isJust) import Data.Maybe (isJust, catMaybes)
import Data.Monoid (All(..)) import Data.Monoid (All(..))
import Graphics.X11.Xlib.Atom import Graphics.X11.Xlib.Atom
@ -345,35 +345,35 @@ myDmenuCmd = "rofi"
-- TODO simplify the convoluted garbage heap...to be fair, this is -- TODO simplify the convoluted garbage heap...to be fair, this is
-- going to be ugly simply because rofi uses xrandr and xmonad uses -- going to be ugly simply because rofi uses xrandr and xmonad uses
-- xinerama to get screen information...and apparently these index -- xinerama to get screen information...and apparently these index
-- differently. However, I'm sure there's a way to condense this code -- differently.
-- to something more sane :(
getMonitorName :: X (Maybe String) getMonitorName :: X (Maybe String)
getMonitorName = do getMonitorName = do
dpy <- asks display dpy <- asks display
root <- asks theRoot root <- asks theRoot
res <- io $ xrrGetScreenResourcesCurrent dpy root -- these are the focused screen coordinates according to xinerama
outputs <- io $ case res of (sx, sy) <- getCoords
Just res' -> foldM (procOutput dpy res') [] $ xrr_sr_outputs res' io $ do
Nothing -> return [] res <- xrrGetScreenResourcesCurrent dpy root
(Rectangle sx sy _ _) <- getFocusedScreen outputs <- forM res $ \res' ->
return $ case find (\(_, x, y) -> x == fromIntegral sx && y == fromIntegral sy) outputs of forM (xrr_sr_outputs res') $ \output -> do
Just (name, _, _) -> Just name oi <- xrrGetOutputInfo dpy res' output
Nothing -> Nothing
where
procOutput dpy res acc output = do
oi <- xrrGetOutputInfo dpy res output
case oi of case oi of
Just oi' -> procResources dpy res acc oi' -- connection: 0 == connected, 1 == disconnected
Nothing -> return acc Just XRROutputInfo { xrr_oi_connection = 0
procResources dpy res acc oi = do , xrr_oi_name = name
let name = xrr_oi_name oi , xrr_oi_crtc = crtc
-- 0 = connected; 1 = disconnected } -> do
if xrr_oi_connection oi == 0 then do ci <- xrrGetCrtcInfo dpy res' crtc
ci <- xrrGetCrtcInfo dpy res $ xrr_oi_crtc oi return $ (\ci' -> Just (name, xrr_ci_x ci', xrr_ci_y ci'))
return $ case ci of =<< ci
Just ci' -> (name, xrr_ci_x ci', xrr_ci_y ci') : acc _ -> return Nothing
Nothing -> acc return $ (\(name, _, _) -> Just name)
else return acc =<< find (\(_, x, y) -> x == sx && y == sy) . catMaybes
=<< outputs
where
getCoords = do
(Rectangle x y _ _) <- getFocusedScreen
return (fromIntegral x, fromIntegral y)
spawnDmenuCmd :: [String] -> X () spawnDmenuCmd :: [String] -> X ()
spawnDmenuCmd args = do spawnDmenuCmd args = do