diff options
| author | Josh Rahm <joshuarahm@gmail.com> | 2022-11-21 20:57:42 -0700 |
|---|---|---|
| committer | Josh Rahm <joshuarahm@gmail.com> | 2022-11-21 20:57:42 -0700 |
| commit | 8888a83ef06d16d4bdd3c06bef721fff43f04175 (patch) | |
| tree | f94c6175c935a05846b6322d29625e354ff2cd17 /src/Rahm/Desktop/XMobarLog.hs | |
| parent | e76a1c089951a72055bc8fc35808ccfa8988ddec (diff) | |
| parent | 7d6e83479719e04b77a8230a7ecf03e971cd5fc6 (diff) | |
| download | rde-8888a83ef06d16d4bdd3c06bef721fff43f04175.tar.gz rde-8888a83ef06d16d4bdd3c06bef721fff43f04175.tar.bz2 rde-8888a83ef06d16d4bdd3c06bef721fff43f04175.zip | |
Merge branch 'v017' of josher.dev:rde into v017
Diffstat (limited to 'src/Rahm/Desktop/XMobarLog.hs')
| -rw-r--r-- | src/Rahm/Desktop/XMobarLog.hs | 129 |
1 files changed, 62 insertions, 67 deletions
diff --git a/src/Rahm/Desktop/XMobarLog.hs b/src/Rahm/Desktop/XMobarLog.hs index 6cf4364..dbe4808 100644 --- a/src/Rahm/Desktop/XMobarLog.hs +++ b/src/Rahm/Desktop/XMobarLog.hs @@ -1,26 +1,25 @@ -module Rahm.Desktop.XMobarLog ( XMobarLog, spawnXMobar, xMobarLogHook ) where +module Rahm.Desktop.XMobarLog (XMobarLog, spawnXMobar, xMobarLogHook) where import Control.Arrow (second) -import Control.Monad (forM_) -import Control.Monad.Writer (tell, execWriter) +import Control.Monad (forM_, unless) +import Control.Monad.Writer (execWriter, tell) +import Data.Char (isAsciiLower, isAsciiUpper, isDigit) import Data.List (sortBy) -import Data.Maybe (mapMaybe, isJust) +import Data.Maybe (isJust, mapMaybe) import Data.Ord (comparing) -import Data.Char (isAsciiLower, isAsciiUpper, isDigit) import Rahm.Desktop.Layout.Draw (drawLayout) -import System.IO (Handle, hSetEncoding, hPutStrLn, utf8) -import XMonad.Util.NamedWindows (getName) -import XMonad.Util.Run (spawnPipe) -import XMonad (X) -import Rahm.Desktop.Workspaces (getPopulatedWorkspaces, WorkspaceState(..)) -import Text.Printf import Rahm.Desktop.Logger +import qualified Rahm.Desktop.StackSet as S import Rahm.Desktop.Theater (getTheaters) - +import Rahm.Desktop.Workspaces (WorkspaceState (..), getPopulatedWorkspaces) +import System.IO (Handle, hPutStrLn, hSetEncoding, utf8) +import Text.Printf +import XMonad (X) import qualified XMonad as X -import qualified Rahm.Desktop.StackSet as S +import XMonad.Util.NamedWindows (getName) +import XMonad.Util.Run (spawnPipe) -data XMobarLog = XMobarLog Handle +newtype XMobarLog = XMobarLog Handle -- The log hook for XMobar. This is a custom log hook that does not use any -- of the Xmonad dynamic log libraries. @@ -35,7 +34,6 @@ spawnXMobar = do hSetEncoding pipe utf8 return (XMobarLog pipe) - -- XMonad Log Hook meant to be used with the XMonad config logHook. xMobarLogHook :: XMobarLog -> X () xMobarLogHook (XMobarLog xmproc) = do @@ -48,66 +46,64 @@ xMobarLogHook (XMobarLog xmproc) = do title <- maybe (pure "") (fmap show . getName) . S.peek $ winset let wss = getPopulatedWorkspaces winset - let log = trunc 80 $ execWriter $ do - tell " " - tell (toChangeLayoutAction layoutXpm) - tell " " - tell $ logLevelToXMobar loglevel - - forM_ theaters $ \theater -> case theater of - (Just n, _, True) -> do - tell "<fn=1><fc=#ffffff>" - tell $ toTheaterAction n - tell " </fc></fn>" - - (Just n, _, False) -> do - tell "<fn=2><fc=#888888>" - tell $ toTheaterAction n - tell " </fc></fn>" - - _ -> return () - - if not (null theaters) - then tell "<fc=#888888>| </fc>" - else return () - - forM_ wss $ \(t, ws) -> do - case t of - Current -> tell "<fn=1><fc=#ff8888>" - Visible -> tell "<fn=6><fc=#8888ff>" - Hidden -> tell "<fn=2><fc=#888888>" - - tell $ toAction $ S.tag ws - tell " </fc></fn>" - - tell " <fc=#ff8888><fn=3>" - tell title - tell "</fn></fc>" + let log = trunc 80 $ + execWriter $ do + tell " " + tell (toChangeLayoutAction layoutXpm) + tell " " + tell $ logLevelToXMobar loglevel + + forM_ theaters $ \theater -> case theater of + (Just n, _, True) -> do + tell "<fn=1><fc=#ffffff>" + tell $ toTheaterAction n + tell " </fc></fn>" + (Just n, _, False) -> do + tell "<fn=2><fc=#888888>" + tell $ toTheaterAction n + tell " </fc></fn>" + + unless (null theaters) $ do + tell "<fc=#888888>| </fc>" + + forM_ wss $ \(t, ws) -> do + case t of + Current -> tell "<fn=1><fc=#ff8888>" + Visible -> tell "<fn=6><fc=#8888ff>" + Hidden -> tell "<fn=2><fc=#888888>" + tell $ toAction $ S.tag ws + tell " </fc></fn>" + + tell " <fc=#ff8888><fn=3>" + tell title + tell "</fn></fc>" logs Trace "XMobar: %s" log X.io $ hPutStrLn xmproc log - where - toAction [ch] | isAsciiUpper ch || - isAsciiLower ch || - isDigit ch = - printf "<action=`xdotool key 'Hyper_L+g' '%s'` button=1><action=`xdotool key 'Hyper_L+Shift_L+g' '%s'` button=3>%s</action></action>" [ch] [ch] [ch] + toAction [ch] + | isAsciiUpper ch + || isAsciiLower ch + || isDigit ch = + printf "<action=`xdotool key 'Hyper_L+g' '%s'` button=1><action=`xdotool key 'Hyper_L+Shift_L+g' '%s'` button=3>%s</action></action>" [ch] [ch] [ch] toAction ch = ch - toTheaterAction [ch] | isAsciiUpper ch || - isAsciiLower ch || - isDigit ch = - printf "<action=`xdotool key 'Hyper_L+Shift_L+g' '%s'` button=1>%s</action>" [ch] [ch] + toTheaterAction [ch] + | isAsciiUpper ch + || isAsciiLower ch + || isDigit ch = + printf "<action=`xdotool key 'Hyper_L+Shift_L+g' '%s'` button=1>%s</action>" [ch] [ch] toTheaterAction ch = ch toChangeLayoutAction :: String -> String toChangeLayoutAction = - printf "<action=`xdotool key Hyper_L+space n` button=1>\ + printf + "<action=`xdotool key Hyper_L+space n` button=1>\ \<action=`xdotool key p` button=3>%s</action></action>" logLevelToXMobar Trace = "<fn=3><fc=#88ffff>[Trace]</fc></fn> " logLevelToXMobar Debug = "<fn=3><fc=#ff88ff>[Debug]</fc></fn> " - logLevelToXMobar Warn = "<fn=3><fc=#ffff88>[Warn] </fc></fn> " + logLevelToXMobar Warn = "<fn=3><fc=#ffff88>[Warn] </fc></fn> " logLevelToXMobar Error = "<fn=3><fc=#ff8888>[Error]</fc></fn> " logLevelToXMobar Fatal = "<fn=3><fc=#888888>[Fatal]</fc></fn> " logLevelToXMobar _ = "" @@ -118,15 +114,14 @@ trunc :: Int -> String -> String trunc amt str = reverse $ trunc' False amt str [] where trunc' _ _ [] acc = acc - trunc' ignore amt (a:as) acc = + trunc' ignore amt (a : as) acc = case a of '<' -> trunc' True amt as (a : acc) '>' -> trunc' False amt as (a : acc) _ -> if ignore then trunc' True amt as (a : acc) - else - case amt of - 0 -> trunc' False 0 as acc - 3 -> trunc' False 0 as ("..." ++ acc) - _ -> trunc' False (amt - 1) as (a : acc) + else case amt of + 0 -> trunc' False 0 as acc + 3 -> trunc' False 0 as ("..." ++ acc) + _ -> trunc' False (amt - 1) as (a : acc) |