@Atrate I have asked for a possibility to listen to focus change events in xfce and the first link in this answer Any way to listen to events? / General discussion / Xfce Forums points to this:
xprop -spy -root -notype _NET_ACTIVE_WINDOW
It basically prints the property change which then in turns can be read, parsed and transformed to the current domain via
xprop -id "$WINDOW" -notype _QUBES_VMNAME
Maybe this is an option for you, without a loop and polling ![]()