aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Vogt <vogt.adam@gmail.com>2009-06-27 22:27:55 +0200
committerAdam Vogt <vogt.adam@gmail.com>2009-06-27 22:27:55 +0200
commit0d7e442682aba438c680000ed3df16481a9cf7ba (patch)
treef56576c21fecd9c2e4e33ef683823b3e8ad3ef6d
parentc5490dd212ab4d1cce6cd9a095560f30eb4cf6d3 (diff)
downloadXMonadContrib-0d7e442682aba438c680000ed3df16481a9cf7ba.tar.gz
XMonadContrib-0d7e442682aba438c680000ed3df16481a9cf7ba.tar.xz
XMonadContrib-0d7e442682aba438c680000ed3df16481a9cf7ba.zip
Add A.RandomBackground, actions to start terminals with a random -bg option
Ignore-this: a90c98bb14a2f917d8552cd2563aeb49 darcs-hash:20090627202755-1499c-e3a7fb184f64ff100151437755d545ee67f47c7e.gz
-rw-r--r--XMonad/Actions/RandomBackground.hs39
-rw-r--r--xmonad-contrib.cabal1
2 files changed, 40 insertions, 0 deletions
diff --git a/XMonad/Actions/RandomBackground.hs b/XMonad/Actions/RandomBackground.hs
new file mode 100644
index 0000000..71a5744
--- /dev/null
+++ b/XMonad/Actions/RandomBackground.hs
@@ -0,0 +1,39 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module : XMonad.Actions.RandomBackground
+-- Copyright : (c) 2009 Anze Slosar
+-- translation to Haskell by Adam Vogt
+-- License : BSD3-style (see LICENSE)
+--
+-- Maintainer : <vogt.adam@gmail.com>
+-- Stability : unstable
+-- Portability : unportable
+--
+-- An action to start terminals with a random background color
+--
+-----------------------------------------------------------------------------
+
+module XMonad.Actions.RandomBackground (randomBg,randomBg') where
+
+import XMonad(X, XConf(config), XConfig(terminal), io, spawn,
+ MonadIO, asks)
+import System.Random(Random(randomRIO))
+import Control.Monad(replicateM)
+import Numeric(showHex)
+
+-- | randomHex produces hex values in the form @xxyyzz@, with each of @xx@,
+-- @yy@, @zz@ within the range specified. The first parameter determines the
+-- the number of such groups.
+randomHex :: Int -> (Int, Int) -> IO String
+randomHex n = fmap disp . replicateM n . randomRIO
+ where ensure x = reverse . take x . (++repeat '0') . reverse
+ disp = concatMap $ ensure 2 . ($ "") . showHex
+
+-- | randomBg' appends the random hex @ -bg '#xxyyzz'@ to the supplied string
+randomBg' :: (MonadIO m) => (Int, Int) -> String -> m String
+randomBg' x t = do
+ num <- io $ randomHex 3 x
+ return $ concat [t," -bg '#",num,"'"]
+
+randomBg :: (Int,Int) -> X ()
+randomBg x = spawn =<< randomBg' x =<< asks (terminal . config)
diff --git a/xmonad-contrib.cabal b/xmonad-contrib.cabal
index 9faa4d7..158bf56 100644
--- a/xmonad-contrib.cabal
+++ b/xmonad-contrib.cabal
@@ -89,6 +89,7 @@ library
XMonad.Actions.Plane
XMonad.Actions.Promote
XMonad.Actions.RotSlaves
+ XMonad.Actions.RandomBackground
XMonad.Actions.Search
XMonad.Actions.SimpleDate
XMonad.Actions.SinkAll