#!/bin/bash

# omarchy:summary=Returns true if a browser has windows open, web apps included.

# Every window a browser draws belongs to one of its processes, the hidden
# prewarmed one included. When the windows can't be listed, assume some are open.
mapfile -t pids < <(pgrep -u "$USER" -x 'chrome|chromium|brave|msedge|firefox')
((${#pids[@]})) || exit 1

clients=$(hyprctl clients -j 2>/dev/null)
[[ $(jq --argjson pids "[$(IFS=,; echo "${pids[*]}")]" 'any(.[]; .pid as $pid | $pids | index($pid))' <<<"$clients" 2>/dev/null) != "false" ]]
