------------------------------------------------------------------------------- |-- Module : XMonad.Actions.CycleWS-- Copyright : (c) Joachim Breitner <mail@joachim-breitner.de>,-- Nelson Elhage <nelhage@mit.edu> (`toggleWS' function)-- License : BSD3-style (see LICENSE)---- Maintainer : Joachim Breitner <mail@joachim-breitner.de>-- Stability : unstable-- Portability : unportable---- Provides bindings to cycle forward or backward through the list of-- workspaces, to move windows between workspaces, and to cycle-- between screens. More general combinators provide ways to cycle-- through workspaces in various orders, to only cycle through some-- subset of workspaces, and to cycle by more than one workspace at a-- time.---- Note that this module now subsumes the functionality of the former-- @XMonad.Actions.RotView@. Former users of @rotView@ can simply replace-- @rotView True@ with @moveTo Next NonEmptyWS@, and so on.---- If you want to exactly replicate the action of @rotView@ (cycling-- through workspace in order lexicographically by tag, instead of in-- the order specified in the config), it can be implemented as:---- > rotView b = do t <- findWorkspace getSortByTag (bToDir b) NonEmptyWS 1-- > windows . greedyView $ t-- > where bToDir True = Next-- > bToDir False = Prev-------------------------------------------------------------------------------moduleXMonad.Actions.CycleWS(-- * Usage-- $usage-- * Moving between workspaces-- $movingnextWS,prevWS,shiftToNext,shiftToPrev-- * Toggling the previous workspace-- $toggling,toggleWS,toggleOrView-- * Moving between screens (xinerama),nextScreen,prevScreen,shiftNextScreen,shiftPrevScreen,swapNextScreen,swapPrevScreen-- * Moving between workspaces, take two!-- $taketwo,Direction1D(..),WSType(..),shiftTo,moveTo,doTo-- * The mother-combinator,findWorkspace,toggleOrDoSkip,skipTags)whereimportControl.Monad(unless)importData.List(findIndex)importData.Maybe(isNothing,isJust)importXMonadhiding(workspaces)importXMonad.StackSethiding(filter)importXMonad.Util.TypesimportXMonad.Util.WorkspaceCompare-- $usage-- You can use this module with the following in your @~\/.xmonad\/xmonad.hs@ file:---- > import XMonad.Actions.CycleWS-- >-- > -- a basic CycleWS setup-- >-- > , ((modm, xK_Down), nextWS)-- > , ((modm, xK_Up), prevWS)-- > , ((modm .|. shiftMask, xK_Down), shiftToNext)-- > , ((modm .|. shiftMask, xK_Up), shiftToPrev)-- > , ((modm, xK_Right), nextScreen)-- > , ((modm, xK_Left), prevScreen)-- > , ((modm .|. shiftMask, xK_Right), shiftNextScreen)-- > , ((modm .|. shiftMask, xK_Left), shiftPrevScreen)-- > , ((modm, xK_z), toggleWS)---- If you want to follow the moved window, you can use both actions:---- > , ((modm .|. shiftMask, xK_Down), shiftToNext >> nextWS)-- > , ((modm .|. shiftMask, xK_Up), shiftToPrev >> prevWS)---- You can also get fancier with 'moveTo', 'shiftTo', and 'findWorkspace'.-- For example:---- > , ((modm , xK_f), moveTo Next EmptyWS) -- find a free workspace-- > , ((modm .|. controlMask, xK_Right), -- a crazy keybinding!-- > do t <- findWorkspace getSortByXineramaRule Next NonEmptyWS 2-- > windows . view $ t )---- For detailed instructions on editing your key bindings, see-- "XMonad.Doc.Extending#Editing_key_bindings".{- $moving
The following commands for moving the view and windows between
workspaces are somewhat inflexible, but are very simple and probably
Do The Right Thing for most users.
All of the commands in this section cycle through workspaces in the
order in which they are given in your config.
-}-- | Switch to the next workspace.nextWS::X()nextWS=switchWorkspace1-- | Switch to the previous workspace.prevWS::X()prevWS=switchWorkspace(-1)-- | Move the focused window to the next workspace.shiftToNext::X()shiftToNext=shiftBy1-- | Move the focused window to the previous workspace.shiftToPrev::X()shiftToPrev=shiftBy(-1)-- $toggling-- | Toggle to the workspace displayed previously.toggleWS::X()toggleWS=dohs<-gets(hidden.windowset)unless(nullhs)(windows.view.tag$headhs)-- | 'XMonad.StackSet.greedyView' a workspace, or if already there, view-- the previously displayed workspace ala weechat. Change @greedyView@ to-- @toggleOrView@ in your workspace bindings as in the 'XMonad.StackSet.view'-- faq at <http://haskell.org/haskellwiki/Xmonad/Frequently_asked_questions>.-- For more flexibility see 'toggleOrDoSkip'.toggleOrView::WorkspaceId->X()toggleOrView=toggleOrDoSkip[]greedyView-- | Allows ignoring listed workspace tags (such as scratchpad's \"NSP\") while-- finding the previously displayed workspace, or choice of different actions,-- like view, shift, etc. For example:---- > import qualified XMonad.StackSet as W-- > import XMonad.Actions.CycleWS-- >-- > -- toggleOrView for people who prefer view to greedyView-- > toggleOrView' = toggleOrDoSkip [] W.view-- >-- > -- toggleOrView ignoring scratchpad and named scratchpad workspace-- > toggleOrViewNoSP = toggleOrDoSkip ["NSP"] W.greedyViewtoggleOrDoSkip::[WorkspaceId]->(WorkspaceId->WindowSet->WindowSet)->WorkspaceId->X()toggleOrDoSkipskipsftoWS=dows<-getswindowsetleths'=hiddenws`skipTags`skipsiftoWS==(tag.workspace$currentws)thenunless(nullhs')(windows.f.tag$headhs')elsewindows(ftoWS)-- | List difference ('\\') for workspaces and tags. Removes workspaces-- matching listed tags from the given workspace list.skipTags::(Eqi)=>[Workspaceila]->[i]->[Workspaceila]skipTagswssids=filter((`notElem`ids).tag)wssswitchWorkspace::Int->X()switchWorkspaced=wsByd>>=windows.greedyViewshiftBy::Int->X()shiftByd=wsByd>>=windows.shiftwsBy::Int->X(WorkspaceId)wsBy=findWorkspacegetSortByIndexNextAnyWS{- $taketwo
A few more general commands are also provided, which allow cycling
through subsets of workspaces.
For example,
> moveTo Next EmptyWS
will move to the first available workspace with no windows, and
> shiftTo Prev (WSIs $ return (('p' `elem`) . tag))
will move the focused window backwards to the first workspace containing
the letter 'p' in its name. =)
-}-- | What type of workspaces should be included in the cycle?dataWSType=EmptyWS-- ^ cycle through empty workspaces|NonEmptyWS-- ^ cycle through non-empty workspaces|HiddenWS-- ^ cycle through non-visible workspaces|HiddenNonEmptyWS-- ^ cycle through non-empty non-visible workspaces|AnyWS-- ^ cycle through all workspaces|WSTagGroupChar-- ^ cycle through workspaces in the same group, the-- group name is all characters up to the first-- separator character or the end of the tag|WSIs(X(WindowSpace->Bool))-- ^ cycle through workspaces satisfying-- an arbitrary predicate-- | Convert a WSType value to a predicate on workspaces.wsTypeToPred::WSType->X(WindowSpace->Bool)wsTypeToPredEmptyWS=return(isNothing.stack)wsTypeToPredNonEmptyWS=return(isJust.stack)wsTypeToPredHiddenWS=dohs<-gets(maptag.hidden.windowset)return(\w->tagw`elem`hs)wsTypeToPredHiddenNonEmptyWS=done<-wsTypeToPredNonEmptyWShi<-wsTypeToPredHiddenWSreturn(\w->hiw&&new)wsTypeToPredAnyWS=return(constTrue)wsTypeToPred(WSTagGroupsep)=docur<-(groupName.workspace.current)`fmap`getswindowsetreturn$(cur==).groupNamewheregroupName=takeWhile(/=sep).tagwsTypeToPred(WSIsp)=p-- | View the next workspace in the given direction that satisfies-- the given condition.moveTo::Direction1D->WSType->X()moveTodirt=doTodirtgetSortByIndex(windows.greedyView)-- | Move the currently focused window to the next workspace in the-- given direction that satisfies the given condition.shiftTo::Direction1D->WSType->X()shiftTodirt=doTodirtgetSortByIndex(windows.shift)-- | Using the given sort, find the next workspace in the given-- direction of the given type, and perform the given action on it.doTo::Direction1D->WSType->XWorkspaceSort->(WorkspaceId->X())->X()doTodirtsrtact=findWorkspacesrtdirt1>>=act-- | Given a function @s@ to sort workspaces, a direction @dir@, a-- predicate @p@ on workspaces, and an integer @n@, find the tag of-- the workspace which is @n@ away from the current workspace in-- direction @dir@ (wrapping around if necessary), among those-- workspaces, sorted by @s@, which satisfy @p@.---- For some useful workspace sorting functions, see-- "XMonad.Util.WorkspaceCompare".---- For ideas of what to do with a workspace tag once obtained, note-- that 'moveTo' and 'shiftTo' are implemented by applying @(>>=-- (windows . greedyView))@ and @(>>= (windows . shift))@, respectively,-- to the output of 'findWorkspace'.findWorkspace::XWorkspaceSort->Direction1D->WSType->Int->XWorkspaceIdfindWorkspacesdirtn=findWorkspaceGens(wsTypeToPredt)(maybeNegatedirn)wheremaybeNegateNextd=dmaybeNegatePrevd=(-d)findWorkspaceGen::XWorkspaceSort->X(WindowSpace->Bool)->Int->XWorkspaceIdfindWorkspaceGen__0=gets(currentTag.windowset)findWorkspaceGensortXwsPredXd=dowsPred<-wsPredXsort<-sortXws<-getswindowsetletcur=workspace(currentws)sorted=sort(workspacesws)pivoted=let(a,b)=span((/=(tagcur)).tag)sortedinb++aws'=filterwsPredpivotedmCurIx=findWsIndexcurws'd'=ifd>0thend-1elsednext=ifnullws'thencurelsecasemCurIxofNothing->ws'!!(d'`mod`lengthws')Justix->ws'!!((ix+d)`mod`lengthws')return$tagnextfindWsIndex::WindowSpace->[WindowSpace]->MaybeIntfindWsIndexwswss=findIndex((==tagws).tag)wss-- | View next screennextScreen::X()nextScreen=switchScreen1-- | View prev screenprevScreen::X()prevScreen=switchScreen(-1)switchScreen::Int->X()switchScreend=dos<-screenBydmws<-screenWorkspacescasemwsofNothing->return()Justws->windows(viewws)screenBy::Int->X(ScreenId)screenByd=dows<-getswindowset--let ss = sortBy screen (screens ws)letnow=screen(currentws)return$(now+fromIntegrald)`mod`fromIntegral(length(screensws))-- | Swap current screen with next screenswapNextScreen::X()swapNextScreen=swapScreen1-- | Swap current screen with previous screenswapPrevScreen::X()swapPrevScreen=swapScreen(-1)swapScreen::Int->X()swapScreend=dos<-screenBydmws<-screenWorkspacescasemwsofNothing->return()Justws->windows(greedyViewws)-- | Move focused window to workspace on next screenshiftNextScreen::X()shiftNextScreen=shiftScreenBy1-- | Move focused window to workspace on prev screenshiftPrevScreen::X()shiftPrevScreen=shiftScreenBy(-1)shiftScreenBy::Int->X()shiftScreenByd=dos<-screenBydmws<-screenWorkspacescasemwsofNothing->return()Justws->windows(shiftws)