mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-08-01 12:41:52 -07:00
Merge pull request #106 from IvanMalison/custom_focus_raise_next_maybe
X.A.WindowGo: Add arg for custom focus fn to raiseNextMaybe
This commit is contained in:
@@ -21,6 +21,7 @@ module XMonad.Actions.WindowGo (
|
|||||||
runOrRaiseNext,
|
runOrRaiseNext,
|
||||||
raiseMaybe,
|
raiseMaybe,
|
||||||
raiseNextMaybe,
|
raiseNextMaybe,
|
||||||
|
raiseNextMaybeCustomFocus,
|
||||||
|
|
||||||
raiseBrowser,
|
raiseBrowser,
|
||||||
raiseEditor,
|
raiseEditor,
|
||||||
@@ -38,7 +39,7 @@ module XMonad.Actions.WindowGo (
|
|||||||
import Control.Monad
|
import Control.Monad
|
||||||
import Data.Char (toLower)
|
import Data.Char (toLower)
|
||||||
import Data.Monoid
|
import Data.Monoid
|
||||||
import XMonad (Query(), X(), ManageHook, withWindowSet, runQuery, liftIO, ask)
|
import XMonad (Query(), X(), ManageHook, WindowSet, withWindowSet, runQuery, liftIO, ask)
|
||||||
import Graphics.X11 (Window)
|
import Graphics.X11 (Window)
|
||||||
import XMonad.ManageHook
|
import XMonad.ManageHook
|
||||||
import XMonad.Operations (windows)
|
import XMonad.Operations (windows)
|
||||||
@@ -137,16 +138,21 @@ raiseNext = raiseNextMaybe $ return ()
|
|||||||
'raiseNextMaybe' is an alternative version that allows cycling
|
'raiseNextMaybe' is an alternative version that allows cycling
|
||||||
through the matching windows. If the focused window matches the
|
through the matching windows. If the focused window matches the
|
||||||
query the next matching window is raised. If no matches are found
|
query the next matching window is raised. If no matches are found
|
||||||
the function f is executed.
|
the function f is executed. -}
|
||||||
-}
|
|
||||||
|
|
||||||
raiseNextMaybe :: X () -> Query Bool -> X ()
|
raiseNextMaybe :: X () -> Query Bool -> X ()
|
||||||
raiseNextMaybe f qry = flip (ifWindows qry) f $ \ws -> do
|
raiseNextMaybe = raiseNextMaybeCustomFocus W.focusWindow
|
||||||
|
|
||||||
|
{- | See 'raiseMaybe' and 'raiseNextMaybe'.
|
||||||
|
In addition to all of the options offered by 'raiseNextMaybe'
|
||||||
|
'raiseNextMaybeCustomFocus' allows the user to supply the function that
|
||||||
|
should be used to shift the focus to any window that is found. -}
|
||||||
|
raiseNextMaybeCustomFocus :: (Window -> WindowSet -> WindowSet) -> X() -> Query Bool -> X()
|
||||||
|
raiseNextMaybeCustomFocus focusFn f qry = flip (ifWindows qry) f $ \ws -> do
|
||||||
foc <- withWindowSet $ return . W.peek
|
foc <- withWindowSet $ return . W.peek
|
||||||
case foc of
|
case foc of
|
||||||
Just w | w `elem` ws -> let (_:y:_) = dropWhile (/=w) $ cycle ws -- cannot fail to match
|
Just w | w `elem` ws -> let (_:y:_) = dropWhile (/=w) $ cycle ws -- cannot fail to match
|
||||||
in windows $ W.focusWindow y
|
in windows $ focusFn y
|
||||||
_ -> windows . W.focusWindow . head $ ws
|
_ -> windows . focusFn . head $ ws
|
||||||
|
|
||||||
-- | Given a function which gets us a String, we try to raise a window with that classname,
|
-- | Given a function which gets us a String, we try to raise a window with that classname,
|
||||||
-- or we then interpret that String as a executable name.
|
-- or we then interpret that String as a executable name.
|
||||||
@@ -167,7 +173,8 @@ raiseAndDo :: X () -> Query Bool -> (Window -> X ()) -> X ()
|
|||||||
raiseAndDo f qry after = ifWindow qry (afterRaise `mappend` raiseHook) f
|
raiseAndDo f qry after = ifWindow qry (afterRaise `mappend` raiseHook) f
|
||||||
where afterRaise = ask >>= (>> idHook) . liftX . after
|
where afterRaise = ask >>= (>> idHook) . liftX . after
|
||||||
|
|
||||||
{- | If a window matching the second argument is found, the window is focused and the third argument is called;
|
{- | If a window matching the second argument is found, the window is focused and
|
||||||
|
the third argument is called;
|
||||||
otherwise, the first argument is called. -}
|
otherwise, the first argument is called. -}
|
||||||
runOrRaiseAndDo :: String -> Query Bool -> (Window -> X ()) -> X ()
|
runOrRaiseAndDo :: String -> Query Bool -> (Window -> X ()) -> X ()
|
||||||
runOrRaiseAndDo = raiseAndDo . safeSpawnProg
|
runOrRaiseAndDo = raiseAndDo . safeSpawnProg
|
||||||
@@ -182,7 +189,6 @@ raiseMaster raisef thatUserQuery = raiseAndDo raisef thatUserQuery (\_ -> window
|
|||||||
{- | If the window is found the window is focused and set to master
|
{- | If the window is found the window is focused and set to master
|
||||||
otherwise, action is run.
|
otherwise, action is run.
|
||||||
|
|
||||||
> runOrRaiseMaster "firefox" (className =? "Firefox"))
|
> runOrRaiseMaster "firefox" (className =? "Firefox")) -}
|
||||||
-}
|
|
||||||
runOrRaiseMaster :: String -> Query Bool -> X ()
|
runOrRaiseMaster :: String -> Query Bool -> X ()
|
||||||
runOrRaiseMaster run query = runOrRaiseAndDo run query (\_ -> windows W.swapMaster)
|
runOrRaiseMaster run query = runOrRaiseAndDo run query (\_ -> windows W.swapMaster)
|
||||||
|
Reference in New Issue
Block a user