summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSpencer Janssen <sjanssen@cse.unl.edu>2009-11-07 02:01:04 +0100
committerSpencer Janssen <sjanssen@cse.unl.edu>2009-11-07 02:01:04 +0100
commit364a0ceb37746c67d10292e3b0b5c21b4b9a411f (patch)
treea184b2aa0c24e6a7a535d146a978989208145305
parent7af999b8b3fc3142e2c4bb32542844175f60f3b9 (diff)
downloadxmobar-364a0ceb37746c67d10292e3b0b5c21b4b9a411f.tar.gz
xmobar-364a0ceb37746c67d10292e3b0b5c21b4b9a411f.tar.bz2
Add XMonadLog.
Ignore-this: 99ce96d00494d6bd681ef524bb93f8c7 Support for writing WM status to a root window property was just added to xmonad, this is the accompanying xmobar plugin. The idea is to use XMonadLog rather than StdinReader with xmonad, this should hopefully be more robust than communicating over a pipe. darcs-hash:20091107010104-a5988-5d111c1cba277269dc2dda2a5f4aaae384d4be3a.gz
-rw-r--r--Config.hs3
-rw-r--r--Plugins/XMonadLog.hs66
2 files changed, 68 insertions, 1 deletions
diff --git a/Config.hs b/Config.hs
index 3e76c8b..ef487ee 100644
--- a/Config.hs
+++ b/Config.hs
@@ -30,6 +30,7 @@ import Plugins.Date
import Plugins.PipeReader
import Plugins.CommandReader
import Plugins.StdinReader
+import Plugins.XMonadLog
#ifdef INOTIFY
import Plugins.Mail
@@ -90,7 +91,7 @@ infixr :*:
-- the 'Runnable.Runnable' Read instance. To install a plugin just add
-- the plugin's type to the list of types (separated by ':*:') appearing in
-- this function's type signature.
-runnableTypes :: Command :*: Monitors :*: Date :*: PipeReader :*: CommandReader :*: StdinReader :*:
+runnableTypes :: Command :*: Monitors :*: Date :*: PipeReader :*: CommandReader :*: StdinReader :*: XMonadLog :*:
#ifdef INOTIFY
Mail :*:
#endif
diff --git a/Plugins/XMonadLog.hs b/Plugins/XMonadLog.hs
new file mode 100644
index 0000000..34fae31
--- /dev/null
+++ b/Plugins/XMonadLog.hs
@@ -0,0 +1,66 @@
+{-# LANGUAGE CPP #-}
+
+-----------------------------------------------------------------------------
+-- |
+-- Module : Plugins.StdinReader
+-- Copyright : (c) Spencer Janssen
+-- License : BSD-style (see LICENSE)
+--
+-- Maintainer : Spencer Janssen <spencerjanssen@gmail.com>
+-- Stability : unstable
+-- Portability : unportable
+--
+-- A plugin to display information from _XMONAD_LOG, specified at
+-- http://code.haskell.org/XMonadContrib/XMonad/Hooks/DynamicLog.hs
+--
+-----------------------------------------------------------------------------
+
+module Plugins.XMonadLog (XMonadLog(..)) where
+
+import Control.Monad
+import Graphics.X11
+import Graphics.X11.Xlib.Extras
+import Plugins
+#ifdef UTF8
+#undef UTF8
+import Codec.Binary.UTF8.String as UTF8
+#define UTF8
+#endif
+import Foreign.C (CChar)
+import XUtil (nextEvent')
+
+
+data XMonadLog = XMonadLog
+ deriving (Read, Show)
+
+instance Exec XMonadLog where
+ start XMonadLog cb = do
+ d <- openDisplay ""
+ xlog <- internAtom d "_XMONAD_LOG" False
+
+ root <- rootWindow d (defaultScreen d)
+ selectInput d root propertyChangeMask
+
+ let update = do
+ mwp <- getWindowProperty8 d xlog root
+ maybe (return ()) (cb . decodeCChar) mwp
+
+ update
+
+ allocaXEvent $ \ep -> forever $ do
+ nextEvent' d ep
+ e <- getEvent ep
+ case e of
+ PropertyEvent { ev_atom = a } | a == xlog -> update
+ _ -> return ()
+
+ return ()
+
+decodeCChar :: [CChar] -> String
+#ifdef UTF8
+#undef UTF8
+decodeCChar = UTF8.decode . map fromIntegral
+#define UTF8
+#else
+decodeCChar = map (toEnum . fromIntegral)
+#endif