{-# LANGUAGE OverloadedStrings #-}-- | This widget listens on DBus for Log events from XMonad and-- displays the formatted status string. To log to this widget using-- the excellent dbus-core library, use code like the following:---- > import DBus.Client.Simple-- > main = do-- > session <- connectSession-- > emit session "/org/xmonad/Log" "org.xmonad.Log" "Update" [toVariant "msg"]---- There is a more complete example of xmonad integration in the-- top-level module.moduleSystem.Taffybar.XMonadLog(-- * ConstructorxmonadLogNew,-- * Log hooks for xmonad.hsdbusLog,dbusLogWithPP,-- * StylestaffybarPP,taffybarDefaultPP,taffybarColor,taffybarEscape)whereimportCodec.Binary.UTF8.String(decodeString)importDBus.Client.Simple(connectSession,emit,Client)importDBus.Client(listen,MatchRule(..))importDBus.TypesimportDBus.MessageimportGraphics.UI.Gtkhiding(Signal)importXMonadimportXMonad.Hooks.DynamicLogimportWeb.Encodings(decodeHtml,encodeHtml)-- | This is a DBus-based logger that can be used from XMonad to log-- to this widget. This version lets you specify the format for the-- log using a pretty printer (e.g., 'taffybarPP').dbusLogWithPP::Client->PP->X()dbusLogWithPPclientpp=dynamicLogWithPPpp{ppOutput=outputThroughDBusclient}-- | A DBus-based logger with a default pretty-print configurationdbusLog::Client->X()dbusLogclient=dbusLogWithPPclienttaffybarDefaultPPtaffybarColor::String->String->String->StringtaffybarColorfgbg=wrapt"</span>".taffybarEscapewheret=concat["<span fgcolor=\"",fg,ifnullbgthen""else"\" bgcolor=\""++bg,"\">"]-- | Escape strings so that they can be safely displayed by Pango in-- the bar widgettaffybarEscape::String->StringtaffybarEscape=encodeHtml.decodeHtml-- | The same as defaultPP in XMonad.Hooks.DynamicLogtaffybarDefaultPP::PPtaffybarDefaultPP=defaultPP{ppCurrent=taffybarEscape.wrap"[""]",ppVisible=taffybarEscape.wrap"<"">",ppHidden=taffybarEscape,ppHiddenNoWindows=taffybarEscape,ppUrgent=taffybarEscape,ppTitle=taffybarEscape.shorten80,ppLayout=taffybarEscape}-- | The same as xmobarPP in XMonad.Hooks.DynamicLogtaffybarPP::PPtaffybarPP=taffybarDefaultPP{ppCurrent=taffybarColor"yellow""".wrap"[""]",ppTitle=taffybarColor"green""".shorten40,ppVisible=wrap"("")",ppUrgent=taffybarColor"red""yellow"}outputThroughDBus::Client->String->IO()outputThroughDBusclientstr=do-- The string that we get from XMonad here isn't quite a normal-- string - each character is actually a byte in a utf8 encoding.-- We need to decode the string back into a real String before we-- send it over dbus.letstr'=decodeStringstremitclient"/org/xmonad/Log""org.xmonad.Log""Update"[toVariantstr']setupDbus::Label->IO()setupDbusw=doletmatcher=MatchRule{matchSender=Nothing,matchDestination=Nothing,matchPath=Just"/org/xmonad/Log",matchInterface=Just"org.xmonad.Log",matchMember=Just"Update"}client<-connectSessionlistenclientmatcher(callbackw)callback::Label->BusName->Signal->IO()callbackw_sig=dolet[bdy]=signalBodysigJuststatus=fromVariantbdypostGUIAsync$labelSetMarkupwstatus-- | Return a new XMonad log widgetxmonadLogNew::IOWidgetxmonadLogNew=dol<-labelNewNothing_<-onlrealize$setupDbuslwidgetShowAlllreturn(toWidgetl)