Skip to content

Commit

Permalink
X.U.PureX: Add focusWindow and focusNth
Browse files Browse the repository at this point in the history
This can be used to reduce flicker in noop focus actions.
  • Loading branch information
liskin committed Nov 5, 2020
1 parent aa67439 commit 068302b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@

- Export `Minimize` type constructor.

* `XMonad.Util.PureX`

- Added `focusWindow` and `focusNth` which don't refresh (and thus
possibly flicker) when they happen to be a no-op.

## 0.16

### Breaking Changes
Expand Down
18 changes: 18 additions & 0 deletions XMonad/Util/PureX.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ module XMonad.Util.PureX (
withWindowSet', withFocii,
modify'', modifyWindowSet',
getStack, putStack, peek,
focusWindow, focusNth,
view, greedyView, invisiView,
shift, curScreen, curWorkspace,
curTag, curScreenId,
Expand All @@ -52,6 +53,7 @@ module XMonad.Util.PureX (
-- xmonad
import XMonad
import qualified XMonad.StackSet as W
import qualified XMonad.Actions.FocusNth

-- mtl
import Control.Monad.State
Expand Down Expand Up @@ -272,5 +274,21 @@ shift tag = withFocii $ \ctag fw ->
mfw' <- peek
return (Any $ Just fw /= mfw')

-- | Internal. Refresh-tracking logic of focus operations.
focusWith :: XLike m => (WindowSet -> WindowSet) -> m Any
focusWith focuser = do
old <- peek
modifyWindowSet' focuser
new <- peek
return (Any $ old /= new)

-- | A refresh-tracking version of @W.focusWindow@.
focusWindow :: XLike m => Window -> m Any
focusWindow w = focusWith (W.focusWindow w)

-- | A refresh-tracking version of @XMonad.Actions.FocusNth.focusNth@.
focusNth :: XLike m => Int -> m Any
focusNth i = focusWith (W.modify' (XMonad.Actions.FocusNth.focusNth' i))

-- }}}

0 comments on commit 068302b

Please sign in to comment.