XMonad.Util.SpawnNamedPipe

xmonad-contrib-0.13: Third party extensions for xmonad

Copyright | (c) Christian Wills 2014
License | BSD3-style (see LICENSE)
Maintainer | cwills.dev@gmail.com
Stability | unstable
Portability | not portable
Safe Haskell | None
Language | Haskell98

XMonad.Util.SpawnNamedPipe

Contents

- Usage

Description

A module for spawning a pipe whose Handle lives in the Xmonad state.

Synopsis

- spawnNamedPipe :: String -> String -> X ()
- getNamedPipe :: String -> X (Maybe Handle)

# Usage

This module makes it possible to spawn a pipe to Dzen2 in the startupHook and write to it from inside the logHook without the need for global variables.

    import XMonad.Util.SpawnNamedPipe
    import Data.Maybe

    -- StartupHook
    startupHook' = spawnNamedPipe "dzen2" "dzenPipe"

    -- LogHook
    logHook' = do
        mh <- getNamedPipeHandle "dzenPipe"
            dynamicLogWithPP $ defaultPP {
                ppOutput = maybe (\s -> return ()) (hPutStrLn) mh}

    -- Main
    main = xmonad $ defaultConfig {
                         startupHook = startupHook'
                       , logHook = logHook'}

spawnNamedPipe :: String -> String -> X () #

When `spawnNamedPipe` is executed with a command String and a name String respectively. The command string is spawned with `spawnPipe` (as long as the name chosen hasn't been used already) and the Handle returned is saved in Xmonad's state associated with the name String.

getNamedPipe :: String -> X (Maybe Handle) #

Attempts to retrieve a Handle to a pipe previously stored in Xmonad's state associated with the given string via a call to `spawnNamedPipe`. If the given string doesn't exist in the map stored in Xmonad's state Nothing is returned.