mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-05-19 11:30:22 -07:00
make FindEmptyWorkspace compile
This commit is contained in:
parent
c39da512e9
commit
020ee6fc03
@ -28,32 +28,36 @@ module XMonadContrib.FindEmptyWorkspace (
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
import Control.Monad.State
|
import Control.Monad.State
|
||||||
import qualified Data.Map as M
|
import Data.List
|
||||||
|
|
||||||
import XMonad
|
import XMonad
|
||||||
import Operations
|
import StackSet
|
||||||
import qualified StackSet as W
|
|
||||||
|
|
||||||
-- | Find the first empty workspace in a WindowSet. Returns Nothing if
|
import qualified Operations as O
|
||||||
-- all workspaces are in use.
|
|
||||||
findEmptyWorkspace :: WindowSet -> Maybe WorkspaceId
|
-- | Find the first hidden empty workspace in a StackSet. Returns
|
||||||
findEmptyWorkspace = findKey (([],[]) ==) . W.stacks
|
-- Nothing if all workspaces are in use. Function searches currently
|
||||||
|
-- focused workspace, other visible workspaces (when in Xinerama) and
|
||||||
|
-- hidden workspaces in this order.
|
||||||
|
findEmptyWorkspace :: StackSet i a s -> Maybe (Workspace i a)
|
||||||
|
findEmptyWorkspace = find (isEmpty . stack) . allWorkspaces
|
||||||
|
where
|
||||||
|
isEmpty Empty = True
|
||||||
|
isEmpty _ = False
|
||||||
|
allWorkspaces ss = (workspace . current) ss :
|
||||||
|
(map workspace . visible) ss ++ hidden ss
|
||||||
|
|
||||||
withEmptyWorkspace :: (WorkspaceId -> X ()) -> X ()
|
withEmptyWorkspace :: (WorkspaceId -> X ()) -> X ()
|
||||||
withEmptyWorkspace f = do
|
withEmptyWorkspace f = do
|
||||||
ws <- gets windowset
|
ws <- gets windowset
|
||||||
whenJust (findEmptyWorkspace ws) f
|
whenJust (findEmptyWorkspace ws) (f . tag)
|
||||||
|
|
||||||
-- | Find and view an empty workspace. Do nothing if all workspaces are
|
-- | Find and view an empty workspace. Do nothing if all workspaces are
|
||||||
-- in use.
|
-- in use.
|
||||||
viewEmptyWorkspace :: X ()
|
viewEmptyWorkspace :: X ()
|
||||||
viewEmptyWorkspace = withEmptyWorkspace view
|
viewEmptyWorkspace = withEmptyWorkspace O.view
|
||||||
|
|
||||||
-- | Tag current window to an empty workspace and view it. Do nothing if
|
-- | Tag current window to an empty workspace and view it. Do nothing if
|
||||||
-- all workspaces are in use.
|
-- all workspaces are in use.
|
||||||
tagToEmptyWorkspace :: X ()
|
tagToEmptyWorkspace :: X ()
|
||||||
tagToEmptyWorkspace = withEmptyWorkspace $ \w -> tag w >> view w
|
tagToEmptyWorkspace = withEmptyWorkspace $ \w -> O.shift w >> O.view w
|
||||||
|
|
||||||
-- Thanks to mauke on #haskell
|
|
||||||
findKey :: (a -> Bool) -> M.Map k a -> Maybe k
|
|
||||||
findKey f = M.foldWithKey (\k a -> mplus (if f a then Just k else Nothing)) Nothing
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user