Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

icon

A square icon from the desktop icon theme, or from a file path. Reach for it for app icons, status glyphs and tray items. Symbolic (SVG) icons take a tint. For photos and artwork at their own aspect ratio, use an image.

The focused window’s icon and title. mantle.applications maps a window’s app_id to its desktop entry, whose icon is a theme name:

local focused_icon = computed({ mantle.applications, mantle.workspaces }, function(apps, workspaces)
    local client = workspaces and workspaces.active_client
    if apps == nil or client == nil then return "" end
    local index = apps.by_app_id[client.class] or apps.by_app_id[string.lower(client.class)]
    return index and apps.entries[index].icon or ""
end)

local app_badge = row {
    spacing = 8, padding = { left = 8, right = 12, top = 6, bottom = 6 }, radius = 8, background = "#313244",
    children = {
        icon { name = focused_icon, size = 20, align_v = "Center" },
        text { content = mantle.workspaces:map(function(w)
            return w and w.active_client and w.active_client.title or ""
        end), max_width = 200, elide = "End", align_v = "Center", foreground = "#CDD6F4" },
    },
}

return app_badge

Properties

icon takes the common properties, plus:

PropertyTypeDefaultBehaviour
namestring|Bound""An icon theme name ("firefox", "audio-volume-high-symbolic"), looked up at the drawn size, or an absolute image path, used as is. "" or a name the theme lacks draws nothing
sizenumber|Bound12The box is size × size px; not range-checked
foregroundColor|BoundThe file’s own coloursColour for the SVG’s currentColor (CSS color), which tints symbolic icons. Full-colour icons ignore it

An explicit width or height overrides that axis of the square; the icon draws at the shorter side, centred.

The theme is gtk-icon-theme-name from $XDG_CONFIG_HOME/gtk-4.0/settings.ini, else gtk-3.0/settings.ini, else hicolor. It is read once per Renderer process, so a theme change shows after a shell restart, not a reload. Files load as PNG, JPEG, WebP, GIF, SVG or SVGZ.

How do I…

TaskAnswer
Show an app’s iconThe example above
Tint a symbolic iconforeground = "#CDD6F4" on a -symbolic name
Show a tray item’s iconname = item.icon_name or item.icon_path: both spellings work (tray)
Show a notification’s app iconname = notification.app_icon (notifications)
Make an icon buttonPut the icon in a button
Put a badge on an iconLayer them in a rect

Gotchas

TrapFix
An icon draws nothingThe theme and its fallbacks lack the name; mantle log warns once with the theme. Check /usr/share/icons/<theme>, or pass an absolute path
foreground does not change a colour iconOnly SVGs that use currentColor (symbolic icons) take it
The wrong theme’s icons appearThe theme comes from GTK settings, read at Renderer start. Set gtk-icon-theme-name and restart the shell
An icon is smaller than its boxIt draws at the shorter side of width/height. Keep them equal, or use size alone
An icon given as a relative path draws nothingA relative name is a theme name. Use mantle.config_dir .. "/icons/x.svg"

See also: image, capabilities.

Source: vocabulary, content parsers, theme lookup, decode, icon draw.