mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-05-19 11:30:22 -07:00
X.H.Focus: Adapt docs to the new activation interface
Fixes: https://github.com/xmonad/xmonad-contrib/issues/396 Related: https://github.com/xmonad/xmonad-contrib/pull/192 Related: https://github.com/xmonad/xmonad-contrib/pull/128
This commit is contained in:
parent
79b130b9d6
commit
860f80a6d3
@ -4,10 +4,13 @@
|
|||||||
|
|
||||||
-- |
|
-- |
|
||||||
-- Module: XMonad.Hooks.Focus
|
-- Module: XMonad.Hooks.Focus
|
||||||
-- Description: Provide additional information about a new window.
|
-- Description: Extends ManageHook EDSL to work on focused windows and current workspace.
|
||||||
-- Copyright: sgf-dma, 2016
|
-- Copyright: sgf-dma, 2016
|
||||||
-- Maintainer: sgf.dma@gmail.com
|
-- Maintainer: sgf.dma@gmail.com
|
||||||
--
|
--
|
||||||
|
-- Extends "XMonad.ManageHook" EDSL to work on focused windows and current
|
||||||
|
-- workspace.
|
||||||
|
--
|
||||||
|
|
||||||
module XMonad.Hooks.Focus
|
module XMonad.Hooks.Focus
|
||||||
(
|
(
|
||||||
@ -95,8 +98,8 @@ import XMonad.Hooks.ManageHelpers (currentWs)
|
|||||||
--
|
--
|
||||||
-- I may use one of predefined configurations.
|
-- I may use one of predefined configurations.
|
||||||
--
|
--
|
||||||
-- 1. Default window activation behavior is to switch to workspace with
|
-- 1. The default window activation behavior (switch to workspace with
|
||||||
-- activated window and switch focus to it:
|
-- activated window and switch focus to it) expressed using this module:
|
||||||
--
|
--
|
||||||
-- > import XMonad
|
-- > import XMonad
|
||||||
-- >
|
-- >
|
||||||
@ -105,44 +108,42 @@ import XMonad.Hooks.ManageHelpers (currentWs)
|
|||||||
-- >
|
-- >
|
||||||
-- > main :: IO ()
|
-- > main :: IO ()
|
||||||
-- > main = do
|
-- > main = do
|
||||||
-- > let mh :: ManageHook
|
-- > let ah :: ManageHook
|
||||||
-- > mh = activateSwitchWs
|
-- > ah = activateSwitchWs
|
||||||
-- > xcf = ewmh $ def
|
-- > xcf = setEwmhActivateHook ah
|
||||||
-- > { modMask = mod4Mask
|
-- > . ewmh $ def{ modMask = mod4Mask }
|
||||||
-- > , logHook = activateLogHook mh <+> logHook def
|
|
||||||
-- > }
|
|
||||||
-- > xmonad xcf
|
-- > xmonad xcf
|
||||||
--
|
--
|
||||||
-- 2. Or i may move activated window to current workspace and switch focus to
|
-- 2. Or i may move activated window to current workspace and switch focus to
|
||||||
-- it:
|
-- it:
|
||||||
--
|
--
|
||||||
-- > let mh :: ManageHook
|
-- > let ah :: ManageHook
|
||||||
-- > mh = activateOnCurrentWs
|
-- > ah = activateOnCurrentWs
|
||||||
--
|
--
|
||||||
-- 3. Or move activated window to current workspace, but keep focus unchanged:
|
-- 3. Or move activated window to current workspace, but keep focus unchanged:
|
||||||
--
|
--
|
||||||
-- > let mh :: ManageHook
|
-- > let ah :: ManageHook
|
||||||
-- > mh = activateOnCurrentKeepFocus
|
-- > ah = activateOnCurrentKeepFocus
|
||||||
--
|
--
|
||||||
-- 4. I may use regular 'ManageHook' combinators for filtering, which windows
|
-- 4. I may use regular 'ManageHook' combinators for filtering, which windows
|
||||||
-- may activate. E.g. activate all windows, except firefox:
|
-- may activate. E.g. activate all windows, except firefox:
|
||||||
--
|
--
|
||||||
-- > let mh :: ManageHook
|
-- > let ah :: ManageHook
|
||||||
-- > mh = not <$> (className =? "Firefox" <||> className =? "Firefox-esr" <||> className =? "Iceweasel")
|
-- > ah = not <$> (className =? "Firefox" <||> className =? "Firefox-esr" <||> className =? "Iceweasel")
|
||||||
-- > --> activateSwitchWs
|
-- > --> activateSwitchWs
|
||||||
--
|
--
|
||||||
-- 5. Or even use 'FocusHook' combinators. E.g. activate all windows, unless
|
-- 5. Or even use 'FocusHook' combinators. E.g. activate all windows, unless
|
||||||
-- xterm is focused on /current/ workspace:
|
-- xterm is focused on /current/ workspace:
|
||||||
--
|
--
|
||||||
-- > let mh :: ManageHook
|
-- > let ah :: ManageHook
|
||||||
-- > mh = manageFocus (not <$> focusedCur (className =? "XTerm")
|
-- > ah = manageFocus (not <$> focusedCur (className =? "XTerm")
|
||||||
-- > --> liftQuery activateSwitchWs)
|
-- > --> liftQuery activateSwitchWs)
|
||||||
--
|
--
|
||||||
-- or activate all windows, unless focused window on the workspace,
|
-- or activate all windows, unless focused window on the workspace,
|
||||||
-- /where activated window is/, is not a xterm:
|
-- /where activated window is/, is not a xterm:
|
||||||
--
|
--
|
||||||
-- > let mh :: ManageHook
|
-- > let ah :: ManageHook
|
||||||
-- > mh = manageFocus (not <$> focused (className =? "XTerm")
|
-- > ah = manageFocus (not <$> focused (className =? "XTerm")
|
||||||
-- > --> liftQuery activateSwitchWs)
|
-- > --> liftQuery activateSwitchWs)
|
||||||
--
|
--
|
||||||
-- == Defining FocusHook.
|
-- == Defining FocusHook.
|
||||||
@ -197,11 +198,11 @@ import XMonad.Hooks.ManageHelpers (currentWs)
|
|||||||
-- > main = do
|
-- > main = do
|
||||||
-- > let newFh :: ManageHook
|
-- > let newFh :: ManageHook
|
||||||
-- > newFh = manageFocus newFocusHook
|
-- > newFh = manageFocus newFocusHook
|
||||||
-- > acFh :: X ()
|
-- > acFh :: ManageHook
|
||||||
-- > acFh = activateLogHook (manageFocus activateFocusHook)
|
-- > acFh = manageFocus activateFocusHook
|
||||||
-- > xcf = ewmh $ def
|
-- > xcf = setEwmhActivateHook acFh
|
||||||
|
-- > . ewmh $ def
|
||||||
-- > { manageHook = newFh <+> manageHook def
|
-- > { manageHook = newFh <+> manageHook def
|
||||||
-- > , logHook = acFh <+> logHook def
|
|
||||||
-- > , modMask = mod4Mask
|
-- > , modMask = mod4Mask
|
||||||
-- > }
|
-- > }
|
||||||
-- > `additionalKeys` [((mod4Mask, xK_v), toggleLock)]
|
-- > `additionalKeys` [((mod4Mask, xK_v), toggleLock)]
|
||||||
@ -214,30 +215,23 @@ import XMonad.Hooks.ManageHelpers (currentWs)
|
|||||||
-- - I need 'XMonad.Hooks.EwmhDesktops' module for enabling window
|
-- - I need 'XMonad.Hooks.EwmhDesktops' module for enabling window
|
||||||
-- activation.
|
-- activation.
|
||||||
-- - 'FocusHook' in 'manageHook' will be called /only/ for new windows.
|
-- - 'FocusHook' in 'manageHook' will be called /only/ for new windows.
|
||||||
-- - 'FocusHook' in 'logHook' will be called /only/ for activated windows.
|
-- - 'FocusHook' in 'setEwmhActivateHook' will be called /only/ for activated windows.
|
||||||
--
|
--
|
||||||
-- Alternatively, i may construct a single 'FocusHook' for both new and
|
-- Alternatively, i may construct a single 'FocusHook' for both new and
|
||||||
-- activated windows and then just add it to both 'manageHook' and 'logHook':
|
-- activated windows and then just add it to both 'manageHook' and 'setEwmhActivateHook':
|
||||||
--
|
--
|
||||||
-- > let fh :: ManageHook
|
-- > let fh :: Bool -> ManageHook
|
||||||
-- > fh = manageFocus $ (composeOne
|
-- > fh activated = manageFocus $ composeOne
|
||||||
-- > [ liftQuery activated -?> activateFocusHook
|
-- > [ pure activated -?> activateFocusHook
|
||||||
-- > , Just <$> newFocusHook
|
-- > , pure True -?> newFocusHook
|
||||||
-- > ])
|
-- > ]
|
||||||
-- > xcf = ewmh $ def
|
-- > xcf = setEwmhActivateHook (fh True)
|
||||||
-- > { manageHook = fh <+> manageHook def
|
-- > . ewmh $ def
|
||||||
-- > , logHook = activateLogHook fh <+> logHook def
|
-- > { manageHook = fh False <+> manageHook def
|
||||||
-- > , modMask = mod4Mask
|
-- > , modMask = mod4Mask
|
||||||
-- > }
|
-- > }
|
||||||
-- > `additionalKeys` [((mod4Mask, xK_v), toggleLock)]
|
-- > `additionalKeys` [((mod4Mask, xK_v), toggleLock)]
|
||||||
--
|
--
|
||||||
-- Note:
|
|
||||||
-- - Predicate 'activated' will be 'True' for activated window.
|
|
||||||
-- - The order, when constructing final 'FocusHook': 'FocusHook' without
|
|
||||||
-- 'activated' predicate will match to activated windows too, thus i should
|
|
||||||
-- place it after one with 'activated' (so the latter will have a chance to
|
|
||||||
-- handle activated window first).
|
|
||||||
--
|
|
||||||
-- And more technical notes:
|
-- And more technical notes:
|
||||||
--
|
--
|
||||||
-- - 'FocusHook' will run /many/ times, so it usually should not keep state
|
-- - 'FocusHook' will run /many/ times, so it usually should not keep state
|
||||||
@ -264,11 +258,6 @@ import XMonad.Hooks.ManageHelpers (currentWs)
|
|||||||
--
|
--
|
||||||
-- now @FH2@ will see window shift made by @FH1@.
|
-- now @FH2@ will see window shift made by @FH1@.
|
||||||
--
|
--
|
||||||
-- Also, note, that if several 'activateLogHook'-s are sequenced, only
|
|
||||||
-- /first/ one (leftmost) will run. Thus, to make above working,
|
|
||||||
-- 'mappend' all 'ManageHook'-s first, and then run by /single/
|
|
||||||
-- 'activateLogHook' (see next example).
|
|
||||||
--
|
|
||||||
-- Another interesting example is moving all activated windows to current
|
-- Another interesting example is moving all activated windows to current
|
||||||
-- workspace by default, and applying 'FocusHook' after:
|
-- workspace by default, and applying 'FocusHook' after:
|
||||||
--
|
--
|
||||||
@ -281,14 +270,14 @@ import XMonad.Hooks.ManageHelpers (currentWs)
|
|||||||
-- >
|
-- >
|
||||||
-- > main :: IO ()
|
-- > main :: IO ()
|
||||||
-- > main = do
|
-- > main = do
|
||||||
-- > let fh :: ManageHook
|
-- > let fh :: Bool -> ManageHook
|
||||||
-- > fh = manageFocus $ (composeOne
|
-- > fh activated = manageFocus $ composeOne
|
||||||
-- > [ liftQuery activated -?> (newOnCur --> keepFocus)
|
-- > [ pure activated -?> (newOnCur --> keepFocus)
|
||||||
-- > , Just <$> newFocusHook
|
-- > , pure True -?> newFocusHook
|
||||||
-- > ])
|
-- > ]
|
||||||
-- > xcf = ewmh $ def
|
-- > xcf = setEwmhActivateHook (fh True <+> activateOnCurrentWs)
|
||||||
-- > { manageHook = fh <+> manageHook def
|
-- > . ewmh $ def
|
||||||
-- > , logHook = activateLogHook (fh <+> activateOnCurrentWs) <+> logHook def
|
-- > { manageHook = fh False <+> manageHook def
|
||||||
-- > , modMask = mod4Mask
|
-- > , modMask = mod4Mask
|
||||||
-- > }
|
-- > }
|
||||||
-- > `additionalKeys` [((mod4Mask, xK_v), toggleLock)]
|
-- > `additionalKeys` [((mod4Mask, xK_v), toggleLock)]
|
||||||
@ -319,11 +308,10 @@ import XMonad.Hooks.ManageHelpers (currentWs)
|
|||||||
--
|
--
|
||||||
-- - i keep focus, when activated window appears on current workspace, in
|
-- - i keep focus, when activated window appears on current workspace, in
|
||||||
-- this example.
|
-- this example.
|
||||||
-- - when @liftQuery activated -?> (newOnCur --> keepFocus)@ runs, activated
|
-- - when @pure activated -?> (newOnCur --> keepFocus)@ runs, activated
|
||||||
-- window will be /already/ on current workspace, thus, if i do not want to
|
-- window will be /already/ on current workspace, thus, if i do not want to
|
||||||
-- move some activated windows, i should filter them out before applying
|
-- move some activated windows, i should filter them out before applying
|
||||||
-- @activateOnCurrentWs@ 'FocusHook'.
|
-- @activateOnCurrentWs@ 'FocusHook'.
|
||||||
-- - i 'mappend' all 'ManageHook'-s and run 'activateLogHook' only once.
|
|
||||||
|
|
||||||
|
|
||||||
-- FocusQuery.
|
-- FocusQuery.
|
||||||
@ -552,21 +540,22 @@ when' b mx
|
|||||||
-- $examples
|
-- $examples
|
||||||
|
|
||||||
-- | Default EWMH window activation behavior: switch to workspace with
|
-- | Default EWMH window activation behavior: switch to workspace with
|
||||||
-- activated window and switch focus to it.
|
-- activated window and switch focus to it. Not to be used in a 'manageHook'.
|
||||||
activateSwitchWs :: ManageHook
|
activateSwitchWs :: ManageHook
|
||||||
activateSwitchWs = manageFocus (switchWorkspace <+> switchFocus)
|
activateSwitchWs = manageFocus (switchWorkspace <+> switchFocus)
|
||||||
|
|
||||||
-- | Move activated window to current workspace.
|
-- | Move activated window to current workspace. Not to be used in a 'manageHook'.
|
||||||
activateOnCurrent' :: ManageHook
|
activateOnCurrent' :: ManageHook
|
||||||
activateOnCurrent' = currentWs >>= unlessFocusLock . doShift
|
activateOnCurrent' = currentWs >>= unlessFocusLock . doShift
|
||||||
|
|
||||||
-- | Move activated window to current workspace and switch focus to it. Note,
|
-- | Move activated window to current workspace and switch focus to it. Note,
|
||||||
-- that i need to explicitly call 'switchFocus' here, because otherwise, when
|
-- that i need to explicitly call 'switchFocus' here, because otherwise, when
|
||||||
-- activated window is /already/ on current workspace, focus won't be
|
-- activated window is /already/ on current workspace, focus won't be
|
||||||
-- switched.
|
-- switched. Not to be used in a 'manageHook'.
|
||||||
activateOnCurrentWs :: ManageHook
|
activateOnCurrentWs :: ManageHook
|
||||||
activateOnCurrentWs = manageFocus (newOnCur --> switchFocus) <+> activateOnCurrent'
|
activateOnCurrentWs = manageFocus (newOnCur --> switchFocus) <+> activateOnCurrent'
|
||||||
|
|
||||||
-- | Move activated window to current workspace, but keep focus unchanged.
|
-- | Move activated window to current workspace, but keep focus unchanged.
|
||||||
|
-- Not to be used in a 'manageHook'.
|
||||||
activateOnCurrentKeepFocus :: ManageHook
|
activateOnCurrentKeepFocus :: ManageHook
|
||||||
activateOnCurrentKeepFocus = manageFocus (newOnCur --> keepFocus) <+> activateOnCurrent'
|
activateOnCurrentKeepFocus = manageFocus (newOnCur --> keepFocus) <+> activateOnCurrent'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user