summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Plugins/XMonadLog.hs12
-rw-r--r--scripts/xmonadpropwrite.hs41
2 files changed, 50 insertions, 3 deletions
diff --git a/Plugins/XMonadLog.hs b/Plugins/XMonadLog.hs
index 34fae31..3461e26 100644
--- a/Plugins/XMonadLog.hs
+++ b/Plugins/XMonadLog.hs
@@ -30,13 +30,19 @@ import Foreign.C (CChar)
import XUtil (nextEvent')
-data XMonadLog = XMonadLog
+data XMonadLog = XMonadLog | XPropertyLog String
deriving (Read, Show)
instance Exec XMonadLog where
- start XMonadLog cb = do
+ alias XMonadLog = "XMonadLog"
+ alias (XPropertyLog atom) = atom
+
+ start x cb = do
+ let atom = case x of
+ XMonadLog -> "_XMONAD_LOG"
+ XPropertyLog a -> a
d <- openDisplay ""
- xlog <- internAtom d "_XMONAD_LOG" False
+ xlog <- internAtom d atom False
root <- rootWindow d (defaultScreen d)
selectInput d root propertyChangeMask
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