Subject: [PATCH] Use correct env var when opening frames with freedesktop menu entries
From: Davide Masserut <[email-masked]>
To: [email-masked]
Date: Thu, 24 Aug 2023 20:32:47 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

Tags: patch

When Emacs is built with PGTK, frames opened with the 
emacsclient.desktop entry are opened as X11 windows instead of 
Wayland.

This patch adds a sed command to the Makefile that replaces the 
environment variable "$DISPLAY" with "$WAYLAND_DISPLAY" when built 
with PGTK.

In GNU Emacs 30.0.50 (build 32, x86_64-pc-linux-gnu, GTK+ Version
 3.24.38, cairo version 1.17.8) of 2023-08-24 built on T480s
Repository revision: 3907c884f03cf5f2a09696bda015b1060c7111ba
Repository branch: master
System Description: Arch Linux

Configured using:
 'configure -C --prefix /home/davide/.local --with-pgtk
 --with-native-compilation --enable-link-time-optimization
 --enable-locallisppath=/usr/share/emacs/site-lisp/
 'CFLAGS=-march=native -O2''
From c4f516e30c72fbc88838f2ad52730d5e26f8f358 Mon Sep 17 00:00:00 2001
From: Davide Masserut <[email-masked]>
Date: Thu, 24 Aug 2023 18:33:39 +0200
Subject: [PATCH] Use correct env var when opening frames with freedesktop menu
 entries

Avoid opening X11 frames with emacsclient.desktop or
emacsclient-mail.desktop when built with PGTK.

* Makefile.in (install-etc): Replace DISPLAY with WAYLAND_DISPLAY when
built with PGTK.
---
 Makefile.in | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/Makefile.in b/Makefile.in
index fdd9353e254..6a08e1a7b18 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 "/--display=/ s/DISPLAY/WAYLAND_DISPLAY/"
+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