Skip to content

Instantly share code, notes, and snippets.

@LSLeary
Last active September 22, 2018 03:02
Show Gist options
  • Save LSLeary/4085fc56a87a4aea35fa2b5227ca0eac to your computer and use it in GitHub Desktop.
Save LSLeary/4085fc56a87a4aea35fa2b5227ca0eac to your computer and use it in GitHub Desktop.
import XMonad
import XMonad.Util.Types
import qualified XMonad.StackSet as W
import qualified Data.Map.Strict as M
import Control.Monad (when)
-- | Shift a @RationalRect@ to an edge of the screen.
toScreenEdge :: Direction2D -> W.RationalRect -> W.RationalRect
toScreenEdge d (W.RationalRect x y w h) = case d of
U -> W.RationalRect x 0 w h
L -> W.RationalRect 0 y w h
D -> W.RationalRect x (1-h) w h
R -> W.RationalRect (1-w) y w h
-- | Apply a function to a window's @RationalRect@ if it's floating.
onRR :: (W.RationalRect -> W.RationalRect) -> Window -> X ()
onRR f w = withWindowSet $ \ws ->
whenJust (M.lookup w $ W.floating ws) $ \rr -> let rr' = f rr in
when (rr /= rr') (windows $ W.float w rr')
-- | Keybindings.
edgeKeys :: XConfig Layout -> M.Map (KeyMask, KeySym) (X ())
edgeKeys = \cnf -> M.fromList $ do
(e, key) <- zip [L, D, U, R] [xK_h, xK_t, xK_n, xK_s]
pure ((modMask cnf .|. shiftMask, key), toEdge e)
where toEdge = withFocused . onRR . toScreenEdge
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment