REF make this function not hurt to look at
This commit is contained in:
parent
5b572277ae
commit
3b9b98a1f6
|
@ -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
|
case oi of
|
||||||
|
-- connection: 0 == connected, 1 == disconnected
|
||||||
|
Just XRROutputInfo { xrr_oi_connection = 0
|
||||||
|
, xrr_oi_name = name
|
||||||
|
, xrr_oi_crtc = crtc
|
||||||
|
} -> do
|
||||||
|
ci <- xrrGetCrtcInfo dpy res' crtc
|
||||||
|
return $ (\ci' -> Just (name, xrr_ci_x ci', xrr_ci_y ci'))
|
||||||
|
=<< ci
|
||||||
|
_ -> return Nothing
|
||||||
|
return $ (\(name, _, _) -> Just name)
|
||||||
|
=<< find (\(_, x, y) -> x == sx && y == sy) . catMaybes
|
||||||
|
=<< outputs
|
||||||
where
|
where
|
||||||
procOutput dpy res acc output = do
|
getCoords = do
|
||||||
oi <- xrrGetOutputInfo dpy res output
|
(Rectangle x y _ _) <- getFocusedScreen
|
||||||
case oi of
|
return (fromIntegral x, fromIntegral y)
|
||||||
Just oi' -> procResources dpy res acc oi'
|
|
||||||
Nothing -> return acc
|
|
||||||
procResources dpy res acc oi = do
|
|
||||||
let name = xrr_oi_name oi
|
|
||||||
-- 0 = connected; 1 = disconnected
|
|
||||||
if xrr_oi_connection oi == 0 then do
|
|
||||||
ci <- xrrGetCrtcInfo dpy res $ xrr_oi_crtc oi
|
|
||||||
return $ case ci of
|
|
||||||
Just ci' -> (name, xrr_ci_x ci', xrr_ci_y ci') : acc
|
|
||||||
Nothing -> acc
|
|
||||||
else return acc
|
|
||||||
|
|
||||||
spawnDmenuCmd :: [String] -> X ()
|
spawnDmenuCmd :: [String] -> X ()
|
||||||
spawnDmenuCmd args = do
|
spawnDmenuCmd args = do
|
||||||
|
|
Loading…
Reference in New Issue