From ed50d0cb4b1e46a6fa531e610c0d8025d12a62ae Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Thu, 27 Jan 2011 00:39:37 +0100 Subject: xmonadpropwrite.hs back to the source package --- README | 8 +++++--- samples/xmonadpropwrite.hs | 41 +++++++++++++++++++++++++++++++++++++++++ scripts/xmonadpropwrite.hs | 41 ----------------------------------------- xmobar.cabal | 2 +- 4 files changed, 47 insertions(+), 45 deletions(-) create mode 100644 samples/xmonadpropwrite.hs delete mode 100644 scripts/xmonadpropwrite.hs diff --git a/README b/README index ae8cd43..a9ac6a5 100644 --- a/README +++ b/README @@ -654,9 +654,11 @@ Monitors have default aliases. - Aliases to `PropName` - Reads the X property named by `PropName` (a string) and displays its - value. The [xmonadpropwrite script] in xmobar's distribution can be - used to set the given property from the output of any other program - or script. + value. The [samples/xmonadpropwrite.hs script] in xmobar's + distribution can be used to set the given property from the output + of any other program or script. + +[samples/xmonadpropwrite.hs script]: https://github.com/jaor/xmobar/raw/master/samples/xmonadpropwrite.hs ## Monitor Plugins Commands Arguments diff --git a/samples/xmonadpropwrite.hs b/samples/xmonadpropwrite.hs new file mode 100644 index 0000000..f3f4a5d --- /dev/null +++ b/samples/xmonadpropwrite.hs @@ -0,0 +1,41 @@ +-- Copyright Spencer Janssen +-- Tomas Janousek +-- 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 diff --git a/scripts/xmonadpropwrite.hs b/scripts/xmonadpropwrite.hs deleted file mode 100644 index f3f4a5d..0000000 --- a/scripts/xmonadpropwrite.hs +++ /dev/null @@ -1,41 +0,0 @@ --- Copyright Spencer Janssen --- Tomas Janousek --- 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 diff --git a/xmobar.cabal b/xmobar.cabal index 343570d..b87d740 100644 --- a/xmobar.cabal +++ b/xmobar.cabal @@ -16,8 +16,8 @@ maintainer: Jose A. Ortega Ruiz cabal-version: >= 1.6 build-type: Simple -data-files: samples/xmobar.config extra-source-files: README, NEWS, + samples/xmobar.config, samples/xmonadpropwrite.hs samples/Plugins/helloworld.config, samples/Plugins/HelloWorld.hs -- cgit v1.2.3