Subject: bug#28340: closed (Re: bug#28340: 26.0.50; xterm frame titles)

From: [email-masked] (GNU bug Tracking System)
Date: Wed, 20 Sep 2017 16:07:03 +0000

Your bug report

#28340: 26.0.50; xterm frame titles

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
28340: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=28340
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#28340: 26.0.50; xterm frame titles
From: Mark Oteiza <[email-masked]>
To: Eli Zaretskii <[email-masked]>
Cc: [email-masked]
Date: Wed, 20 Sep 2017 12:06:18 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

On 20/09/17 at 01:47pm, Eli Zaretskii wrote:
> > Date: Wed, 20 Sep 2017 08:23:51 -0400
> > From: Mark Oteiza <[email-masked]>
> > Cc: [email-masked]
> > 
> > > What about window-configuration-change-hook, does that help?  You
> > > could set some flag in after-make-frame-functions, and then test and
> > > reset that flag in window-configuration-change-hook, when you see that
> > > a buffer is switched in the frame.  Would that work?
> > 
> > This appears to work, thank you.  Please see attached.
> 
> Thanks, this LGTM.  It needs a NEWS entry about the new defcustom, and
> then it can go in.

Thanks.  Done, pushed as 3a09343e

Subject: 26.0.50; xterm frame titles
From: Mark Oteiza <[email-masked]>
To: [email-masked]
Date: Sun, 03 Sep 2017 17:37:24 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

Wishlist item.

Hi,

I tacked setting window/iconified window titles into term/xterm.el, but
found a quirk I suspect is related to Bug#18137 (which refers to
42fe2e88d and Bug#15025).  Because clients don't always have focus,
opening a new client won't trigger hooks that I would think trigger,
perhaps even after-make-frame-functions or window-size-change-functions.

diff --git a/lisp/term/xterm.el b/lisp/term/xterm.el
index e6d224dd3d..03dd516ebf 100644
--- a/lisp/term/xterm.el
+++ b/lisp/term/xterm.el
@@ -802,6 +802,7 @@ terminal-init-xterm
     (when (memq 'setSelection xterm-extra-capabilities)
       (xterm--init-activate-set-selection)))
 
+  (xterm--init-frame-title)
   ;; Unconditionally enable bracketed paste mode: terminals that don't
   ;; support it just ignore the sequence.
   (xterm--init-bracketed-paste-mode)
@@ -828,6 +829,22 @@ xterm--init-activate-set-selection
   "Terminal initialization for `gui-set-selection'."
   (set-terminal-parameter nil 'xterm--set-selection t))
 
+(defun xterm--init-frame-title ()
+  "Terminal initialization for `gui-set-selection'."
+  (xterm-set-window-title)
+  (add-hook 'post-command-hook 'xterm-set-window-title)
+  (add-hook 'minibuffer-exit-hook 'xterm-set-window-title))
+
+(defun xterm-set-window-title ()
+  "Set the window title of the Xterm with the current Emacs frame."
+  (send-string-to-terminal
+   (format "\e]2;%s\a" (format-mode-line frame-title-format))))
+
+(defun xterm-set-icon-title ()
+  "Set the window title of the Xterm with the current Emacs frame."
+  (send-string-to-terminal
+   (format "\e]1;%s\a" (format-mode-line icon-title-format))))
+
 (defun xterm--selection-char (type)
   (pcase type
     ('PRIMARY "p")