{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE TypeApplications #-}
module XMonad.Hooks.StatusBar.WorkspaceScreen
(
combineWithScreen
, combineWithScreenName
, combineWithScreenNumber
, WorkspaceScreenCombiner
) where
import Graphics.X11.Xrandr
import XMonad
import XMonad.Hooks.StatusBar.PP
import XMonad.Prelude
import qualified XMonad.StackSet as W
type WorkspaceScreenCombiner = WorkspaceId -> WindowScreen -> String
screenNames :: X [Maybe String]
screenNames :: X [Maybe WorkspaceId]
screenNames = do
XConf { display, theRoot } <- X XConf
forall r (m :: * -> *). MonadReader r m => m r
ask
let getName XRRMonitorInfo
mi = Display -> Window -> IO (Maybe WorkspaceId)
getAtomName Display
display (XRRMonitorInfo -> Window
xrr_moninf_name XRRMonitorInfo
mi)
io
$ maybe (pure []) (traverse getName)
=<< xrrGetMonitors display theRoot True
combineWithScreenName :: (WorkspaceId -> String -> String) -> PP -> X PP
combineWithScreenName :: (WorkspaceId -> WorkspaceId -> WorkspaceId) -> PP -> X PP
combineWithScreenName WorkspaceId -> WorkspaceId -> WorkspaceId
c = X WorkspaceScreenCombiner -> PP -> X PP
combineWithScreen (X WorkspaceScreenCombiner -> PP -> X PP)
-> X WorkspaceScreenCombiner -> PP -> X PP
forall a b. (a -> b) -> a -> b
$ do
screens <- X [Maybe WorkspaceId]
screenNames
return $ \WorkspaceId
w WindowScreen
sc -> WorkspaceId
-> (WorkspaceId -> WorkspaceId) -> Maybe WorkspaceId -> WorkspaceId
forall b a. b -> (a -> b) -> Maybe a -> b
maybe WorkspaceId
w (WorkspaceId -> WorkspaceId -> WorkspaceId
c WorkspaceId
w) (Maybe WorkspaceId -> WorkspaceId)
-> Maybe WorkspaceId -> WorkspaceId
forall a b. (a -> b) -> a -> b
$ Maybe (Maybe WorkspaceId) -> Maybe WorkspaceId
forall (m :: * -> *) a. Monad m => m (m a) -> m a
join ([Maybe WorkspaceId]
screens [Maybe WorkspaceId] -> Int -> Maybe (Maybe WorkspaceId)
forall a. [a] -> Int -> Maybe a
!? ScreenId -> Int
forall a b. (Integral a, Num b) => a -> b
fi (WindowScreen -> ScreenId
forall i l a sid sd. Screen i l a sid sd -> sid
W.screen WindowScreen
sc))
combineWithScreenNumber :: (WorkspaceId -> String -> String) -> PP -> X PP
combineWithScreenNumber :: (WorkspaceId -> WorkspaceId -> WorkspaceId) -> PP -> X PP
combineWithScreenNumber WorkspaceId -> WorkspaceId -> WorkspaceId
c =
X WorkspaceScreenCombiner -> PP -> X PP
combineWithScreen (X WorkspaceScreenCombiner -> PP -> X PP)
-> (WorkspaceScreenCombiner -> X WorkspaceScreenCombiner)
-> WorkspaceScreenCombiner
-> PP
-> X PP
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WorkspaceScreenCombiner -> X WorkspaceScreenCombiner
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (WorkspaceScreenCombiner -> PP -> X PP)
-> WorkspaceScreenCombiner -> PP -> X PP
forall a b. (a -> b) -> a -> b
$ \WorkspaceId
w WindowScreen
sc -> WorkspaceId -> WorkspaceId -> WorkspaceId
c WorkspaceId
w (forall a. Show a => a -> WorkspaceId
show @Int (Int -> WorkspaceId)
-> (WindowScreen -> Int) -> WindowScreen -> WorkspaceId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ScreenId -> Int
forall a b. (Integral a, Num b) => a -> b
fi (ScreenId -> Int)
-> (WindowScreen -> ScreenId) -> WindowScreen -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowScreen -> ScreenId
forall i l a sid sd. Screen i l a sid sd -> sid
W.screen (WindowScreen -> WorkspaceId) -> WindowScreen -> WorkspaceId
forall a b. (a -> b) -> a -> b
$ WindowScreen
sc)
combineWithScreen :: X WorkspaceScreenCombiner -> PP -> X PP
combineWithScreen :: X WorkspaceScreenCombiner -> PP -> X PP
combineWithScreen X WorkspaceScreenCombiner
xCombiner PP
pp = do
combiner <- X WorkspaceScreenCombiner
xCombiner
ss <- withWindowSet (return . W.screens)
return $ pp
{ ppRename = ppRename pp <=< \WorkspaceId
s WindowSpace
w ->
WorkspaceId
-> (WindowScreen -> WorkspaceId)
-> Maybe WindowScreen
-> WorkspaceId
forall b a. b -> (a -> b) -> Maybe a -> b
maybe WorkspaceId
s (WorkspaceScreenCombiner
combiner WorkspaceId
s) ((WindowScreen -> Bool) -> [WindowScreen] -> Maybe WindowScreen
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find ((WorkspaceId -> WorkspaceId -> Bool
forall a. Eq a => a -> a -> Bool
== WindowSpace -> WorkspaceId
forall i l a. Workspace i l a -> i
W.tag WindowSpace
w) (WorkspaceId -> Bool)
-> (WindowScreen -> WorkspaceId) -> WindowScreen -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowSpace -> WorkspaceId
forall i l a. Workspace i l a -> i
W.tag (WindowSpace -> WorkspaceId)
-> (WindowScreen -> WindowSpace) -> WindowScreen -> WorkspaceId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowScreen -> WindowSpace
forall i l a sid sd. Screen i l a sid sd -> Workspace i l a
W.workspace) [WindowScreen]
ss)
}