about summary refs log tree commit diff
path: root/src/XMonad/Actions/PerConditionKeys.hs
blob: 2099e1d8d5f6242bec919c14d9edefb6546f63b8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
-- |
-- Module      : XMonad.Actions.PerConditionKeys
-- Copyright   : (c) 2018-2019 Azat Bahawi <azahi@teknik.io>
-- License     : BSD3-style (see LICENSE)
-- Maintainer  : Azat Bahawi <azahi@teknik.io>
-- Stability   : unstable
-- Portability : unportable
--

module XMonad.Actions.PerConditionKeys
    ( XCond(..)
    , chooseAction
    , bindOn
    ) where

import           Data.List
import           XMonad
import qualified XMonad.StackSet as S

data XCond = WS | LD

chooseAction :: XCond -> (String -> X ()) -> X ()
chooseAction WS f = withWindowSet (f . S.currentTag)
chooseAction LD f = withWindowSet (f . description . S.layout . S.workspace . S.current)

bindOn :: XCond -> [(String, X ())] -> X ()
bindOn xc bindings = chooseAction xc chooser
    where chooser x = case find ((x ==) . fst) bindings of
                           Just (_, action) -> action
                           Nothing          -> case find (("" ==) . fst) bindings of
                                                    Just (_, action) -> action
                                                    Nothing          -> return ()

Consider giving Nix/NixOS a try! <3