Subject: bug#11033: (no subject)

From: Peter Oliver <[email-masked]>
Date: Tue, 8 Jun 2021 14:43:02 +0100 (BST)

Attached is a patch which causes emacs to try to create a new GUI frame if there are no existing frames and the current TTY is unusable.

This only works if emacsclient tells us which display to use, and currently it only does that if --display=… is specified.  This is fine for my purposes, but we might want to look at having it pass along $DISPLAY in more situations.

I have submitted copyright assignment paperwork but am currently waiting to hear back.

-- 
Peter Oliver

From 9b13571d0da02344a6fbb0a875ff0f88b9c65b18 Mon Sep 17 00:00:00 2001
From: Peter Oliver <[email-masked]>
Date: Tue, 8 Jun 2021 14:31:00 +0100
Subject: [PATCH] =?UTF-8?q?If=20the=20daemon=E2=80=99s=20TTY=20is=20our=20?=
 =?UTF-8?q?only=20frame,=20create=20a=20new=20frame?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* server.el (server-process-filter): If there won't be a current frame
to use, fall back to trying to create a new one.
---
 lisp/server.el | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/lisp/server.el b/lisp/server.el
index 3205ba182e..ac5db197f3 100644
--- a/lisp/server.el
+++ b/lisp/server.el
@@ -1308,7 +1308,17 @@ server-process-filter
 						       frame-parameters))
 		   ;; When resuming on a tty, tty-name is nil.
 		   (tty-name
-		    (server-create-tty-frame tty-name tty-type proc))))
+		    (server-create-tty-frame tty-name tty-type proc))
+
+                   ;; If there won't be a current frame to use, fall
+                   ;; back to trying to create a new one.
+		   ((and use-current-frame
+			 (daemonp)
+			 (null (cdr (frame-list)))
+			 (eq (selected-frame) terminal-frame)
+			 display)
+		    (setq tty-name nil tty-type nil)
+		    (server-select-display display))))
 
             (process-put
              proc 'continuation
-- 
2.31.1