Skip to content

Conversation

@kabhijeet
Copy link

Screenshot 2025-08-19 at 12 39 42 PM

Summary

This PR brings Hyprland-style window icon “rewrite” functionality to the niri/workspaces module. It adds a {windows} format token and opt‑in configuration keys to map window metadata (e.g., app_id and title) to icons/text via regex rules, then renders them per workspace with a configurable separator.

The feature is fully backward compatible: if you don’t configure the new keys, the module behaves as before.

Motivation

Waybar’s Hyprland module supports window icon rewrite rules that many users rely on for consistent workspace indicators. This PR provides feature parity for niri/workspaces, enabling unified configs across compositors.

Changes

  • Code:
    • include/modules/niri/workspaces.hpp
    • src/modules/niri/workspaces.cpp
  • Docs:
    • man/waybar-niri-workspaces.5.scd (documents {windows}, window-rewrite, window-rewrite-default, format-window-separator)
  • Example:
    • resources/config.jsonc (shows how to configure rewrite rules)

New configuration

  • format: now supports {windows} to render the per‑workspace window representations.
  • window-rewrite (object): ordered regex map; keys are patterns applied to app_id and title, values are the replacement strings (usually glyphs or short names).
    • Supported match sources: app_id<regex>, title<regex>
  • window-rewrite-default (string): fallback text/icon when no rule matches (default: ?).
  • format-window-separator (string): string inserted between window representations (default: single space).

Example (JSONC)

"niri/workspaces": {
  // Show workspace name/index and window icons
  "format": "{name}: {windows}",
  // Map app_id/title regexes to icons
  "window-rewrite": {
    "app_id<^firefox$>": "",
    "app_id<^org\\.gnome\\.Nautilus$>": "",
    "app_id<^foot$>": "",
    "title<YouTube|Twitch>": ""
  },
  // Fallback when nothing matches
  "window-rewrite-default": "",
  // Join multiple window icons with this separator
  "format-window-separator": " "
}

Note: Icon glyphs require a compatible font (e.g., Nerd Fonts).

Behavior

  • Collects windows for each workspace (using ws["windows"] when present; otherwise filters from the global windows list by workspace association).
  • For each window, tries window-rewrite rules (regex against app_id and title) and uses the first match.
  • Uses window-rewrite-default when no rule matches.
  • Joins per‑workspace representations with format-window-separator and injects into {windows}.

Backward compatibility

  • No breaking changes. If the new keys are not configured, the module’s output is unchanged.
  • All additions are opt‑in.

Documentation

  • The niri/workspaces man page has been updated to document:
    • {windows} token semantics
    • window-rewrite, window-rewrite-default, and format-window-separator
    • Matching sources (app_id<regex> and title<regex>) and precedence

Test plan

  • Run Waybar with Niri and this module enabled.
  • Open windows across multiple workspaces:
    • Apps: Firefox, Nautilus, Foot, and a window with a “YouTube” title.
  • Configure the example window-rewrite rules above.
  • Verify:
    • Icons appear per workspace and update on window open/close/move.
    • Non‑matching windows render as the configured default ( or ?).
    • The separator is respected.
    • Empty workspaces remain unaffected.

Notes for reviewers

  • The implementation mirrors Hyprland’s approach to minimize surprise and ease maintenance.
  • Logging is kept at debug/trace for diagnostics without impacting normal usage.
  • If desired in follow‑ups, shared utilities for “window rewrite” logic could be factored to reduce duplication between compositors.

Checklist

  • Feature is opt‑in; default behavior unchanged.
  • Man page and example config updated.
  • Regex‑based mapping and fallback implemented.
  • Handles both direct ws["windows"] and a global windows fallback.

tested locally with this example - Screenshot 2025-08-19 at 12 39 42 PM

Abhijeet and others added 8 commits April 29, 2025 09:51
Implement window-rewrite functionality for Niri workspaces, allowing
custom icons for windows similar to Hyprland. This includes new
configuration options for format, window separator, and default
icon, enhancing user experience by providing visual cues for
workspace windows. Debug logging added for better traceability
during development.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant