make CopyWindow export a fancy copy-window-anywhere function.

This commit is contained in:
David Roundy 2007-11-23 12:10:20 +00:00
parent 8b3ad50c57
commit 51d6066d15

View File

@ -1,3 +1,4 @@
{-# OPTIONS_GHC -fglasgow-exts #-}
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- | -- |
-- Module : XMonad.Actions.CopyWindow -- Module : XMonad.Actions.CopyWindow
@ -16,10 +17,11 @@
module XMonad.Actions.CopyWindow ( module XMonad.Actions.CopyWindow (
-- * Usage -- * Usage
-- $usage -- $usage
copy, kill1 copy, copyWindow, kill1
) where ) where
import Prelude hiding ( filter ) import Prelude hiding ( filter )
import Graphics.X11.Xlib ( Window )
import Control.Monad.State ( gets ) import Control.Monad.State ( gets )
import qualified Data.List as L import qualified Data.List as L
import XMonad import XMonad
@ -54,15 +56,22 @@ import XMonad.StackSet
-- %keybindlist | (i, k) <- zip workspaces [xK_1 ..] -- %keybindlist | (i, k) <- zip workspaces [xK_1 ..]
-- %keybindlist , (f, m) <- [(view, 0), (shift, shiftMask), (copy, shiftMask .|. controlMask)]] -- %keybindlist , (f, m) <- [(view, 0), (shift, shiftMask), (copy, shiftMask .|. controlMask)]]
-- | copy. Copy a window to a new workspace. -- | copy. Copy the focussed window to a new workspace.
copy :: WorkspaceId -> WindowSet -> WindowSet copy :: WorkspaceId -> WindowSet -> WindowSet
copy n = copy' copy n s | Just w <- peek s = copyWindow w n s
where copy' s = if n `tagMember` s && n /= tag (workspace (current s)) | otherwise = s
then maybe s (go s) (peek s)
-- | copyWindow. Copy a window to a new workspace
copyWindow :: Window -> WorkspaceId -> WindowSet -> WindowSet
copyWindow w n = copy'
where copy' s = if n `tagMember` s
then view (tag (workspace (current s))) $ insertUp' w $ view n s
else s else s
go s w = view (tag (workspace (current s))) $ insertUp' w $ view n s
insertUp' a s = modify (Just $ Stack a [] []) insertUp' a s = modify (Just $ Stack a [] [])
(\(Stack t l r) -> Just $ Stack a (L.delete a l) (L.delete a (t:r))) s (\(Stack t l r) -> if a `elem` t:l++r
then Just $ Stack t l r
else Just $ Stack a (L.delete a l) (L.delete a (t:r))) s
-- | Remove the focused window from this workspace. If it's present in no -- | Remove the focused window from this workspace. If it's present in no
-- other workspace, then kill it instead. If we do kill it, we'll get a -- other workspace, then kill it instead. If we do kill it, we'll get a