Search code examples
haskellxmonad

Haskell XMonad configuration using readProcess


I'm trying to configure XMonad without actually understand the Haskell syntax.

I run a gnome session with xmonad on top. I want to press mod-p to toggle the gnome-panel:

  • if the gnome panel is not running I want to launch it.
  • if the gnome panel is already running I want to kill it

I thought that this would do it:

startgpanel :: X ()
startgpanel = do
  gp <- readProcess "pidof" ["gnome-panel"] ""
     if (length gp)
     then spawn "killall gnome-panel"
     else spawn "gnome-panel"

  ...
 ((myModMask, xK_g), startgpanel)
  ...

But I get an error:

xmonad.hs:169:12:
    Couldn't match expected type âX (t0 a0)â
                with actual type âIO Stringâ
    In a stmt of a 'do' block:
      gp <- readProcess "pidof" ["gnome-panel"] ""
    In the expression:
      do { gp <- readProcess "pidof" ["gnome-panel"] "";
           if (length gp) then
               spawn "killall gnome-panel"
           else
               spawn "gnome-panel" }

I dont really understand the Monad concept, I just want to do some IO, but it seems very complex...


Solution

  • As others have mentioned, you need to use liftIO.

    Also consult the discussion of this SO question:

    How do I use the output of readProcess in an xmonad keybinding?

    Instead of readProcess you might need to use readProcessWithInput.