summaryrefslogtreecommitdiffhomepage
path: root/scripts/xmonadpropwrite.hs
diff options
context:
space:
mode:
authorTomas Janousek <tomi@nomi.cz>2009-11-20 15:44:26 +0100
committerTomas Janousek <tomi@nomi.cz>2009-11-20 15:44:26 +0100
commitf0ebea1d9095c151405f0fb45603dfdd721f12f7 (patch)
tree74bf51f7da682221026e0dadcd142e9e968d6810 /scripts/xmonadpropwrite.hs
parentbffbb688f0ff79e130b5c5a783d4142d402f1a30 (diff)
downloadxmobar-f0ebea1d9095c151405f0fb45603dfdd721f12f7.tar.gz
xmobar-f0ebea1d9095c151405f0fb45603dfdd721f12f7.tar.bz2
extend XMonadLog with XPropertyLog
Ignore-this: baec7062f93ab5950f57c44876c2f XMonadLog can be even more awesome with the ability to gather input from custom sources. This patch adds exactly that, along with a script to read from pipe and write to xmobar using an X property. darcs-hash:20091120144426-c9ff5-596f8b40c4b3df6ede43832b147e95e48ad582ba.gz
Diffstat (limited to 'scripts/xmonadpropwrite.hs')
-rw-r--r--scripts/xmonadpropwrite.hs41
1 files changed, 41 insertions, 0 deletions
diff --git a/scripts/xmonadpropwrite.hs b/scripts/xmonadpropwrite.hs
new file mode 100644
index 0000000..476a5db
--- /dev/null
+++ b/scripts/xmonadpropwrite.hs
@@ -0,0 +1,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 Codec.Binary.UTF8.String as UTF8
+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 <- getLine
+ changeProperty8 d root xlog ustring propModeReplace (encodeCChar msg)
+ sync d True
+
+ return ()
+
+encodeCChar :: String -> [CChar]
+encodeCChar = map fromIntegral . UTF8.encode