mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-08-17 21:33:46 -07:00
Merge pull request #24 from nlewo/master
X.P.Window: add window selector for the prompt and BringToMaster action
This commit is contained in:
@@ -18,10 +18,16 @@ module XMonad.Prompt.Window
|
|||||||
(
|
(
|
||||||
-- * Usage
|
-- * Usage
|
||||||
-- $usage
|
-- $usage
|
||||||
|
WindowPrompt(..),
|
||||||
|
windowPrompt,
|
||||||
|
allWindows,
|
||||||
|
wsWindows,
|
||||||
|
XWindowMap,
|
||||||
|
|
||||||
|
-- * Deprecated
|
||||||
windowPromptGoto,
|
windowPromptGoto,
|
||||||
windowPromptBring,
|
windowPromptBring,
|
||||||
windowPromptBringCopy,
|
windowPromptBringCopy,
|
||||||
WindowPrompt,
|
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
@@ -31,11 +37,13 @@ import XMonad
|
|||||||
import XMonad.Prompt
|
import XMonad.Prompt
|
||||||
import XMonad.Actions.CopyWindow
|
import XMonad.Actions.CopyWindow
|
||||||
import XMonad.Actions.WindowBringer
|
import XMonad.Actions.WindowBringer
|
||||||
|
import XMonad.Util.NamedWindows
|
||||||
|
|
||||||
-- $usage
|
-- $usage
|
||||||
-- WindowPrompt brings windows to you and you to windows.
|
-- WindowPrompt brings windows to you and you to windows. That is to
|
||||||
-- That is to say, it pops up a prompt with window names, in case you forgot
|
-- say, it pops up a prompt with window names, in case you forgot
|
||||||
-- where you left your XChat.
|
-- where you left your XChat. It also offers helpers to build the
|
||||||
|
-- subset of windows which is used for the prompt completion.
|
||||||
--
|
--
|
||||||
-- You can use this module with the following in your @~\/.xmonad\/xmonad.hs@:
|
-- You can use this module with the following in your @~\/.xmonad\/xmonad.hs@:
|
||||||
--
|
--
|
||||||
@@ -44,13 +52,14 @@ import XMonad.Actions.WindowBringer
|
|||||||
--
|
--
|
||||||
-- and in the keys definition:
|
-- and in the keys definition:
|
||||||
--
|
--
|
||||||
-- > , ((modm .|. shiftMask, xK_g ), windowPromptGoto def)
|
-- > , ((modm .|. shiftMask, xK_g ), windowPrompt def Goto wsWindows)
|
||||||
-- > , ((modm .|. shiftMask, xK_b ), windowPromptBring def)
|
-- > , ((modm .|. shiftMask, xK_b ), windowPrompt def Bring allWindows)
|
||||||
--
|
--
|
||||||
-- The autoComplete option is a handy complement here:
|
-- The autoComplete option is a handy complement here:
|
||||||
--
|
--
|
||||||
-- > , ((modm .|. shiftMask, xK_g ), windowPromptGoto
|
-- > , ((modm .|. shiftMask, xK_g ), windowPrompt
|
||||||
-- > def { autoComplete = Just 500000 } )
|
-- > def { autoComplete = Just 500000 }
|
||||||
|
-- > Goto allWindows)
|
||||||
--
|
--
|
||||||
-- The \'500000\' is the number of microseconds to pause before sending you to
|
-- The \'500000\' is the number of microseconds to pause before sending you to
|
||||||
-- your new window. This is useful so that you don't accidentally send some
|
-- your new window. This is useful so that you don't accidentally send some
|
||||||
@@ -59,27 +68,49 @@ import XMonad.Actions.WindowBringer
|
|||||||
-- For detailed instruction on editing the key binding see
|
-- For detailed instruction on editing the key binding see
|
||||||
-- "XMonad.Doc.Extending#Editing_key_bindings".
|
-- "XMonad.Doc.Extending#Editing_key_bindings".
|
||||||
|
|
||||||
data WindowPrompt = Goto | Bring | BringCopy
|
-- Describe actions that can applied on the selected window
|
||||||
|
data WindowPrompt = Goto | Bring | BringCopy | BringToMaster
|
||||||
instance XPrompt WindowPrompt where
|
instance XPrompt WindowPrompt where
|
||||||
showXPrompt Goto = "Go to window: "
|
showXPrompt Goto = "Go to window: "
|
||||||
showXPrompt Bring = "Bring window: "
|
showXPrompt Bring = "Bring window: "
|
||||||
|
showXPrompt BringToMaster
|
||||||
|
= "Bring window to master: "
|
||||||
showXPrompt BringCopy = "Bring a copy: "
|
showXPrompt BringCopy = "Bring a copy: "
|
||||||
commandToComplete _ c = c
|
commandToComplete _ c = c
|
||||||
nextCompletion _ = getNextCompletion
|
nextCompletion _ = getNextCompletion
|
||||||
|
|
||||||
|
-- | Deprecated. Use windowPrompt instead.
|
||||||
windowPromptGoto, windowPromptBring, windowPromptBringCopy :: XPConfig -> X ()
|
windowPromptGoto, windowPromptBring, windowPromptBringCopy :: XPConfig -> X ()
|
||||||
windowPromptGoto = doPrompt Goto
|
windowPromptGoto c = windowPrompt c Goto windowMap
|
||||||
windowPromptBring = doPrompt Bring
|
windowPromptBring c = windowPrompt c Bring windowMap
|
||||||
windowPromptBringCopy = doPrompt BringCopy
|
windowPromptBringCopy c = windowPrompt c BringCopy windowMap
|
||||||
|
|
||||||
-- | Pops open a prompt with window titles. Choose one, and you will be
|
-- | A helper to get the map of all windows.
|
||||||
-- taken to the corresponding workspace.
|
allWindows :: XWindowMap
|
||||||
doPrompt :: WindowPrompt -> XPConfig -> X ()
|
allWindows = windowMap
|
||||||
doPrompt t c = do
|
|
||||||
|
-- | A helper to get the map of windows of the current workspace.
|
||||||
|
wsWindows :: XWindowMap
|
||||||
|
wsWindows = withWindowSet (return . W.index) >>= windowMap
|
||||||
|
where
|
||||||
|
windowMap = fmap M.fromList . mapM pair
|
||||||
|
pair w = do name <- fmap show $ getName w
|
||||||
|
return (name, w)
|
||||||
|
|
||||||
|
-- | A Map where keys are pretty printable window names and values are
|
||||||
|
-- Xmonad windows identifier.
|
||||||
|
type XWindowMap = X (M.Map String Window)
|
||||||
|
|
||||||
|
-- | Pops open a prompt with window titles belonging to
|
||||||
|
-- windowMap. Choose one, and an action is applied on the
|
||||||
|
-- selected window, according to WindowPrompt.
|
||||||
|
windowPrompt :: XPConfig -> WindowPrompt -> XWindowMap -> X ()
|
||||||
|
windowPrompt c t windowMap = do
|
||||||
a <- case t of
|
a <- case t of
|
||||||
Goto -> fmap gotoAction windowMap
|
Goto -> fmap gotoAction windowMap
|
||||||
Bring -> fmap bringAction windowMap
|
Bring -> fmap bringAction windowMap
|
||||||
BringCopy -> fmap bringCopyAction windowMap
|
BringCopy -> fmap bringCopyAction windowMap
|
||||||
|
BringToMaster -> fmap bringToMaster windowMap
|
||||||
wm <- windowMap
|
wm <- windowMap
|
||||||
mkXPrompt t c (compList wm) a
|
mkXPrompt t c (compList wm) a
|
||||||
|
|
||||||
@@ -88,10 +119,10 @@ doPrompt t c = do
|
|||||||
gotoAction = winAction W.focusWindow
|
gotoAction = winAction W.focusWindow
|
||||||
bringAction = winAction bringWindow
|
bringAction = winAction bringWindow
|
||||||
bringCopyAction = winAction bringCopyWindow
|
bringCopyAction = winAction bringCopyWindow
|
||||||
|
bringToMaster = winAction (\w s -> W.shiftMaster . W.focusWindow w $ bringWindow w s)
|
||||||
|
|
||||||
compList m s = return . filter (searchPredicate c s) . map fst . M.toList $ m
|
compList m s = return . filter (searchPredicate c s) . map fst . M.toList $ m
|
||||||
|
|
||||||
|
|
||||||
-- | Brings a copy of the specified window into the current workspace.
|
-- | Brings a copy of the specified window into the current workspace.
|
||||||
bringCopyWindow :: Window -> WindowSet -> WindowSet
|
bringCopyWindow :: Window -> WindowSet -> WindowSet
|
||||||
bringCopyWindow w ws = copyWindow w (W.currentTag ws) ws
|
bringCopyWindow w ws = copyWindow w (W.currentTag ws) ws
|
||||||
|
Reference in New Issue
Block a user