xmonad-contrib/XMonad/Actions/PerLayoutKeys.hs
Tony Zorman 3d65a6bf72 Refer to the tutorial instead of X.D.Extending more often
Essentially, whenever the tutorial actually has decent material on the
subject matter.  The replacement is roughly done as follows:

  - logHook → tutorial
  - keybindings → tutorial, as this is thoroughly covered
  - manageHook → tutorial + X.D.Extending, as the manageHook stuff the
    tutorial talks about is a little bit of an afterthought.
  - X.D.Extending (on its own) → tutorial + X.D.Extending
  - layoutHook → tutorial + X.D.Extending, as the tutorial, while
    talking about layouts, doesn't necessarily have a huge focus there.
  - mouse bindings → leave this alone, as the tutorial does not at all
    talk about them.
2022-10-21 09:17:43 +02:00

50 lines
1.9 KiB
Haskell

-----------------------------------------------------------------------------
-- |
-- Module : XMonad.Actions.PerLayoutKeys
-- Description : Define key-bindings on per-layout basis.
-- Copyright : (c) brandon s allbery kf8nh 2022, Roman Cheplyaka, 2008
-- License : BSD3-style (see LICENSE)
--
-- Maintainer : brandon s allbery kf8ng <allbery.b@gmail.com>
-- Stability : unstable
-- Portability : unportable
--
-- Define key-bindings on per-layout basis.
--
-----------------------------------------------------------------------------
module XMonad.Actions.PerLayoutKeys (
-- * Usage
-- $usage
chooseActionByLayout,
bindByLayout
) where
import XMonad
import XMonad.StackSet as S
-- $usage
--
-- You can use this module with the following in your @~\/.xmonad\/xmonad.hs@:
--
-- > import XMonad.Actions.PerLayoutKeys
--
-- > ,((0, xK_F2), bindByLayout [("Tall", spawn "rxvt"), ("Mirror Tall", spawn "xeyes"), ("", spawn "xmessage hello")])
--
-- For detailed instructions on editing your key bindings, see
-- <https://xmonad.org/TUTORIAL.html#customizing-xmonad the tutorial>.
-- | Uses supplied function to decide which action to run depending on current layout name.
chooseActionByLayout :: (String->X()) -> X()
chooseActionByLayout f = withWindowSet (f . description . S.layout. S.workspace . S.current)
-- | If current layout is listed, run appropriate action (only the first match counts!)
-- If it isn't listed, then run default action (marked with empty string, \"\"), or do nothing if default isn't supplied.
bindByLayout :: [(String, X())] -> X()
bindByLayout bindings = chooseActionByLayout chooser where
chooser l = case lookup l bindings of
Just action -> action
Nothing -> case lookup "" bindings of
Just action -> action
Nothing -> return ()