but you see, you know its a GUI window because you made the menu specifically for that window name
"menu @MyPopup {"
AFAIK, you cannot make a menu for an arbitrary custom window, so you will always know the menu you made is for a specific window. This goes back to how i said "menu $active" is meaningless, and that you should consult /help menu prefix