summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/Config
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2025-02-12 02:06:55 +0000
committerjao <jao@gnu.org>2025-02-12 02:06:55 +0000
commitde7a0aff77114638f3e83835de0fe00395fe6bf7 (patch)
treefb7fd61650298e812d2e307e13070520928fb89b /src/Xmobar/Config
parentaf4390e1f9152ba1bd3142a5ce5b63313e9747f9 (diff)
downloadxmobar-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/Config')
-rw-r--r--src/Xmobar/Config/Template.hs9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/Xmobar/Config/Template.hs b/src/Xmobar/Config/Template.hs
index ad30c3d..6ea1898 100644
--- a/src/Xmobar/Config/Template.hs
+++ b/src/Xmobar/Config/Template.hs
@@ -1,7 +1,7 @@
------------------------------------------------------------------------------
-- |
-- Module: Xmobar.Config.Template
--- Copyright: (c) 2022 jao
+-- Copyright: (c) 2022, 2025 jao
-- License: BSD3-style (see LICENSE)
--
-- Maintainer: mail@jao.io
@@ -15,7 +15,7 @@
------------------------------------------------------------------------------
-module Xmobar.Config.Template (parseString) where
+module Xmobar.Config.Template (parseString, withEmptyAction) where
import Data.Maybe (fromMaybe)
import qualified Control.Monad as CM
@@ -101,11 +101,14 @@ hspaceParser c = do
pVal <- C.manyTill P.digit (P.try (P.string "/>"))
retSegment c (T.Hspace (fromMaybe 0 $ readMaybe pVal))
+withEmptyAction :: String -> String
+withEmptyAction str = "<action=>" ++ str ++ "</action>"
+
actionParser :: Context -> Parser [T.Segment]
actionParser (ti, fi, act) = do
P.string "<action="
command <- C.between (P.char '`') (P.char '`') (C.many1 (P.noneOf "`"))
- <|> C.many1 (P.noneOf ">")
+ <|> C.many1 (P.noneOf ">") <|> P.string ""
buttons <- (P.char '>' >> return "1") <|> (P.space >> P.spaces >>
C.between (P.string "button=") (P.string ">") (C.many1 (P.oneOf "12345")))
let a = T.Spawn (toButtons buttons) command