summaryrefslogtreecommitdiffhomepage
path: root/etc/xmonadpropwrite.hs
blob: f3f4a5dd4880a81341939b559b11488cdf406484 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
-- Copyright Spencer Janssen <spencerjanssen@gmail.com>
--           Tomas Janousek <tomi@nomi.cz>
-- BSD3 (see LICENSE)
--
-- Reads from standard input and writes to an X propery on root window.
-- To be used with XPropertyLog:
--  Add it to commands:
--      Run XPropertyLog "_XMONAD_LOG_CUSTOM"
--  Add it to the template:
--      template = "... %_XMONAD_LOG_CUSTOM% ..."
--  Run:
--      $ blah blah | xmonadpropwrite _XMONAD_LOG_CUSTOM

import Control.Monad
import Graphics.X11
import Graphics.X11.Xlib.Extras
import qualified Data.ByteString as B
import Foreign.C (CChar)
import System.IO
import System.Environment

main = do
    atom <- flip fmap getArgs $ \args -> case args of
        [a] -> a
        _   -> "_XMONAD_LOG"

    d <- openDisplay ""
    xlog <- internAtom d atom False
    ustring <- internAtom d "UTF8_STRING" False

    root  <- rootWindow d (defaultScreen d)

    forever $ do
        msg <- B.getLine
        changeProperty8 d root xlog ustring propModeReplace (encodeCChar msg)
        sync d True

    return ()

encodeCChar :: B.ByteString -> [CChar]
encodeCChar = map fromIntegral . B.unpack