xmonad-contrib-0.18.0: Community-maintained extensions for xmonad

Copyright | (c) Will Pierlot <willp@outlook.com.au>
License | BSD3-style (see LICENSE)
Maintainer | Will Pierlot <willp@outlook.com.au>
Stability | unstable
Portability | unportable
Safe Haskell | None
Language | Haskell2010

XMonad.Hooks.DynamicIcons

Contents

- Usage
- Creating Dynamic Icons
- Customization

Description

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

Synopsis

- iconsPP :: Query [String] -> PP -> X PP
- dynamicLogIconsWithPP :: Query [String] -> PP -> X ()
- appIcon :: String -> Query [String]
- dynamicIconsPP :: IconConfig -> PP -> X PP
- getWorkspaceIcons :: IconConfig -> X (String -> WindowSpace -> String)
- data IconConfig = IconConfig {
  - iconConfigIcons :: Query [String]
  - iconConfigFmt :: WorkspaceId -> [String] -> String
  - iconConfigFilter :: Maybe (Stack Window) -> X [Window]
  }
- iconsFmtAppend :: ([String] -> String) -> WorkspaceId -> [String] -> String
- iconsFmtReplace :: ([String] -> String) -> WorkspaceId -> [String] -> String
- wrapUnwords :: String -> String -> [String] -> String
- iconsGetAll :: Maybe (Stack Window) -> X [Window]
- iconsGetFocus :: Maybe (Stack Window) -> X [Window]

# Usage

Dynamically augment Workspace's `WorkspaceId` as shown on a status bar based on the `Window`s 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 `String`s (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 #

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 #

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] #

Shortcut for configuring single icons.

# Customization

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

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) #

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

data IconConfig #

Datatype for expanded `Icon` configurations

Constructors

IconConfig |
Fields iconConfigIcons :: Query [String] What icons to use for each window. iconConfigFmt :: WorkspaceId -> [String] -> String How to format the result, see `iconsFmtReplace`, `iconsFmtAppend`. iconConfigFilter :: Maybe (Stack Window) -> X [Window] Which windows (icons) to show.

#### Instances

Instances details

Default IconConfig # |
Instance details Defined in XMonad.Hooks.DynamicIcons Methods def :: IconConfig #

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

`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 #

`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 #

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] #

`iconConfigFilter` that shows all windows of every workspace.

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

`iconConfigFilter` that shows only the focused window for each workspace.