From 02c5beadee33cd172248d7194ca6a2c1595a27b3 Mon Sep 17 00:00:00 2001 From: lan3ny Date: Mon, 2 Jun 2008 22:57:42 +0200 Subject: XMonad.Actions.CopyWindow runOrCopy darcs-hash:20080602205742-20747-65c3b7fcab114e84def368c54056a8f58cadec2e.gz --- XMonad/Actions/CopyWindow.hs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'XMonad') diff --git a/XMonad/Actions/CopyWindow.hs b/XMonad/Actions/CopyWindow.hs index 68d6e38..06d181e 100644 --- a/XMonad/Actions/CopyWindow.hs +++ b/XMonad/Actions/CopyWindow.hs @@ -2,7 +2,7 @@ ----------------------------------------------------------------------------- -- | -- Module : XMonad.Actions.CopyWindow --- Copyright : (c) David Roundy , Ivan Veselov +-- Copyright : (c) David Roundy , Ivan Veselov , Lanny Ripple -- License : BSD3-style (see LICENSE) -- -- Maintainer : ??? @@ -17,10 +17,12 @@ module XMonad.Actions.CopyWindow ( -- * Usage -- $usage - copy, copyToAll, copyWindow, killAllOtherCopies, kill1 + copy, copyToAll, copyWindow, runOrCopy + , killAllOtherCopies, kill1 ) where import Prelude hiding (filter) +import Control.Monad (filterM) import qualified Data.List as L import XMonad hiding (modify, workspaces) import XMonad.StackSet @@ -50,6 +52,11 @@ import XMonad.StackSet -- -- > , ((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 -- always visible' (i.e. always on current workspace), similar to corresponding -- 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: -- --- > , ((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 -- -- For detailed instructions on editing your key bindings, see -- "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 n s | Just w <- peek s = copyWindow w n 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 +-- | 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 -- other workspace, then kill it instead. If we do kill it, we'll get a -- delete notify back from X. -- cgit v1.2.3