mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-05-19 03:20:21 -07:00
X.A.Submap: Add visualSubmapSorted
This commit is contained in:
parent
cbdee7db6f
commit
abef527f73
@ -65,6 +65,11 @@
|
|||||||
(See also `XMonad.Hooks.FloatConfigureReq` and/or `XMonad.Util.Hacks`
|
(See also `XMonad.Hooks.FloatConfigureReq` and/or `XMonad.Util.Hacks`
|
||||||
for additional Steam client workarounds.)
|
for additional Steam client workarounds.)
|
||||||
|
|
||||||
|
* `XMonad.Actions.Submap`
|
||||||
|
|
||||||
|
- Added `visualSubmapSorted` to enable sorting of the keymap
|
||||||
|
descriptions.
|
||||||
|
|
||||||
### Other changes
|
### Other changes
|
||||||
|
|
||||||
## 0.18.0 (February 3, 2024)
|
## 0.18.0 (February 3, 2024)
|
||||||
|
@ -18,6 +18,7 @@ module XMonad.Actions.Submap (
|
|||||||
-- $usage
|
-- $usage
|
||||||
submap,
|
submap,
|
||||||
visualSubmap,
|
visualSubmap,
|
||||||
|
visualSubmapSorted,
|
||||||
submapDefault,
|
submapDefault,
|
||||||
submapDefaultWithKey,
|
submapDefaultWithKey,
|
||||||
|
|
||||||
@ -88,15 +89,32 @@ visualSubmap :: WindowConfig -- ^ The config for the spawned window.
|
|||||||
-> M.Map (KeyMask, KeySym) (String, X ())
|
-> M.Map (KeyMask, KeySym) (String, X ())
|
||||||
-- ^ A map @keybinding -> (description, action)@.
|
-- ^ A map @keybinding -> (description, action)@.
|
||||||
-> X ()
|
-> X ()
|
||||||
visualSubmap wc keys =
|
visualSubmap = visualSubmapSorted id
|
||||||
|
|
||||||
|
-- | Like 'visualSubmap', but is able to sort the descriptions.
|
||||||
|
-- For example,
|
||||||
|
--
|
||||||
|
-- > import Data.Ord (comparing, Down)
|
||||||
|
-- >
|
||||||
|
-- > visualSubmapSorted (sortBy (comparing Down)) def
|
||||||
|
--
|
||||||
|
-- would sort the @(key, description)@ pairs by their keys in descending
|
||||||
|
-- order.
|
||||||
|
visualSubmapSorted :: ([((KeyMask, KeySym), String)] -> [((KeyMask, KeySym), String)])
|
||||||
|
-- ^ A function to resort the descriptions
|
||||||
|
-> WindowConfig -- ^ The config for the spawned window.
|
||||||
|
-> M.Map (KeyMask, KeySym) (String, X ())
|
||||||
|
-- ^ A map @keybinding -> (description, action)@.
|
||||||
|
-> X ()
|
||||||
|
visualSubmapSorted sorted wc keys =
|
||||||
withSimpleWindow wc descriptions waitForKeyPress >>= \(m', s) ->
|
withSimpleWindow wc descriptions waitForKeyPress >>= \(m', s) ->
|
||||||
maybe (pure ()) snd (M.lookup (m', s) keys)
|
maybe (pure ()) snd (M.lookup (m', s) keys)
|
||||||
where
|
where
|
||||||
descriptions :: [String]
|
descriptions :: [String]
|
||||||
descriptions =
|
descriptions =
|
||||||
zipWith (\key desc -> keyToString key <> ": " <> desc)
|
map (\(key, desc) -> keyToString key <> ": " <> desc)
|
||||||
(M.keys keys)
|
. sorted
|
||||||
(map fst (M.elems keys))
|
$ zip (M.keys keys) (map fst (M.elems keys))
|
||||||
|
|
||||||
-- | Give a name to an action.
|
-- | Give a name to an action.
|
||||||
subName :: String -> X () -> (String, X ())
|
subName :: String -> X () -> (String, X ())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user