XMonad.Actions.CopyWindow runOrCopy

This commit is contained in:
lan3ny 2008-06-02 20:57:42 +00:00
parent 9fc46d0dfd
commit af08bec754

View File

@ -2,7 +2,7 @@
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
-- | -- |
-- Module : XMonad.Actions.CopyWindow -- Module : XMonad.Actions.CopyWindow
-- Copyright : (c) David Roundy <droundy@darcs.net>, Ivan Veselov <veselov@gmail.com> -- Copyright : (c) David Roundy <droundy@darcs.net>, Ivan Veselov <veselov@gmail.com>, Lanny Ripple <lan3ny@gmail.com>
-- License : BSD3-style (see LICENSE) -- License : BSD3-style (see LICENSE)
-- --
-- Maintainer : ??? -- Maintainer : ???
@ -17,10 +17,12 @@
module XMonad.Actions.CopyWindow ( module XMonad.Actions.CopyWindow (
-- * Usage -- * Usage
-- $usage -- $usage
copy, copyToAll, copyWindow, killAllOtherCopies, kill1 copy, copyToAll, copyWindow, runOrCopy
, killAllOtherCopies, kill1
) where ) where
import Prelude hiding (filter) import Prelude hiding (filter)
import Control.Monad (filterM)
import qualified Data.List as L import qualified Data.List as L
import XMonad hiding (modify, workspaces) import XMonad hiding (modify, workspaces)
import XMonad.StackSet import XMonad.StackSet
@ -50,6 +52,11 @@ import XMonad.StackSet
-- --
-- > , ((modMask x .|. shiftMask, xK_c ), kill1) -- @@ Close the focused window -- > , ((modMask x .|. shiftMask, xK_c ), kill1) -- @@ Close the focused window
-- --
-- Instead of copying a window from a workset to a workset maybe you don't
-- want to have to remember where you placed it. For that consider:
--
-- > , ((modMask x, xK_b ), runOrCopy "firefox" (className =? "Firefox")) -- @@ run or copy firefox
--
-- Another possibility which this extension provides is 'making window -- Another possibility which this extension provides is 'making window
-- always visible' (i.e. always on current workspace), similar to corresponding -- always visible' (i.e. always on current workspace), similar to corresponding
-- metacity functionality. This behaviour is emulated through copying given -- metacity functionality. This behaviour is emulated through copying given
@ -58,13 +65,13 @@ import XMonad.StackSet
-- --
-- Here is the example of keybindings which provide these actions: -- Here is the example of keybindings which provide these actions:
-- --
-- > , ((modMask x, xK_v )", windows copyToAll) -- @@ Make focused window always visible -- > , ((modMask x, xK_v ), windows copyToAll) -- @@ Make focused window always visible
-- > , ((modMask x .|. shiftMask, xK_v ), killAllOtherCopies) -- @@ Toggle window state back -- > , ((modMask x .|. shiftMask, xK_v ), killAllOtherCopies) -- @@ Toggle window state back
-- --
-- For detailed instructions on editing your key bindings, see -- For detailed instructions on editing your key bindings, see
-- "XMonad.Doc.Extending#Editing_key_bindings". -- "XMonad.Doc.Extending#Editing_key_bindings".
-- | copy. Copy the focussed window to a new workspace. -- | copy. Copy the focused window to a new workspace.
copy :: (Eq s, Eq i, Eq a) => i -> StackSet i l a s sd -> StackSet i l a s sd copy :: (Eq s, Eq i, Eq a) => i -> StackSet i l a s sd -> StackSet i l a s sd
copy n s | Just w <- peek s = copyWindow w n s copy n s | Just w <- peek s = copyWindow w n s
| otherwise = s | otherwise = s
@ -85,6 +92,21 @@ copyWindow w n = copy'
else Just $ Stack a (L.delete a l) (L.delete a (t:r))) s else Just $ Stack a (L.delete a l) (L.delete a (t:r))) s
-- | runOrCopy . runOrCopy will run the provided shell command unless it can
-- find a specified window in which case it will copy the window to
-- the current workspace. Similar to (i.e., stolen from) "XMonad.Actions.WindowGo".
runOrCopy :: String -> Query Bool -> X ()
runOrCopy action = copyMaybe $ spawn action
-- | copyMaybe. Flatters "XMonad.Actions.WindowGo" ('raiseMaybe')
copyMaybe :: X () -> Query Bool -> X ()
copyMaybe f thatUserQuery = withWindowSet $ \s -> do
maybeResult <- filterM (runQuery thatUserQuery) (allWindows s)
case maybeResult of
[] -> f
(x:_) -> windows $ copyWindow x (currentTag 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
-- delete notify back from X. -- delete notify back from X.