diff options
Diffstat (limited to 'src/Xmobar/X11/Loop.hs')
-rw-r--r-- | src/Xmobar/X11/Loop.hs | 36 |
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 [] |