This is extremely difficult and fragile, as described. Instead, consider allowing the window to always be opened, but all of its features disabled by default.
Then, set up a couple memory tags. One to hold the client ID of the client "in control", and a second to contain a datetime timeout value.
Enable the controls on the window while the particular client's ID matches and the timeout timestamp is greater than now()
.
Use a button on the window to "claim" control by writing the current client ID to the memory tag, with a timeout a short time in the future.
(The claim button would also be disabled when some other client has control.)