module XMonad.Util.ClickableWorkspaces (
clickablePP,
clickableWrap,
) where
import XMonad.Prelude ((<&>), (>=>))
import XMonad
import XMonad.Hooks.StatusBar.PP (xmobarAction, PP(..))
import XMonad.Util.WorkspaceCompare (getSortByIndex)
import qualified XMonad.StackSet as W
import Data.List (elemIndex)
clickableWrap :: Int -> String -> String
clickableWrap :: Int -> WorkspaceId -> WorkspaceId
clickableWrap Int
i = WorkspaceId -> WorkspaceId -> WorkspaceId -> WorkspaceId
xmobarAction (WorkspaceId
"xdotool set_desktop " WorkspaceId -> WorkspaceId -> WorkspaceId
forall a. [a] -> [a] -> [a]
++ Int -> WorkspaceId
forall a. Show a => a -> WorkspaceId
show Int
i) WorkspaceId
"1"
getWsIndex :: X (WorkspaceId -> Maybe Int)
getWsIndex :: X (WorkspaceId -> Maybe Int)
getWsIndex = do
WorkspaceSort
wSort <- X WorkspaceSort
getSortByIndex
[WorkspaceId]
spaces <- (XState -> [WorkspaceId]) -> X [WorkspaceId]
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets ((WindowSpace -> WorkspaceId) -> [WindowSpace] -> [WorkspaceId]
forall a b. (a -> b) -> [a] -> [b]
map WindowSpace -> WorkspaceId
forall i l a. Workspace i l a -> i
W.tag ([WindowSpace] -> [WorkspaceId])
-> (XState -> [WindowSpace]) -> XState -> [WorkspaceId]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WorkspaceSort
wSort WorkspaceSort
-> (XState -> [WindowSpace]) -> XState -> [WindowSpace]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> [WindowSpace]
forall i l a s sd. StackSet i l a s sd -> [Workspace i l a]
W.workspaces (StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> [WindowSpace])
-> (XState
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> XState
-> [WindowSpace]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XState
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
windowset)
(WorkspaceId -> Maybe Int) -> X (WorkspaceId -> Maybe Int)
forall (m :: * -> *) a. Monad m => a -> m a
return ((WorkspaceId -> Maybe Int) -> X (WorkspaceId -> Maybe Int))
-> (WorkspaceId -> Maybe Int) -> X (WorkspaceId -> Maybe Int)
forall a b. (a -> b) -> a -> b
$ (WorkspaceId -> [WorkspaceId] -> Maybe Int)
-> [WorkspaceId] -> WorkspaceId -> Maybe Int
forall a b c. (a -> b -> c) -> b -> a -> c
flip WorkspaceId -> [WorkspaceId] -> Maybe Int
forall a. Eq a => a -> [a] -> Maybe Int
elemIndex [WorkspaceId]
spaces
getClickable :: X (String -> WindowSpace -> String)
getClickable :: X (WorkspaceId -> WindowSpace -> WorkspaceId)
getClickable = X (WorkspaceId -> Maybe Int)
getWsIndex X (WorkspaceId -> Maybe Int)
-> ((WorkspaceId -> Maybe Int)
-> WorkspaceId -> WindowSpace -> WorkspaceId)
-> X (WorkspaceId -> WindowSpace -> WorkspaceId)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \WorkspaceId -> Maybe Int
idx WorkspaceId
s WindowSpace
w -> (WorkspaceId -> WorkspaceId)
-> (Int -> WorkspaceId -> WorkspaceId)
-> Maybe Int
-> WorkspaceId
-> WorkspaceId
forall b a. b -> (a -> b) -> Maybe a -> b
maybe WorkspaceId -> WorkspaceId
forall a. a -> a
id Int -> WorkspaceId -> WorkspaceId
clickableWrap (WorkspaceId -> Maybe Int
idx (WindowSpace -> WorkspaceId
forall i l a. Workspace i l a -> i
W.tag WindowSpace
w)) WorkspaceId
s
clickablePP :: PP -> X PP
clickablePP :: PP -> X PP
clickablePP PP
pp = X (WorkspaceId -> WindowSpace -> WorkspaceId)
getClickable X (WorkspaceId -> WindowSpace -> WorkspaceId)
-> ((WorkspaceId -> WindowSpace -> WorkspaceId) -> PP) -> X PP
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \WorkspaceId -> WindowSpace -> WorkspaceId
ren -> PP
pp{ ppRename :: WorkspaceId -> WindowSpace -> WorkspaceId
ppRename = PP -> WorkspaceId -> WindowSpace -> WorkspaceId
ppRename PP
pp (WorkspaceId -> WindowSpace -> WorkspaceId)
-> (WorkspaceId -> WindowSpace -> WorkspaceId)
-> WorkspaceId
-> WindowSpace
-> WorkspaceId
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> WorkspaceId -> WindowSpace -> WorkspaceId
ren }