I'd suggest moving reading the DISPLAY shell variable into the program initialisation
I think this may cause crashes after changing screen configuration (for example, when user connect additional monitor).
I wouldn't have thought so, since generally speaking identifiers will be claimed by X11 servers sequentially rather than being shuffled. And I'd have expected that to have applied irrespective of whether multiple monitors tiled onto the same desktop environment or were allocated different desktop environments (i.e. distinct window managers).
Also I wouldn't have expected X11 applications to have tolerated having to shut their existing socket connection (TCP, unix-domain or whatever... basically, what you weren't closing earlier even if it's not readily visible) in response to that sort of external event.
I was "playing" with multiple devices a few weeks ago, but I don't think that involved any hotplugging (multiple outputs on the same physical card, and the low-level X11 driver wanted to know which ones had something attached when it initialised).
However I'd be interested to be proven wrong :-)
MarkMLl