用于在XMobar(XMonad)中指示布局的图标

时间:2014-06-18 17:21:05

标签: xmonad xmobar

我知道XMobar支持位图图标,我可以配置它们。但是,我还想使用图标来指示当前的XMonad布局,但XMobar会从XMonad在stdin上获取它。我无法找到一种方法来传递位图图标而不是常规符号。

那么如何传递图标而不是符号来表示XMobar中的XMonad布局?

我当前配置相对于布局的部分:

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 个答案:

答案 0 :(得分:2)

只需将其添加到xmonad.hs

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

答案 1 :(得分:2)

作为替代建议,您可以更改XMonad显示布局标题的方式。首先,改变行

      , ppLayout = xmobarColor solarizedCyan ""

阅读

      , ppLayout = xmobarColor solarizedCyan "" . myLayoutPrinter

然后,在文件中的某处添加以下功能:

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

显然,您需要自定义您使用的布局名称以及图标名称。

理论上,你甚至可以更进一步,如果你想变得非常华丽,并给每个布局自己的颜色。您实际上将ppLayout行简化为

      , ppLayout = myLayoutPrinter

将自定义颜色添加到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