xmonad-contrib-0.18.1: Community-maintained extensions for xmonad
Copyright(c) Will Pierlot <willp@outlook.com.au>
LicenseBSD3-style (see LICENSE)
MaintainerWill Pierlot <willp@outlook.com.au>
Stabilityunstable
Portabilityunportable
Safe HaskellNone
LanguageHaskell2010

XMonad.Hooks.DynamicIcons

Description

Dynamically augment workspace names logged to a status bar based on the contents (windows) of the workspace.

Synopsis

Usage

Dynamically augment Workspace's WorkspaceId as shown on a status bar based on the Windows inside the Workspace.

Icons are specified by a Query [String], which is something like a ManageHook (and uses the same syntax) that returns a list of Strings (icons). This Query is evaluated for each window and the results are joined together. appIcon is a useful shortcut here.

For example:

myIcons :: Query [String]
myIcons = composeAll
  [ className =? "discord" --> appIcon "\xfb6e"
  , className =? "Discord" --> appIcon "\xf268"
  , className =? "Firefox" --> appIcon "\63288"
  , className =? "Spotify" <||> className =? "spotify" --> appIcon "阮"
  ]

then you can add it to your XMonad.Hooks.StatusBar config:

myBar = statusBarProp "xmobar" (iconsPP myIcons myPP)
main = xmonad . withSB myBar $ … $ def

Here is an example of this

Note: You can use any string you want here. The example shown here uses NerdFont Icons to represent open applications.

If you want to customize formatting and/or combine this with other PP extensions like XMonad.Util.ClickableWorkspaces, here's a more advanced example how to do that:

myIconConfig = def{ iconConfigIcons = myIcons, iconConfigFmt = iconsFmtAppend concat }
myBar = statusBarProp "xmobar" (clickablePP =<< dynamicIconsPP myIconConfig myPP)
main = xmonad . withSB myBar . … $ def

This can be also used with XMonad.Hooks.DynamicLog:

main = xmonad $ … $ def
  { logHook = dynamicLogIconsWithPP myIcons xmobarPP
  , … }

or with more customziation:

myIconConfig = def{ iconConfigIcons = myIcons, iconConfigFmt = iconsFmtAppend concat }
main = xmonad $ … $ def
  { logHook = xmonadPropLog =<< dynamicLogString =<< clickablePP =<<
              dynamicIconsPP myIconConfig xmobarPP
  , … }

Creating Dynamic Icons

iconsPP Source #

Arguments

:: Query [String]

The IconSet to use

-> PP

The PP to alter

-> X PP

The resulting 'X PP'

Adjusts the PP with the given IconSet

dynamicLogIconsWithPP Source #

Arguments

:: Query [String]

The IconSet to use

-> PP

The PP to alter

-> X ()

The resulting X action

Adjusts the PP and then runs dynamicLogWithPP

appIcon :: String -> Query [String] Source #

Shortcut for configuring single icons.

Customization

dynamicIconsPP :: IconConfig -> PP -> X PP Source #

Modify a pretty-printer, PP, to augment workspace names with icons based on the contents (windows) of the workspace.

getWorkspaceIcons :: IconConfig -> X (String -> WindowSpace -> String) Source #

Returns a function for ppRename that augments workspaces with icons according to the provided IconConfig.

data IconConfig Source #

Datatype for expanded Icon configurations

Constructors

IconConfig 

Fields

Instances

Instances details
Default IconConfig Source # 
Instance details

Defined in XMonad.Hooks.DynamicIcons

Methods

def :: IconConfig #

iconsFmtAppend :: ([String] -> String) -> WorkspaceId -> [String] -> String Source #

iconConfigFmt that appends icons to the workspace name.

First parameter specifies how to concatenate multiple icons. Useful values include: concat, unwords, wrapUnwords.

Examples

Expand
>>> iconsFmtAppend concat "1" []
"1"
>>> iconsFmtAppend concat "1" ["A", "B"]
"1:AB"

iconsFmtReplace :: ([String] -> String) -> WorkspaceId -> [String] -> String Source #

iconConfigFmt that replaces the workspace name with icons, if any.

First parameter specifies how to concatenate multiple icons. Useful values include: concat, unwords, wrapUnwords.

Examples

Expand
>>> iconsFmtReplace concat "1" []
"1"
>>> iconsFmtReplace concat "1" ["A", "B"]
"AB"
>>> iconsFmtReplace (wrapUnwords "{" "}") "1" ["A", "B"]
"{A B}"

wrapUnwords :: String -> String -> [String] -> String Source #

Join words with spaces, and wrap the result in delimiters unless there was exactly one element.

Examples

Expand
>>> wrapUnwords "{" "}" ["A", "B"]
"{A B}"
>>> wrapUnwords "{" "}" ["A"]
"A"
>>> wrapUnwords "{" "}" []
""

iconsGetAll :: Maybe (Stack Window) -> X [Window] Source #

iconConfigFilter that shows all windows of every workspace.

iconsGetFocus :: Maybe (Stack Window) -> X [Window] Source #

iconConfigFilter that shows only the focused window for each workspace.