Search code examples
haskellarchlinuxxmonadxmobarxmonad-contrib

Migrating XMobar to the new 0.17 standard


Just to make it clear, my XMobar uses UnsafeStdinReader and SpawnPipe to send information about workspaces right now. Here are the relevant portions of the configuration:

main = do
    xmprocleft <- spawnPipe "xmobar -x 0 $HOME/.config/xmobar/xmobarrc0.hs"
    xmonad $ docks $ ewmhFullscreen $ ewmh $ def
        { manageHook         = myManageHook <+> manageDocks
        , modMask            = myModMask
        , terminal           = myTerminal
        , startupHook        = myStartupHook
        , layoutHook         = showWName' myShowWNameTheme $ myLayoutHook
        , workspaces         = myWorkspaces
        , borderWidth        = myBorderWidth
        , normalBorderColor  = myNormColor
        , focusedBorderColor = myFocusColor
        , logHook = dynamicLogWithPP $ xmobarPP
              { ppOutput = \x -> hPutStrLn xmprocleft x                          
              , ppCurrent = xmobarColor "#f8f16a" "" . wrap "<fn=1>" "</fn>"         -- Workspace that I am viewing now
              , ppVisible = xmobarColor "#98be65" "" . wrap "<fn=1>" "</fn>" . clickable              -- Workspace that is open on any monitor other than this one
              , ppHidden = xmobarColor "#2ac3de" "" . wrap "<fn=1>" "</fn>" . clickable -- Hidden workspaces that have any open software in it but not open on any monitors
              , ppHiddenNoWindows = xmobarColor "#c0caf5" "" . wrap "<fn=1>" "</fn>" . clickable     -- Workspaces with no open softwares and not open on any monitors
              , ppTitle = xmobarColor "#c0caf5" "" . shorten 60               -- Title of active window
              , ppSep =  "<fc=#444b6a> | </fc>"                    -- Separator character
              , ppUrgent = xmobarColor "#EBCB8B" "" . wrap "!<fn=1>" "</fn>!"            -- Urgent workspace
              , ppExtras  = [windowCount]                                     -- # of windows current workspace
                 -- name of workspaces, current layout, current title of open software, number of open windows in current workspace
              , ppOrder  = \(ws:_:_:_) -> [ws]                               -- stopped showing the current layout, number of open programs in current workspace
              }
        } `additionalKeysP` myKeys

What I am trying to achieve

According to the XMonad Wiki, SpawnPipe is deprecated for the newer use of XMonadLog to send data to XMobar. I am trying to use Dynamic status bar using dynamicEasySBs according to XMonad.Hooks.StatusBar.PP and XMonad.Hooks.StatusBar.

I did make necessary changes on the XMobar config too. But, the configuration is a bit confusing for me. Has anyone yet made a working config using this new format?


