3

I am configuring my xmonad file to send the Stdout to a SpawnPipe per the documentation at https://hackage.haskell.org/package/xmonad-contrib-0.16/docs/XMonad-Hooks-DynamicLog.html#v:ppOutput

Here is the code that I have so far... I am sure I am just missing a way to pass h along to the myLogHook function! - Thanks for your help.

myLogHook = dynamicLogWithPP $ def { ppOutput = hPutStrLn h }

main = do
h <- spawnPipe "xmobar ~/.xmobar/.xmobarrc"
xmonad $ docks defaults

defaults = def {
  -- simple stuff
    terminal           = myTerminal,
    focusFollowsMouse  = myFocusFollowsMouse,
    clickJustFocuses   = myClickJustFocuses,
    borderWidth        = myBorderWidth,
    modMask            = myModMask,
    workspaces         = myWorkspaces,
    normalBorderColor  = myNormalBorderColor,
    focusedBorderColor = myFocusedBorderColor,

  -- key bindings
    keys               = myKeys,
    mouseBindings      = myMouseBindings,

  -- hooks, layouts
    layoutHook         = myLayout,
    manageHook         = myManageHook,
    handleEventHook    = myEventHook,
    logHook            = myLogHook,
    startupHook        = myStartupHook
}
Nick McLean
  • 601
  • 1
  • 9
  • 23

1 Answers1

3

First, change myLogHook to take the handle as a parameter:

import System.IO
import XMonad

myLogHook :: Handle -> X ()
myLogHook h = dynamicLogWithPP $ def { ppOutput = hPutStrLn h }

Then, pass it to the hook and get rid of it from the defaults:

main = do
    h <- spawnPipe "xmobar ~/.xmobar/.xmobarrc"
    xmonad $ docks $ defaults {
        logHook = myLogHook h
    }

defaults = def {
    -- some stuff
    logHook = return ()
    -- more stuff
}

The {} after the defaults basically overwrites properties.

Aplet123
  • 33,825
  • 1
  • 29
  • 55
  • Things are starting to make sense a bit more - Thanks so much for your time! Now, where I pass the hook, h is not in scope here. "logHook = myLogHook h" – Nick McLean Nov 20 '20 at 17:50
  • I've misread your code and I've fixed my answer so it should hopefully work now. – Aplet123 Nov 20 '20 at 17:53
  • Awesome! She's workin! Thanks! Defiantly new to Haskell, this helps a lot, and I'm digging this language. – Nick McLean Nov 20 '20 at 17:56
  • Does the handle come from the System.IO? – Nick McLean Nov 20 '20 at 17:59
  • 1
    You can search `Handle` on [Hoogle](https://hoogle.haskell.org/?hoogle=Handle), and see that the first result that comes up (`data Handle`) has `base System.IO` underneath it, signifying that it's from the `System.IO` module in the `base` package. – Aplet123 Nov 20 '20 at 18:00