Icons for indicating layouts in XMobar (XMonad)

4.2k Views Asked by At

I know XMobar supports bitmap icons and I was able to configure those. However I also want to use icons for indicating current XMonad layout, but XMobar gets it on stdin from XMonad. And I couldn't figure out a way to pass bitmap icons instead of regular symbols.

So how one would pass icons instead of symbols for indicating XMonad layout in XMobar?

My current part of config relative to layouts:

defaultLayouts = smartBorders(avoidStruts(
  renamed [Replace "R"] (ResizableTall 1 (3/100) (1/2) [])
  ||| renamed [Replace "R!"] (Mirror (ResizableTall 1 (3/100) (1/2) []))
  ||| renamed [Replace "F"] (noBorders Full)
  ||| renamed [Replace "#"] (Grid)
  ||| renamed [Replace "3C"] (ThreeColMid 1 (3/100) (3/4))
  ||| renamed [Replace "O"] (Circle)))

chatLayout = renamed [Replace "Chat"] 
  $ avoidStruts $ withIM (0.2) isPidgin 
  $ reflectHoriz $ withIM (0.2) isSkype (Grid) 
  where 
    isSkype = (Title "zoresvit - Skype™")
    isPidgin = (Title "Buddy List")

fullLayout = renamed [Replace "F"] $ avoidStruts $ noBorders $ (Full)
myLayouts = onWorkspace "η" chatLayout $ defaultLayouts

main = do
  xmproc <- spawnPipe "xmobar ~/.xmobarrc"
  xmonad $ withUrgencyHook NoUrgencyHook $ defaultConfig {
        borderWidth = myBorderWidth
      , focusedBorderColor = myFocusedBorderColor
      , handleEventHook = fullscreenEventHook
      , layoutHook = myLayouts
      , manageHook = manageHook defaultConfig
          <+> composeAll myManagementHooks
          <+> manageDocks
      , modMask = myModMask
      , normalBorderColor = myNormalBorderColor
      , startupHook = do
          spawn "~/.xmonad/startup_hook.sh"
      , terminal = myTerminal
      , workspaces = myWorkspaces
      , logHook = dynamicLogWithPP $ xmobarPP {
            ppOutput = hPutStrLn xmproc
          , ppCurrent = xmobarColor solarizedGreen "" . wrap myCurrentWSLeft myCurrentWSRight
          , ppHidden = xmobarColor solarizedBase0 ""
          , ppHiddenNoWindows = xmobarColor solarizedBase02 ""
          , ppLayout = xmobarColor solarizedCyan ""
          , ppTitle = xmobarColor solarizedBase1 "" . shorten myTitleLength
          , ppUrgent = xmobarColor solarizedRed "" . wrap myUrgentWSLeft myUrgentWSRight
          , ppVisible = xmobarColor solarizedBase01 "" . wrap myVisibleWSLeft myVisibleWSRight
          }
      } `additionalKeys` myKeyBindings
2

There are 2 best solutions below

0
On BEST ANSWER

Just add this to your xmonad.hs:

import XMonad.Layout.Named
myLayout = named "<icon=/home/foo/bar/icon.xpm/>" $ ResizableTall 1 (3/100) (1/2) []
0
On

As an alternate suggestion, you can change how XMonad displays the Layout titles. First, change the line

      , ppLayout = xmobarColor solarizedCyan ""

to read

      , ppLayout = xmobarColor solarizedCyan "" . myLayoutPrinter

Then, add the following function somewhere in your file:

myLayoutPrinter :: String -> String
myLayoutPrinter "Full" = "<icon=layout_full.xbm/>"
myLayoutPrinter "Tall" = "<icon=layout_tall.xbm/>"
myLayoutPrinter "Mirror Tall" = "<icon=layout_mirror_tall.xbm/>"
myLayoutPrinter x = x

Obviously, you'll need to customize the names of the layouts that you use, as well as the icon names.

In theory, you could even take it a step further, if you wanted to get really gaudy and give each layout its own colour. You'd actually simplify the ppLayout line down to

      , ppLayout = myLayoutPrinter

The added the custom colours into myLayoutPrinter

myLayoutPrinter :: String -> String
myLayoutPrinter "Full" = xmobarColor "red" "" "<icon=layout_full.xbm/>"
myLayoutPrinter "Tall" = xmobarColor "green" "" "<icon=layout_tall.xbm/>"
myLayoutPrinter "Mirror Tall" = xmobarColor "blue" "" "<icon=layout_mirror_tall.xbm/>"
myLayoutPrinter x = xmobarColor "white" "" x