scripts/xmonadpropread: Document and support custom props

This commit is contained in:
Tomas Janousek 2021-02-11 15:52:23 +00:00
parent cdc6c6d39c
commit ccebeb675d
2 changed files with 25 additions and 8 deletions

View File

@ -154,15 +154,16 @@ import XMonad.Hooks.ManageDocks
-- > } -- > }
-- --
-- If you don't have an @.xmobarrc@, create it; the @XMonadLog@ plugin is not -- If you don't have an @.xmobarrc@, create it; the @XMonadLog@ plugin is not
-- part of the default xmobar configuration and you status bar will not show -- part of the default xmobar configuration and your status bar will not show
-- otherwise! -- otherwise!
-- --
-- Because 'statusBarProp' lets you define your own executable, you can also -- Because 'statusBarProp' lets you define your own executable, you can also
-- give it a different status bar entirely; you only need to make sure that the -- give it a different status bar entirely; you only need to make sure that the
-- status bar supports reading a property string from the root window, or use -- status bar supports reading a property string from the root window, or use
-- some kind of wrapper that reads the property and pipes it into the bar. -- a wrapper that reads the property and pipes it into the bar (e.g.
-- @xmonadpropread | dzen2@, see @scripts/xmonadpropread.hs@).
-- --
-- If you don't want to read from the default property, you can specify your own -- If you don't want to use the default property, you can specify your own
-- with the 'statusBarPropTo' function. -- with the 'statusBarPropTo' function.
-- --
-- If your status bar does not support property-based logging, you may also try -- If your status bar does not support property-based logging, you may also try

View File

@ -1,20 +1,38 @@
-- Copyright Spencer Janssen <spencerjanssen@gmail.com> -- Copyright Spencer Janssen <spencerjanssen@gmail.com>
-- BSD3 (see LICENSE) -- BSD3 (see LICENSE)
-- --
-- Experimental, will add proper documentation later (famous last words) -- Reads from an X property on the root window and writes to standard output.
--
-- May be used together with XMonad.Hooks.DynamicLog.xmonadPropLog and a
-- status bar that doesn't support reading from properties itself, such as
-- dzen.
--
-- Usage:
--
-- $ xmonadpropread | dzen2
--
-- or
--
-- $ xmonadpropread _XMONAD_LOG_CUSTOM | dzen2
import Control.Monad import Control.Monad
import Graphics.X11 import Graphics.X11
import Graphics.X11.Xlib.Extras import Graphics.X11.Xlib.Extras
import Codec.Binary.UTF8.String as UTF8 import Codec.Binary.UTF8.String as UTF8
import Foreign.C (CChar) import Foreign.C (CChar)
import System.Environment
import System.IO import System.IO
main :: IO ()
main = do main = do
hSetBuffering stdout LineBuffering hSetBuffering stdout LineBuffering
atom <- flip fmap getArgs $ \args -> case args of
[a] -> a
_ -> "_XMONAD_LOG"
d <- openDisplay "" d <- openDisplay ""
xlog <- internAtom d "_XMONAD_LOG" False xlog <- internAtom d atom False
root <- rootWindow d (defaultScreen d) root <- rootWindow d (defaultScreen d)
selectInput d root propertyChangeMask selectInput d root propertyChangeMask
@ -28,7 +46,5 @@ main = do
maybe (return ()) (putStrLn . decodeCChar) mwp maybe (return ()) (putStrLn . decodeCChar) mwp
_ -> return () _ -> return ()
return ()
decodeCChar :: [CChar] -> String decodeCChar :: [CChar] -> String
decodeCChar = UTF8.decode . map fromIntegral decodeCChar = UTF8.decode . map fromIntegral