From 60e95ba9c4115cb4d31bf3f408522c0d323160ba Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Thu, 4 Nov 2021 14:10:52 -0600 Subject: Fix old bug. Old bug where shifting workspaces relatively using mod-n/p would not work as expected where visible workspaces without any windows would be skipped over or plain not work. --- src/Internal/XMobarLog.hs | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'src/Internal/XMobarLog.hs') diff --git a/src/Internal/XMobarLog.hs b/src/Internal/XMobarLog.hs index d0ff8f8..c0aa2a7 100644 --- a/src/Internal/XMobarLog.hs +++ b/src/Internal/XMobarLog.hs @@ -1,5 +1,6 @@ module Internal.XMobarLog ( XMobarLog, spawnXMobar, xMobarLogHook ) where +import Control.Arrow (second) import Control.Monad (forM_) import Control.Monad.Writer (tell, execWriter) import Data.List (sortBy) @@ -10,12 +11,11 @@ import System.IO (Handle, hSetEncoding, hPutStrLn, utf8) import XMonad.Util.NamedWindows (getName) import XMonad.Util.Run (spawnPipe) import XMonad (X) +import Internal.Lib (getPopulatedWorkspaces, WorkspaceState(..)) import qualified XMonad as X import qualified XMonad.StackSet as S -data WorkspaceState = Current | Hidden | Visible - data XMobarLog = XMobarLog Handle -- The log hook for XMobar. This is a custom log hook that does not use any @@ -39,19 +39,19 @@ xMobarLogHook (XMobarLog xmproc) = do winset <- X.gets X.windowset title <- maybe (pure "") (fmap show . getName) . S.peek $ winset - let wss = getWorkspaces winset + let wss = getPopulatedWorkspaces winset X.liftIO $ do hPutStrLn xmproc $ trunc 80 $ execWriter $ do tell layoutXpm tell $ " │ " - forM_ wss $ \(t, name) -> do + forM_ wss $ \(t, ws) -> do case t of Current -> tell "" Visible -> tell "" Hidden -> tell "" - tell name + tell (S.tag ws) tell " " tell $ "" @@ -76,13 +76,3 @@ trunc amt str = reverse $ trunc' False amt str [] 0 -> trunc' False 0 as acc 3 -> trunc' False 0 as ("..." ++ acc) _ -> trunc' False (amt - 1) as (a : acc) - --- Returns all the workspaces with a stack on them and if that workspace is --- Visible, Current or Hidden. -getWorkspaces :: (Ord i) => S.StackSet i l a sid sd -> [(WorkspaceState, i)] -getWorkspaces (S.StackSet (S.Screen cur _ _) vis hi _) = - sortBy (comparing snd) $ - mapMaybe (\(a, S.Workspace t _ s) -> fmap (const (a, t)) s) $ - map (\w -> (Hidden, w)) hi ++ - map (\(S.Screen w _ _) -> (Visible, w)) vis ++ - [(Current, cur)] -- cgit