Subject: bug#67628: Emacs 29.1: (x-open-connection (getenv "DISPLAY")) gets "Display :0.0 does not exist" error

From: Eli Zaretskii <[email-masked]>
Date: Wed, 06 Dec 2023 14:38:25 +0200

> From: Po Lu <[email-masked]>
> Cc: [email-masked],  [email-masked]
> Date: Wed, 06 Dec 2023 20:21:36 +0800
> 
> Eli Zaretskii <[email-masked]> writes:
> 
> >> The display is opened successfully, but the next event to arrive
> >> activates the dynamic-setting machinery that calls get-device-terminal,
> >> which signals an error in response to there being no frames on that
> >> display at the time.
> >
> > So you are saying that this is an issue with the fine timing of when
> > the event arrives?  And if it arrived a bit later, it would have been
> > processed correctly?
> 
> No, see below.
> 
> >> The sound fix is for get-device-terminal to search for the device
> >> provided within x_display_list instead of the list of live frames.
> >
> > I'm not sure this is the correct fix.  If a frame is not yet in the
> > list of live frames exposed to Lisp, it might mean the frame is not
> > yet fully set up, and some code running off the dynamic-setting
> > machinery could similarly fail, right?
> >
> > Wouldn't it be better to delay the processing of this event until the
> > frame is fully set?
> 
> There's no frame being created halfway in this scenario.  Rather, a
> display connection is opened _without_ creating any frames, from which a
> dynamic-setting event subsequently arrives.

If the frame doesn't exist, why do we consider this anything but a
cockpit error?

Or why would the dynamic-setting machinery call get-device-terminal
for a display that has no frames?

I guess I'm still missing something, so please elaborate, and maybe
point me to the relevant code involved in this.

Thanks.