diff --git a/CHANGES.md b/CHANGES.md index 0e37ef17..80b4f98b 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -232,6 +232,11 @@ - The `emacsLikeXPKeymap` and `vimLikeXPKeymap` keymaps now treat `C-m` the same as `Return`. + * `XMonad.Actions.Prefix` + + - Added `orIfPrefixed`, a combinator to decide upon an action based + on whether any prefix argument was given. + ### Other changes ## 0.17.1 (September 3, 2022) diff --git a/XMonad/Actions/Prefix.hs b/XMonad/Actions/Prefix.hs index 8404674b..3890416b 100644 --- a/XMonad/Actions/Prefix.hs +++ b/XMonad/Actions/Prefix.hs @@ -29,6 +29,7 @@ module XMonad.Actions.Prefix , withPrefixArgument , isPrefixRaw , isPrefixNumeric + , orIfPrefixed , ppFormatPrefix ) where @@ -173,7 +174,7 @@ handlePrefixArg events = do -- -- First, fetch the current prefix, then pass it as argument to the -- original function. You should use this to "run" your commands. -withPrefixArgument :: (PrefixArgument -> X ()) -> X () +withPrefixArgument :: (PrefixArgument -> X a) -> X a withPrefixArgument = (>>=) XS.get -- | Test if 'PrefixArgument' is 'Raw' or not. @@ -186,6 +187,13 @@ isPrefixNumeric :: PrefixArgument -> Bool isPrefixNumeric (Numeric _) = True isPrefixNumeric _ = False +-- | Execute the first action, unless any prefix argument is given, +-- in which case the second action is chosen instead. +-- +-- > action1 `orIfPrefixed` action2 +orIfPrefixed :: X a -> X a -> X a +orIfPrefixed xa xb = withPrefixArgument $ bool xa xb . isPrefixRaw + -- | Format the prefix using the Emacs convetion for use in a -- statusbar, like xmobar. --