Subject: bug#63555: closed (Re: bug#63555: emacs 29 complains that it can't connect to the display)

From: Robert Pluim <[email-masked]>
Date: Mon, 22 May 2023 09:29:10 +0200

>>>>> On Sat, 20 May 2023 13:35:56 -0400, Phillip Susi <[email-masked]> said:

    Phillip> Eli Zaretskii <[email-masked]> writes:

    >> > Can we invoke those same functions earlier during startup to realize
    >> > this fact where we still can start as -nw?
    >> 
    >> Unfortunately not.  At least, not enough to make a change suitable for
    >> the release branch.

    Phillip> Why not?  How hard can it be to set -nw if neither DISPLAY nor
    Phillip> WAYLAND_DISPLAY is set, as emacs always has, prior to
    Phillip> window-system-initialization?

Not too hard. Very much for master, though (and Iʼd need to check if
gtk_init_check has any GTK version dependencies).

diff --git a/src/dispnew.c b/src/dispnew.c
index a928a5d1b14..9a23fb5a182 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -6518,7 +6518,28 @@ init_display_interactive (void)
      try to use X, and if that fails output a line to stderr
      reporting that -nw will be simulated.  */
 
-#ifdef HAVE_X_WINDOWS
+#ifdef HAVE_PGTK
+  if (! inhibit_window_system)
+    {
+     if (! gtk_init_check (0, 0))
+	{
+	  fprintf (stderr, "PGTK display unavailable, simulating -nw\nCheck your $DISPLAY, $WAYLAND_DISPLAY, or $BROADWAY_DISPLAY\n");
+	  inhibit_window_system = 1;
+	}
+    }
+
+  if (!inhibit_window_system)
+    {
+      Vinitial_window_system = Qpgtk;
+#ifdef USE_NCURSES
+      /* In some versions of ncurses,
+	 tputs crashes if we have not called tgetent.
+	 So call tgetent.  */
+      { char b[2044]; tgetent (b, "xterm");}
+#endif
+      return;
+    }
+#elif defined (HAVE_X_WINDOWS)
   if (! inhibit_window_system && ! display_arg)
     {
       char *display;

Robert
--