summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/X11
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/X11
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/X11')
-rw-r--r--src/Xmobar/X11/Loop.hs36
1 files changed, 18 insertions, 18 deletions
diff --git a/src/Xmobar/X11/Loop.hs b/src/Xmobar/X11/Loop.hs
index 0451697..5f0a762 100644
--- a/src/Xmobar/X11/Loop.hs
+++ b/src/Xmobar/X11/Loop.hs
@@ -58,8 +58,9 @@ import qualified Xmobar.X11.Window as W
import qualified Xmobar.X11.Events as E
#endif
-data Act = Run R.Runnable | Act [A.Action]
-type Acts = [(Act, D.Position, D.Position)]
+data Act = Run R.Runnable | Act [A.Action] deriving Show
+type ActPos = (Act, D.Position, D.Position)
+type Acts = [ActPos]
runX :: T.XConf -> T.X a -> IO a
runX xc f = MR.runReaderT f xc
@@ -108,13 +109,6 @@ eventLoop dpy w signalv =
where (b, p) = (X11x.ev_button ev, fromIntegral $ X11x.ev_x ev)
_ -> return ()
-completeActions :: [R.Runnable] -> D.Actions -> Acts -> Acts
-completeActions [] _ res = reverse res
-completeActions _ [] res = reverse res
-completeActions (r:rs) (([], x, y):as) res =
- completeActions rs as ((Run r, x, y):res)
-completeActions (_:rs) ((a, x, y):as) res =
- completeActions rs as ((Act a, x, y):res)
-- | Continuously wait for a signal from a thread or an interrupt handler.
-- The list of actions provides the positions of clickable rectangles,
@@ -124,10 +118,9 @@ signalLoop :: T.XConf -> [R.Runnable] -> D.Actions
-> STM.TMVar S.SignalType -> STM.TVar [String] -> IO ()
signalLoop xc@(T.XConf d r w fs is cfg) runs actions signalv strs = do
typ <- STM.atomically $ STM.takeTMVar signalv
- let acts = completeActions runs actions []
case typ of
S.Wakeup -> wakeup
- S.Action button x -> runActs acts button x >> loopOn
+ S.Action button x -> runActions runs actions button x >> loopOn
S.Reposition -> reposWindow cfg
S.ChangeScreen -> updateConfigPosition d cfg >>= reposWindow
S.Hide t -> hiderev t S.Hide W.hideWindow
@@ -185,14 +178,21 @@ updateConfigPosition disp cfg =
else (cfg {C.position = C.OnScreen (n+1) o}))
o -> return (cfg {C.position = C.OnScreen 1 o})
-runAct :: A.Button -> Act -> IO ()
-runAct b (Run r) = E.onClick r b
-runAct b (Act as) =
+toActs :: [R.Runnable] -> D.Actions -> Acts -> Acts
+toActs [] _ res = reverse res
+toActs _ [] res = reverse res
+toActs (r:rs) (([a], x, y):as) res
+ | A.isEmpty a = toActs rs as ((Run r, x, y):res)
+toActs rs ((a, x, y):as) res = toActs rs as ((Act a, x, y):res)
+
+runAct :: A.Button -> ActPos -> IO ()
+runAct b ((Run r), _, _) = E.onClick r b
+runAct b ((Act as), _, _) =
mapM_ A.runAction $ filter (\(A.Spawn bs _) -> b `elem` bs) as
-runActs:: Acts -> A.Button -> X11.Position -> IO ()
-runActs acts button pos =
+runActions :: [R.Runnable] -> D.Actions -> A.Button -> X11.Position -> IO ()
+runActions runs actions button pos =
mapM_ (runAct button) $
- map (\(a, _, _) -> a) $
- filter (\(_, from, to) -> pos' >= from && pos' <= to) acts
+ filter (\(_, from, to) -> pos' >= from && pos' < to) acts
where pos' = fromIntegral pos
+ acts = toActs runs actions []