Subject: Re: bug#65509: [PATCH] Use correct env var when opening frames with freedesktop menu entries

From: Davide Masserut <[email-masked]>
Date: Fri, 08 Sep 2023 17:49:43 +0200

Po Lu <[email-masked]> writes:

> Eli Zaretskii <[email-masked]> writes:
>
>>> From: Davide Masserut <[email-masked]>
>>> Cc: Stefan Kangas <[email-masked]>, Eli Zaretskii <[email-masked]>,
>>>  [email-masked]
>>> Date: Wed, 06 Sep 2023 16:01:58 +0200
>>> 
>>> It turns out that Emacs 29 has new CLI option that solves exactly these problems.
>>> 
>>> The attached patch replaces the usage of --display=$DISPLAY with --reuse-frame.
>>
>> Po Lu, any objections to installing this on emacs-29?
>
> Yes.  Davide, would you please rewrite the patch so that your change is
> only applied to the PGTK port?

Done.  Po, why can't we use --reuse-frame in X builds?

>From 43085522a08b94ef594bd270d61a38d7bb26e036 Mon Sep 17 00:00:00 2001
From: Davide Masserut <[email-masked]>
Date: Thu, 24 Aug 2023 18:33:39 +0200
Subject: [PATCH] Avoid using --display to reuse frames in PGTK

Using hard-coded display values can cause PGTK graphical frames to
open using the wrong backend or not open at all.

* Makefile.in (install-etc): Use --reuse-frame instead of
--display=$DISPLAY.
---
 Makefile.in | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/Makefile.in b/Makefile.in
index fdd9353e254..c82aad1af60 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -843,6 +843,9 @@ EMACS_ICON=
 ifeq (${USE_STARTUP_NOTIFICATION},no)
 USE_STARTUP_NOTIFICATION_SED_CMD=-e "/^StartupNotify=true$$/d"
 endif
+ifeq ($(HAVE_PGTK),yes)
+USE_WAYLAND_DISPLAY_SED_CMD=-e "s/display=[^ ]*/reuse-frame/"
+endif
 install-etc:
 	umask 022; ${MKDIR_P} "$(DESTDIR)${desktopdir}"
 	tmp=etc/emacs.tmpdesktop; rm -f $${tmp}; \
@@ -857,6 +860,7 @@ install-etc:
 	sed -e "/^Exec=/ s|emacsclient|${bindir}/$${client_name}|" \
 	  -e "/^Icon=emacs/ s/emacs/${EMACS_NAME}/" \
 	  $(USE_STARTUP_NOTIFICATION_SED_CMD) \
+	  $(USE_WAYLAND_DISPLAY_SED_CMD) \
 	  ${srcdir}/etc/emacsclient.desktop > $${tmp}; \
 	${INSTALL_DATA} $${tmp} "$(DESTDIR)${desktopdir}/$${client_name}.desktop"; \
 	rm -f $${tmp}
@@ -870,6 +874,7 @@ install-etc:
 	client_name=`echo emacsclient | sed '$(TRANSFORM)'`${EXEEXT}; \
 	sed -e "/^Exec=/ s|emacsclient|${bindir}/$${client_name}|" \
 	  -e "/^Icon=emacs/ s/emacs/${EMACS_NAME}/" \
+	  $(USE_WAYLAND_DISPLAY_SED_CMD) \
 	  ${srcdir}/etc/emacsclient-mail.desktop > $${tmp}; \
 	${INSTALL_DATA} $${tmp} "$(DESTDIR)${desktopdir}/$${client_name}-mail.desktop"; \
 	rm -f $${tmp}
-- 
2.42.0