1
0
mirror of https://github.com/xmonad/xmonad-contrib.git synced 2025-07-25 01:01:51 -07:00

onScreen' variation for X () functions

This commit is contained in:
Nils Schweinsberg
2009-12-09 00:37:17 +00:00
parent f46873fdab
commit 9464b32395

@@ -16,6 +16,7 @@ module XMonad.Actions.OnScreen (
-- * Usage -- * Usage
-- $usage -- $usage
onScreen onScreen
, onScreen'
, Focus(..) , Focus(..)
, viewOnScreen , viewOnScreen
, greedyViewOnScreen , greedyViewOnScreen
@@ -24,10 +25,12 @@ module XMonad.Actions.OnScreen (
, toggleGreedyOnScreen , toggleGreedyOnScreen
) where ) where
import XMonad
import XMonad.Core import XMonad.Core
import XMonad.StackSet import XMonad.StackSet hiding (new)
import Control.Monad (guard) import Control.Monad (guard)
-- import Control.Monad.State.Class (gets)
import Data.Maybe (fromMaybe) import Data.Maybe (fromMaybe)
@@ -50,20 +53,43 @@ onScreen f foc sc st = fromMaybe st $ do
ws <- lookupWorkspace sc st ws <- lookupWorkspace sc st
let fStack = f $ view ws st let fStack = f $ view ws st
curScreen = screen $ current st
focusCur = lookupWorkspace curScreen fStack >>= return . flip view fStack return $ setFocus foc st fStack
isVisible = (`elem` map (tag.workspace) (visible st))
-- set focus for new stack -- set focus for new stack
setFocus FocusNew = return $ fStack setFocus :: Focus
setFocus FocusCurrent = focusCur -> WindowSet -- ^ old stack
setFocus (FocusTag i) = return $ view i fStack -> WindowSet -- ^ new stack
setFocus (FocusTagVisible i) = -> WindowSet
if isVisible i setFocus FocusNew _ new = new
then setFocus (FocusTag i) setFocus FocusCurrent old new =
else setFocus FocusCurrent case lookupWorkspace (screen $ current old) new of
Nothing -> new
Just i -> view i new
setFocus (FocusTag i) _ new = view i new
setFocus (FocusTagVisible i) old new =
if i `elem` map (tag . workspace) (visible old)
then setFocus (FocusTag i) old new
else setFocus FocusCurrent old new
-- | A variation of @onScreen@ which will take any @X ()@ function and run it
-- on the given screen.
-- Warning: This function will change focus even if the function it's supposed
-- to run doesn't succeed.
onScreen' :: X () -- ^ X function to run
-> Focus -- ^ focus
-> ScreenId -- ^ screen id
-> X ()
onScreen' x foc sc = do
st <- gets windowset
case lookupWorkspace sc st of
Nothing -> return ()
Just ws -> do
windows $ view ws
x
windows $ setFocus foc st
setFocus foc
-- | Switch to workspace @i@ on screen @sc@. If @i@ is visible use @view@ to -- | Switch to workspace @i@ on screen @sc@. If @i@ is visible use @view@ to
-- switch focus to the workspace @i@. -- switch focus to the workspace @i@.
@@ -122,7 +148,6 @@ toggleOrView' f i st = fromMaybe (f i st) $ do
return $ f (tag . head $ st') st return $ f (tag . head $ st') st
-- $usage -- $usage
-- --
-- This module provides an easy way to control, what you see on other screens in -- This module provides an easy way to control, what you see on other screens in