aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJosh Rahm <rahm@google.com>2021-11-04 14:10:52 -0600
committerJosh Rahm <joshuarahm@gmail.com>2022-10-09 12:19:45 -0600
commit60e95ba9c4115cb4d31bf3f408522c0d323160ba (patch)
tree98f092bff2d67a47632d72c0fddd3366a7422577 /src
parent6b8f9e2b113f88206e394ab93b15a1137247fd98 (diff)
downloadrde-60e95ba9c4115cb4d31bf3f408522c0d323160ba.tar.gz
rde-60e95ba9c4115cb4d31bf3f408522c0d323160ba.tar.bz2
rde-60e95ba9c4115cb4d31bf3f408522c0d323160ba.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/Internal/Lib.hs22
-rw-r--r--src/Internal/XMobarLog.hs20
2 files changed, 26 insertions, 16 deletions
diff --git a/src/Internal/Lib.hs b/src/Internal/Lib.hs
index feb5f26..3ba1eca 100644
--- a/src/Internal/Lib.hs
+++ b/src/Internal/Lib.hs
@@ -21,6 +21,9 @@ import XMonad hiding (workspaces, Screen)
import XMonad.StackSet hiding (filter, focus)
import qualified Data.Map as Map
import Internal.DMenu
+import Data.Ord (comparing)
+
+import qualified XMonad.StackSet as S
type WorkspaceName = Char
newtype Selector = Selector (forall a. (Eq a) => a -> [a] -> a)
@@ -31,6 +34,23 @@ instance XPrompt WinPrompt where
showXPrompt _ = "[Window] "
commandToComplete _ = id
+data WorkspaceState = Current | Hidden | Visible
+
+-- Returns all the workspaces that are either visible, current or Hidden but
+-- have windows and that workspace's state.
+--
+-- In other words, filters out workspaces that have no windows and are not
+-- visible.
+--
+-- This function will sort the result by the workspace tag.
+getPopulatedWorkspaces ::
+ (Ord i) => S.StackSet i l a sid sd -> [(WorkspaceState, S.Workspace i l a)]
+getPopulatedWorkspaces (S.StackSet (S.Screen cur _ _) vis hi _) =
+ sortBy (comparing (tag . snd)) $
+ mapMaybe (\w@(S.Workspace _ _ s) -> fmap (const (Hidden, w)) s) hi ++
+ map (\(S.Screen w _ _) -> (Visible, w)) vis ++
+ [(Current, cur)]
+
getHorizontallyOrderedScreens ::
StackSet wid l a ScreenId ScreenDetail ->
[Screen wid l a ScreenId ScreenDetail]
@@ -91,7 +111,7 @@ getString = runQuery $ do
relativeWorkspaceShift :: Selector -> X ()
relativeWorkspaceShift (Selector selector) = do
windows $ \ss ->
- let tags = sort $ (tag <$> filter (isJust . stack) (workspaces ss))
+ let tags = sort $ (tag . snd <$> getPopulatedWorkspaces ss)
from = tag $ workspace $ current ss
to = selector from tags
in greedyView to ss
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 $ "<fc=#404040> │ </fc>"
- forM_ wss $ \(t, name) -> do
+ forM_ wss $ \(t, ws) -> do
case t of
Current -> tell "<fn=1><fc=#ff8888>"
Visible -> tell "<fn=6><fc=#8888ff>"
Hidden -> tell "<fn=2><fc=#888888>"
- tell name
+ tell (S.tag ws)
tell " </fc></fn>"
tell $ "<fc=#404040>│ </fc><fc=#a0a0a0><fn=3>"
@@ -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)]