From 219295d64e15758d47f06eb6da5734687081c829 Mon Sep 17 00:00:00 2001 From: "Ivan N. Veselov" Date: Tue, 8 Apr 2008 21:51:11 +0200 Subject: XMonad.Actions.CopyWindow: added copyToAll and killAllOtherCopies functions darcs-hash:20080408195111-98257-fa939d0b1d9fad8212e9051443451f133488bbc5.gz --- XMonad/Actions/CopyWindow.hs | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'XMonad/Actions/CopyWindow.hs') diff --git a/XMonad/Actions/CopyWindow.hs b/XMonad/Actions/CopyWindow.hs index 1104bcf..1fcbdb3 100644 --- a/XMonad/Actions/CopyWindow.hs +++ b/XMonad/Actions/CopyWindow.hs @@ -2,7 +2,7 @@ ----------------------------------------------------------------------------- -- | -- Module : XMonad.Actions.CopyWindow --- Copyright : (c) David Roundy +-- Copyright : (c) David Roundy , Ivan Veselov -- License : BSD3-style (see LICENSE) -- -- Maintainer : David Roundy @@ -17,12 +17,12 @@ module XMonad.Actions.CopyWindow ( -- * Usage -- $usage - copy, copyWindow, kill1 + copy, copyToAll, copyWindow, killAllOtherCopies, kill1 ) where -import Prelude hiding ( filter ) +import Prelude hiding (filter) import qualified Data.List as L -import XMonad hiding (modify) +import XMonad hiding (modify, workspaces) import XMonad.StackSet -- $usage @@ -50,6 +50,17 @@ import XMonad.StackSet -- -- > , ((modMask x .|. shiftMask, xK_c ), kill1) -- @@ Close the focused window -- +-- Another possibility which this extension provides is 'making window +-- always visible' (i.e. always on current workspace), similar to corresponding +-- metacity functionality. This behaviour is emulated through copying given +-- window to all the workspaces and then removing it when it's unneeded on +-- all workspaces any more. +-- +-- Here is the example of keybindings which provide these actions: +-- +-- > , ((modMask x, xK_v )", windows copyToAll) -- @@ Make focused window always visible +-- > , ((modMask x .|. shiftMask, xK_v ), killAllOtherCopies) -- @@ Toggle window state back +-- -- For detailed instructions on editing your key bindings, see -- "XMonad.Doc.Extending#Editing_key_bindings". @@ -58,6 +69,10 @@ copy :: WorkspaceId -> WindowSet -> WindowSet copy n s | Just w <- peek s = copyWindow w n s | otherwise = s +-- | copyToAll. Copy the focused window to all of workspaces. +copyToAll :: WindowSet -> WindowSet +copyToAll s = foldr ($) s $ map (copy . tag) (workspaces s) + -- | copyWindow. Copy a window to a new workspace copyWindow :: Window -> WorkspaceId -> WindowSet -> WindowSet copyWindow w n = copy' @@ -83,3 +98,19 @@ kill1 = do ss <- gets windowset then windows $ delete'' w else kill where delete'' w = modify Nothing (filter (/= w)) + +-- | Kill all other copies of focused window (if they're present) +-- 'All other' means here 'copies, which are not on current workspace' +-- +-- Consider calling this function after copyToAll +-- +killAllOtherCopies :: X () +killAllOtherCopies = do ss <- gets windowset + whenJust (peek ss) $ \w -> windows $ + view (tag (workspace (current ss))) . + delFromAllButCurrent w + where + delFromAllButCurrent w ss = foldr ($) ss $ + map (delWinFromWorkspace w . tag) $ + hidden ss ++ map workspace (visible ss) + delWinFromWorkspace w wid ss = modify Nothing (filter (/= w)) $ view wid ss -- cgit v1.2.3