Skip to main content
  1. Series/
  2. Niri Window Manager/

Workspace window count

niri - This article is part of a series.
Part 8: This Article

When integrated with Waybar, this script returns the currently selected Window followed by the total number of Windows on the current workspace.

As an example, the returned text below shows that the currently selected window is the first window on a workspace with two windows.
{“text”:“ 1:2 “,“tooltip”:“Current Window”,“class”:“unmuted”}

#!/bin/bash

ME="$(niri msg -j workspaces | jq ".[] | select(.is_focused == true ) | .id")"
NUM="$(niri msg -j windows | jq "[.[] | select(.workspace_id == $ME)] | length")"

LAYOUT="$(niri msg -j windows | jq ".[] | select(.is_focused == true ) | .layout")"
POS_IN_LAYOUT=$(echo $LAYOUT | jq ". | .pos_in_scrolling_layout")
FINAL=$(echo $POS_IN_LAYOUT |  sed -E 's/^\[ (.+?),(.+)/\1/')

if [[ $NUM -gt 0 && $FINAL -gt 0 ]] then
  TEXT=" "$FINAL":"$NUM
fi

echo '{"text":"'$TEXT' ","tooltip":"Current Window","class":"unmuted"}'
niri - This article is part of a series.
Part 8: This Article