Solution

  • While reading the new Tutorial I manage to Update my setup, this way.

    This is how you want to write your xmobarrc

     -- appearance
       font =         "xft:Fira Code:size=11:bold:antialias=true"
       , bgColor =      "#272727"
       , fgColor =      "#073642"
       , position =     Top
       , border =       BottomB
       , borderColor =  "#646464"
       , textOffset = 11
    
       -- layout
       , sepChar =  "%"   -- delineator between plugin names and straight text
       , alignSep = "}{"  -- separator between left-right alignment
       , template = " %XMonadLog% | %coretemp% | %memory% | %dynnetwork% }{%StdinReader% | %dropbox% | %RJTT% | %date% || %kbd% "
    
       -- general behavior
       , lowerOnStart =     True    -- send to bottom of window stack on start
       , hideOnStart =      False   -- start with window unmapped (hidden)
       , allDesktops =      True    -- show on all desktops
       , overrideRedirect = True    -- set the Override Redirect flag (Xlib)
       , pickBroadest =     False   -- choose widest display (multi-monitor)
       , persistent =       True    -- enable/disable hiding (True = disabled)
    
    - plugins
       --   Numbers can be automatically colored according to their value. xmobar
       --   decides color based on a three-tier/two-cutoff system, controlled by
       --   command options:
       --     --Low sets the low cutoff
       --     --High sets the high cutoff
       --
       --     --low sets the color below --Low cutoff
       --     --normal sets the color between --Low and --High cutoffs
       --     --High sets the color above --High cutoff
       --
       --   The --template option controls how the plugin is displayed. Text
       --   color can be set by enclosing in <fc></fc> tags. For more details
       --   see http://projects.haskell.org/xmobar/#system-monitor-plugins.
    
       , commands =
    
            -- weather monitor
            [ Run Weather "RJTT" [ "--template", "<skyCondition> | <fc=#4682B4><tempC></fc>°C | <fc=#4682B4><rh></fc>% | <fc=#4682B4><pressure></fc>hPa"
                                 ] 36000
    
            -- network activity monitor (dynamic interface resolution)
            , Run DynNetwork     [ "--template" , "<dev>: <tx>kB/s|<rx>kB/s"
                                 , "--Low"      , "1000"       -- units: kB/s
                                 , "--High"     , "5000"       -- units: kB/s
                                 , "-m"         , "4"
                                 , "--low"      , "darkgreen"
                                 , "--normal"   , "darkorange"
                                 , "--high"     , "darkred"
                                 ] 10
    
            -- cpu activity monitor
            , Run MultiCpu       [ "--template" , "Cpu: <total0> <total1> <total2> <total3> <total4> <total5> <total6> <total7>%"
                                 , "--Low"      , "50"         -- units: %
                                 , "--High"     , "85"         -- units: %
                                 , "-p"         , "3"
                                 , "--low"      , "darkgreen"
                                 , "--normal"   , "darkorange"
                                 , "--high"     , "darkred"
                                 ] 10
    
            -- cpu core temperature monitor
            , Run CoreTemp       [ "--template" , "Temp: <core0> <core1> <core2> <core3>°C"
                                 , "--Low"      , "70"        -- units: °C
                                 , "--High"     , "80"        -- units: °C
                                 , "--low"      , "darkgreen"
                                 , "--normal"   , "darkorange"
                                 , "--high"     , "darkred"
                                 ] 50
    
            -- memory usage monitor
            , Run Memory         [ "--template" ,"Mem: <usedratio>%"
                                 , "--Low"      , "20"        -- units: %
                                 , "--High"     , "90"        -- units: %
                                 , "--low"      , "darkgreen"
                                 , "--normal"   , "darkorange"
                                 , "--high"     , "darkred"
                                 ] 10
    
            -- battery monitor
            , Run Battery        [ "--template" , "Batt: <left>% - <timeleft>"
                                 , "--Low"      , "10"        -- units: %
                                 , "--High"     , "80"        -- units: %
                                 , "--low"      , "darkred"
                                 , "--normal"   , "darkorange"
                                 , "--high"     , "darkgreen"
    
                                 , "--" -- battery specific options
                                           -- discharging status
                                           , "-o"   , "<left>% (<timeleft>)"
                                           -- AC "on" status
                                           , "-O"   , "<fc=#dAA520>Charging</fc>"
                                           -- charged status
                                           , "-i"   , "<fc=#006000>Charged</fc>"
                                 ] 50
    
            -- time and date indicator
            --   (%F = y-m-d date, %a = day of week, %T = h:m:s time)
            , Run Date           "<fc=#ABABAB>%F (%a) %T</fc>" "date" 10
    
    
            -- Xmonad Xmobar Constructor
            ,  Run XMonadLog
    
            ]
    
    

    And this should be your xmonad.hs

    main :: IO ()
    main = xmonad
         . ewmhFullscreen
         . ewmh
         . withEasySB (statusBarProp "xmobar" (pure def)) defToggleStrutsKey
         $ myConfig
    

    According with this documentation about dinamicLog

    DynamicLog API is frozen and users are encouraged to migrate to these modern replacements.

    That is then XMonad.Hooks.StatusBar

    This module provides a composable interface for (re)starting these status bars and logging to them, either using pipes or X properties. There's also XMonad.Hooks.StatusBar.PP which provides an abstraction and some utilities for customization what is logged to a status bar. Together, these are a modern replacement for XMonad.Hooks.DynamicLog, which is now just a compatibility wrapper.