Can xmonad logHook run at set intervals, and not in the (simple) response to layout events?

I use dynamicLogWithPPfrom XMonad.Hooks.DynamicLogalong with dzen2 as the status bar in xmonad. One of the things that I would like to display in the bar is the time remaining on the current game track in bold (if any). Getting this information is easy:

audStatus :: Player -> X (Maybe String)
audStatus p = do
  info <- liftIO $ tryS $ withPlayer p $ do
                ispaused <- paused
                md <- getMetadataString
                timeleftmillis <- (-) <$> (getCurrentTrack >>= songFrames) <*> time
                let artist = md ! "artist"
                    title = md ! "title"
                    timeleft = timeleftmillis `quot` 1000
                    (minutes, seconds) = timeleft `quotRem` 60
                    disp = artist ++ " - " ++ title ++ " (-"++(show minutes)++":"++(show seconds)++")" -- will be wrong if seconds < 10
                    audcolor False = dzenColor base0  base03
                    audcolor True = dzenColor base1 base02 
                return $ wrap "^ca(1, pms p)" "^ca()" (audcolor ispaused disp)
  return $ either (const Nothing) Just info

Therefore, I can stick to this in ppExtras, and it works fine - in addition, it only starts when it starts logHook, and this only happens when a suitable event leaves the pike. Thus, the display is potentially static for a long time, until I (for example) move to workspaces.

, , script. ? xmonad ( /)?

ETA: , , , :

  • TChan XMonad, Audacious;
  • ppOutput PP DynamicLog TChan;
  • TChan;
  • fork TChans ( , , ) .

XMonad , Audacious . , - .

+5
2

, , , , , , . xmonad. , , , , .

, XMonad.Util.Timer, X ( , ). , , .

XMonad.Util.ExtensibleState, Timer id, , , .

:

{-# LANGUAGE DeriveDataTypeable #-}

import qualified XMonad.Util.ExtensibleState as XS
import XMonad.Util.Timer

...

-- wrapper for the Timer id, so it can be stored as custom mutable state
data TidState = TID TimerId deriving Typeable

instance ExtensionClass TidState where
  initialValue = TID 0

...

-- put this in your startupHook
-- start the initial timer, store its id
clockStartupHook = startTimer 1 >>= XS.put . TID

-- put this in your handleEventHook
clockEventHook e = do               -- e is the event we've hooked
  (TID t) <- XS.get                 -- get the recent Timer id
  handleTimer t e $ do              -- run the following if e matches the id
    startTimer 1 >>= XS.put . TID   -- restart the timer, store the new id
    ask >>= logHook.config          -- get the loghook and run it
    return Nothing                  -- return required type
  return $ All True                 -- return required type

. , - .

+6

xmonad; xmonad (, , dzen's). , , , (, dmplex), .

xmobar taffybar, , dzen.

, TChan , "", " " " Runtime" FFI gtk, , xmonad - GHC. , xmonad FFI Xlib, X; Haskell, .

+2

All Articles