diff options
author | jao <jao@gnu.org> | 2025-02-12 02:06:55 +0000 |
---|---|---|
committer | jao <jao@gnu.org> | 2025-02-12 02:06:55 +0000 |
commit | de7a0aff77114638f3e83835de0fe00395fe6bf7 (patch) | |
tree | fb7fd61650298e812d2e307e13070520928fb89b /src/Xmobar/Run/Actions.hs | |
parent | af4390e1f9152ba1bd3142a5ce5b63313e9747f9 (diff) | |
download | xmobar-de7a0aff77114638f3e83835de0fe00395fe6bf7.tar.gz xmobar-de7a0aff77114638f3e83835de0fe00395fe6bf7.tar.bz2 |
on-click implementation based on implicit actions
Draw methods based on Segments don't keep enough information to fill in
correctly a list of actions. With this implementation, we introduce empty
actions as markers where Runnable instances can be inserted. Triggering them
is then just calling the corresponding Exec method, onClick.
Conceivably, onClick could receive some kind of additional state, but that's
better done as a base Plugin instance that keeps state and makes it available
via its onClick function, for instance.
Very lightly tested, needs documentation and extending the plugin example to
include an onClick method.
Diffstat (limited to 'src/Xmobar/Run/Actions.hs')
-rw-r--r-- | src/Xmobar/Run/Actions.hs | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/Xmobar/Run/Actions.hs b/src/Xmobar/Run/Actions.hs index cbc10c5..fc9682d 100644 --- a/src/Xmobar/Run/Actions.hs +++ b/src/Xmobar/Run/Actions.hs @@ -12,6 +12,7 @@ module Xmobar.Run.Actions ( Button , Action(..) + , isEmpty , runAction , runAction' , stripActions) where @@ -20,12 +21,17 @@ import System.Process (spawnCommand, waitForProcess) import Control.Monad (void) import Text.Regex (Regex, subRegex, mkRegex, matchRegex) import Data.Word (Word32) +import Data.Char (isSpace) type Button = Word32 data Action = Spawn [Button] String deriving (Eq, Read, Show) +isEmpty :: Action -> Bool +isEmpty (Spawn _ s) = all isSpace s + runAction :: Action -> IO () +runAction a | isEmpty a = return () runAction (Spawn _ s) = void $ spawnCommand (s ++ " &") >>= waitForProcess -- | Run action with stdout redirected to stderr |