Copyright | (c) 2018 L. S. Leary |
---|---|
License | BSD3-style (see LICENSE) |
Maintainer | L. S. Leary |
Stability | unstable |
Portability | unportable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Provides hooks and actions that keep track of recently focused windows on a per workspace basis and automatically refocus the last window on loss of the current (if appropriate as determined by user specified criteria).
Synopsis
- refocusLastLogHook :: X ()
- refocusLastLayoutHook :: l a -> ModifiedLayout RefocusLastLayoutHook l a
- refocusLastWhen :: Query Bool -> Event -> X All
- refocusingIsActive :: Query Bool
- isFloat :: Query Bool
- toggleRefocusing :: X ()
- toggleFocus :: X ()
- swapWithLast :: X ()
- refocusWhen :: Query Bool -> WorkspaceId -> X (WindowSet -> WindowSet)
- shiftRLWhen :: Query Bool -> WorkspaceId -> X (WindowSet -> WindowSet)
- updateRecentsOn :: WorkspaceId -> X ()
- data RecentWins = Recent {}
- newtype RecentsMap = RecentsMap (Map WorkspaceId RecentWins)
- data RefocusLastLayoutHook a = RefocusLastLayoutHook
- newtype RefocusLastToggle = RefocusLastToggle {
- refocusing :: Bool
- withRecentsIn :: WorkspaceId -> a -> (Window -> Window -> X a) -> X a
Usage
To use this module, you must either include refocusLastLogHook
in your log
hook or refocusLastLayoutHook
in your layout hook; don't use both.
This suffices to make use of both toggleFocus
and shiftRLWhen
but will
not refocus automatically upon loss of the current window; for that you must
include in your event hook
for some valid refocusLastWhen
predpred
.
The event hooks that trigger refocusing only fire when a window is lost
completely, not when it's simply e.g. moved to another workspace. Hence you
will need to use
or shiftRLWhen
pred
as appropriate
if you want the same behaviour in such cases.refocusWhen
pred
Example configuration:
import XMonad import XMonad.Hooks.RefocusLast import qualified Data.Map.Strict as M main :: IO () main = xmonad def { handleEventHook = refocusLastWhen myPred <> handleEventHook def , logHook = refocusLastLogHook <> logHook def -- , layoutHook = refocusLastLayoutHook $ layoutHook def , keys = refocusLastKeys <> keys def } where myPred = refocusingIsActive <||> isFloat refocusLastKeys cnf = M.fromList $ ((modMask cnf , xK_a), toggleFocus) : ((modMask cnf .|. shiftMask, xK_a), swapWithLast) : ((modMask cnf , xK_b), toggleRefocusing) : [ ( (modMask cnf .|. shiftMask, n) , windows =<< shiftRLWhen myPred wksp ) | (n, wksp) <- zip [xK_1..xK_9] (workspaces cnf) ]
refocusLastLogHook :: X () Source #
A log hook recording the current workspace's most recently focused windows into extensible state.
refocusLastLayoutHook :: l a -> ModifiedLayout RefocusLastLayoutHook l a Source #
Records a workspace's recently focused windows into extensible state upon
relayout. Potentially a less wasteful alternative to refocusLastLogHook
,
as it does not run on WM_NAME
propertyNotify
events.
refocusLastWhen :: Query Bool -> Event -> X All Source #
Given a predicate on the event window determining whether or not to act, construct an event hook that runs iff the core xmonad event handler will unmanage the window, and which shifts focus to the last focused window on the appropriate workspace if desired.
Predicates
Impure Query Bool
predicates on event windows for use as arguments to
refocusLastWhen
, shiftRLWhen
and refocusWhen
. Can be combined with
<||>
or <&&>
. Use like e.g.
, handleEventHook = refocusLastWhen refocusingIsActive
or in a keybinding:
windows =<< shiftRLWhen (refocusingIsActive <&&> isFloat) "3"
It's also valid to use a property lookup like className =? "someProgram"
as
a predicate, and it should function as expected with e.g. shiftRLWhen
.
In the event hook on the other hand, the window in question has already been
unmapped or destroyed, so external lookups to X properties don't work:
only the information fossilised in xmonad's state is available.
refocusingIsActive :: Query Bool Source #
Holds iff refocusing is toggled active.
Actions
toggleRefocusing :: X () Source #
Toggle automatic refocusing at runtime. Has no effect unless the
refocusingIsActive
predicate has been used.
toggleFocus :: X () Source #
Refocuses the previously focused window; acts as a toggle.
Is not affected by toggleRefocusing
.
swapWithLast :: X () Source #
Swaps the current and previous windows of the current workspace.
Is not affected by toggleRefocusing
.
refocusWhen :: Query Bool -> WorkspaceId -> X (WindowSet -> WindowSet) Source #
Given a target workspace and a predicate on its current window, produce a
windows
suitable function that will refocus that workspace appropriately.
Allows you to hook refocusing into any action you can run through
windows
. See the implementation of shiftRLWhen
for a straight-forward
usage example.
shiftRLWhen :: Query Bool -> WorkspaceId -> X (WindowSet -> WindowSet) Source #
Sends the focused window to the specified workspace, refocusing the last
focused window if the predicate holds on the current window. Note that the
native version of this, windows . W.shift
, has a nice property that this
does not: shifting a window to another workspace then shifting it back
preserves its place in the stack. Can be used in a keybinding like e.g.
windows =<< shiftRLWhen refocusingIsActive "3"
or
(windows <=< shiftRLWhen refocusingIsActive) "3"
where <=<
is imported from Control.Monad.
updateRecentsOn :: WorkspaceId -> X () Source #
Perform an update to the RecentWins
for the specified workspace.
The RefocusLast log and layout hooks are both implemented trivially in
terms of this function. Only exported to aid extensibility.
Types
The types and constructors used in this module are exported principally to aid extensibility; typical users will have nothing to gain from this section.
data RecentWins Source #
Data type holding onto the previous and current Window
.
Instances
Read RecentWins Source # | |
Defined in XMonad.Hooks.RefocusLast readsPrec :: Int -> ReadS RecentWins # readList :: ReadS [RecentWins] # readPrec :: ReadPrec RecentWins # readListPrec :: ReadPrec [RecentWins] # | |
Show RecentWins Source # | |
Defined in XMonad.Hooks.RefocusLast showsPrec :: Int -> RecentWins -> ShowS # show :: RecentWins -> String # showList :: [RecentWins] -> ShowS # | |
Eq RecentWins Source # | |
Defined in XMonad.Hooks.RefocusLast (==) :: RecentWins -> RecentWins -> Bool # (/=) :: RecentWins -> RecentWins -> Bool # |
newtype RecentsMap Source #
Newtype wrapper for a Map
holding the RecentWins
for each workspace.
Is an instance of ExtensionClass
with persistence of state.
Instances
Read RecentsMap Source # | |
Defined in XMonad.Hooks.RefocusLast readsPrec :: Int -> ReadS RecentsMap # readList :: ReadS [RecentsMap] # readPrec :: ReadPrec RecentsMap # readListPrec :: ReadPrec [RecentsMap] # | |
Show RecentsMap Source # | |
Defined in XMonad.Hooks.RefocusLast showsPrec :: Int -> RecentsMap -> ShowS # show :: RecentsMap -> String # showList :: [RecentsMap] -> ShowS # | |
Eq RecentsMap Source # | |
Defined in XMonad.Hooks.RefocusLast (==) :: RecentsMap -> RecentsMap -> Bool # (/=) :: RecentsMap -> RecentsMap -> Bool # | |
ExtensionClass RecentsMap Source # | |
Defined in XMonad.Hooks.RefocusLast |
data RefocusLastLayoutHook a Source #
A LayoutModifier
that updates the RecentWins
for a workspace upon
relayout.
Instances
newtype RefocusLastToggle Source #
A newtype on Bool
to act as a universal toggle for refocusing.
Instances
Read RefocusLastToggle Source # | |
Defined in XMonad.Hooks.RefocusLast | |
Show RefocusLastToggle Source # | |
Defined in XMonad.Hooks.RefocusLast showsPrec :: Int -> RefocusLastToggle -> ShowS # show :: RefocusLastToggle -> String # showList :: [RefocusLastToggle] -> ShowS # | |
Eq RefocusLastToggle Source # | |
Defined in XMonad.Hooks.RefocusLast (==) :: RefocusLastToggle -> RefocusLastToggle -> Bool # (/=) :: RefocusLastToggle -> RefocusLastToggle -> Bool # | |
ExtensionClass RefocusLastToggle Source # | |
Defined in XMonad.Hooks.RefocusLast |
Library functions
withRecentsIn :: WorkspaceId -> a -> (Window -> Window -> X a) -> X a Source #
Perform an X action dependent on successful lookup of the RecentWins for the specified workspace, or return a default value.