Fix some DISPLAY variable related bugs on PGTK

* src/callproc.c (getenv_internal, make_environment_block):
Don't set DISPLAY on non-X GDK backends.  (bug#54844)
This commit is contained in:
Po Lu 2022-04-12 13:27:56 +08:00
parent b15d9fcebb
commit e2b64f8999

View file

@ -85,6 +85,10 @@ extern char **environ;
#include "nsterm.h"
#endif
#ifdef HAVE_PGTK
#include "pgtkterm.h"
#endif
/* Pattern used by call-process-region to make temp files. */
static Lisp_Object Vtemp_file_name_pattern;
@ -1687,6 +1691,7 @@ getenv_internal (const char *var, ptrdiff_t varlen, char **value,
/* For DISPLAY try to get the values from the frame or the initial env. */
if (strcmp (var, "DISPLAY") == 0)
{
#ifndef HAVE_PGTK
Lisp_Object display
= Fframe_parameter (NILP (frame) ? selected_frame : frame, Qdisplay);
if (STRINGP (display))
@ -1695,6 +1700,7 @@ getenv_internal (const char *var, ptrdiff_t varlen, char **value,
*valuelen = SBYTES (display);
return 1;
}
#endif
/* If still not found, Look for DISPLAY in Vinitial_environment. */
if (getenv_internal_1 (var, varlen, value, valuelen,
Vinitial_environment))
@ -1812,6 +1818,18 @@ make_environment_block (Lisp_Object current_dir)
if (NILP (display))
{
Lisp_Object tmp = Fframe_parameter (selected_frame, Qdisplay);
#ifdef HAVE_PGTK
/* The only time GDK actually returns correct information is
when it's running under X Windows. DISPLAY shouldn't be
set to a Wayland display either, since that's an X specific
variable. */
if (FRAME_WINDOW_P (SELECTED_FRAME ())
&& strcmp (G_OBJECT_TYPE_NAME (FRAME_X_DISPLAY (SELECTED_FRAME ())),
"GdkX11Display"))
tmp = Qnil;
#endif
if (!STRINGP (tmp) && CONSP (Vinitial_environment))
/* If still not found, Look for DISPLAY in Vinitial_environment. */
tmp = Fgetenv_internal (build_string ("DISPLAY"),