xmonad-contrib-0.18.0: Community-maintained extensions for xmonad

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

XMonad.Hooks.RefocusLast

Contents

- Usage
  - Predicates
- Actions
- Types
- Library functions

Description

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 {
  - previous :: !Window
  - current :: !Window
  }
- 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 ``refocusLastWhen` pred` for some valid `pred`.

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 ``shiftRLWhen` pred` or ``refocusWhen` pred` as appropriate if you want the same behaviour in such cases.

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.

isFloat :: Query Bool Source #

Holds iff the event window is a float.

# 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`.

Constructors

Recent |

Fields

- previous :: !Window
- current :: !Window

#### Instances

Instances details

Read RecentWins Source # |
Instance details Defined in XMonad.Hooks.RefocusLast Methods readsPrec :: Int -> ReadS RecentWins Source # readList :: ReadS [RecentWins] Source # readPrec :: ReadPrec RecentWins Source # readListPrec :: ReadPrec [RecentWins] Source #
Show RecentWins Source # |
Instance details Defined in XMonad.Hooks.RefocusLast Methods showsPrec :: Int -> RecentWins -> ShowS Source # show :: RecentWins -> String Source # showList :: [RecentWins] -> ShowS Source #
Eq RecentWins Source # |
Instance details Defined in XMonad.Hooks.RefocusLast Methods (==) :: RecentWins -> RecentWins -> Bool Source # (/=) :: RecentWins -> RecentWins -> Bool Source #

newtype RecentsMap Source #

Newtype wrapper for a `Map` holding the `RecentWins` for each workspace. Is an instance of `ExtensionClass` with persistence of state.

Constructors

RecentsMap (Map WorkspaceId RecentWins) |

#### Instances

Instances details

Read RecentsMap Source # |
Instance details Defined in XMonad.Hooks.RefocusLast Methods readsPrec :: Int -> ReadS RecentsMap Source # readList :: ReadS [RecentsMap] Source # readPrec :: ReadPrec RecentsMap Source # readListPrec :: ReadPrec [RecentsMap] Source #
Show RecentsMap Source # |
Instance details Defined in XMonad.Hooks.RefocusLast Methods showsPrec :: Int -> RecentsMap -> ShowS Source # show :: RecentsMap -> String Source # showList :: [RecentsMap] -> ShowS Source #
Eq RecentsMap Source # |
Instance details Defined in XMonad.Hooks.RefocusLast Methods (==) :: RecentsMap -> RecentsMap -> Bool Source # (/=) :: RecentsMap -> RecentsMap -> Bool Source #
ExtensionClass RecentsMap Source # |
Instance details Defined in XMonad.Hooks.RefocusLast Methods initialValue :: RecentsMap Source # extensionType :: RecentsMap -> StateExtension Source #

data RefocusLastLayoutHook a Source #

A `LayoutModifier` that updates the `RecentWins` for a workspace upon relayout.

Constructors

RefocusLastLayoutHook |

#### Instances

Instances details

LayoutModifier RefocusLastLayoutHook a Source # |

Instance details

Defined in XMonad.Hooks.RefocusLast

Methods

modifyLayout :: LayoutClass l a => RefocusLastLayoutHook a -> Workspace WorkspaceId (l a) a -> Rectangle -> X ([(a, Rectangle)], Maybe (l a)) Source #

modifyLayoutWithUpdate :: LayoutClass l a => RefocusLastLayoutHook a -> Workspace WorkspaceId (l a) a -> Rectangle -> X (([(a, Rectangle)], Maybe (l a)), Maybe (RefocusLastLayoutHook a)) Source #

handleMess :: RefocusLastLayoutHook a -> SomeMessage -> X (Maybe (RefocusLastLayoutHook a)) Source #

handleMessOrMaybeModifyIt :: RefocusLastLayoutHook a -> SomeMessage -> X (Maybe (Either (RefocusLastLayoutHook a) SomeMessage)) Source #

pureMess :: RefocusLastLayoutHook a -> SomeMessage -> Maybe (RefocusLastLayoutHook a) Source #

redoLayout :: RefocusLastLayoutHook a -> Rectangle -> Maybe (Stack a) -> [(a, Rectangle)] -> X ([(a, Rectangle)], Maybe (RefocusLastLayoutHook a)) Source #

pureModifier :: RefocusLastLayoutHook a -> Rectangle -> Maybe (Stack a) -> [(a, Rectangle)] -> ([(a, Rectangle)], Maybe (RefocusLastLayoutHook a)) Source #

hook :: RefocusLastLayoutHook a -> X () Source #

unhook :: RefocusLastLayoutHook a -> X () Source #

modifierDescription :: RefocusLastLayoutHook a -> String Source #

modifyDescription :: LayoutClass l a => RefocusLastLayoutHook a -> l a -> String Source #

Read (RefocusLastLayoutHook a) Source # |
Instance details Defined in XMonad.Hooks.RefocusLast Methods readsPrec :: Int -> ReadS (RefocusLastLayoutHook a) Source # readList :: ReadS [RefocusLastLayoutHook a] Source # readPrec :: ReadPrec (RefocusLastLayoutHook a) Source # readListPrec :: ReadPrec [RefocusLastLayoutHook a] Source #
Show (RefocusLastLayoutHook a) Source # |
Instance details Defined in XMonad.Hooks.RefocusLast Methods showsPrec :: Int -> RefocusLastLayoutHook a -> ShowS Source # show :: RefocusLastLayoutHook a -> String Source # showList :: [RefocusLastLayoutHook a] -> ShowS Source #

newtype RefocusLastToggle Source #

A newtype on `Bool` to act as a universal toggle for refocusing.

Constructors

RefocusLastToggle |

Fields

- refocusing :: Bool

#### Instances

Instances details

Read RefocusLastToggle Source # |
Instance details Defined in XMonad.Hooks.RefocusLast Methods readsPrec :: Int -> ReadS RefocusLastToggle Source # readList :: ReadS [RefocusLastToggle] Source # readPrec :: ReadPrec RefocusLastToggle Source # readListPrec :: ReadPrec [RefocusLastToggle] Source #
Show RefocusLastToggle Source # |
Instance details Defined in XMonad.Hooks.RefocusLast Methods showsPrec :: Int -> RefocusLastToggle -> ShowS Source # show :: RefocusLastToggle -> String Source # showList :: [RefocusLastToggle] -> ShowS Source #
Eq RefocusLastToggle Source # |
Instance details Defined in XMonad.Hooks.RefocusLast Methods (==) :: RefocusLastToggle -> RefocusLastToggle -> Bool Source # (/=) :: RefocusLastToggle -> RefocusLastToggle -> Bool Source #
ExtensionClass RefocusLastToggle Source # |
Instance details Defined in XMonad.Hooks.RefocusLast Methods initialValue :: RefocusLastToggle Source # extensionType :: RefocusLastToggle -> StateExtension Source #

# 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.