unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Glenn Linderman <v+python@g.nevcal.com>
Cc: 19590-done@debbugs.gnu.org
Subject: bug#19590: 24.4; Window titles non-Unicode
Date: Wed, 14 Jan 2015 20:17:16 +0200	[thread overview]
Message-ID: <8361c9447n.fsf@gnu.org> (raw)
In-Reply-To: <54B574FD.9090305@g.nevcal.com>

> Date: Tue, 13 Jan 2015 11:41:49 -0800
> From: Glenn Linderman <v+python@g.nevcal.com>
> 
> I'm delighted that emacs 24.4 can, at long last, actually open files
> with any characters in their names. However, when it opens one that it
> previously couldn't (because the character is not in the current ANSI
> set), the display of the file name in the title bar has such characters
> omitted.

Thanks, this is now fixed for the next release.  The diffs are below,
in case you build your own Emacs.

commit 61cc7bf8c4059e0243903752189a13c88cc2cee5
Author: Eli Zaretskii <eliz@gnu.org>
Date:   Wed Jan 14 20:14:02 2015 +0200

    Fix support of non-ASCII frame titles on MS-Windows  (Bug#19590)
    
     src/w32fns.c (w32_set_title_bar_text): New function, including
     support for titles with non-ASCII characters outside of the
     current system codepage.
     (x_set_name, x_set_title): Use it.

diff --git a/src/ChangeLog b/src/ChangeLog
index 6296302..a90cc41 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,10 @@
+2015-01-14  Eli Zaretskii  <eliz@gnu.org>
+
+	* w32fns.c (w32_set_title_bar_text): New function, including
+	support for titles with non-ASCII characters outside of the
+	current system codepage.
+	(x_set_name, x_set_title): Use it.  (Bug#19590)
+
 2015-01-10  Eli Zaretskii  <eliz@gnu.org>
 
 	* indent.c (Fvertical_motion): Return zero if we started from ZV
diff --git a/src/w32fns.c b/src/w32fns.c
index 412e91e..5af36b9 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -1732,6 +1732,50 @@ struct frame *
   run_window_configuration_change_hook (f);
 }
 
+static void
+w32_set_title_bar_text (struct frame *f, Lisp_Object name)
+{
+  if (FRAME_W32_WINDOW (f))
+    {
+      block_input ();
+#ifdef __CYGWIN__
+      GUI_FN (SetWindowText) (FRAME_W32_WINDOW (f),
+                              GUI_SDATA (GUI_ENCODE_SYSTEM (name)));
+#else
+      /* The frame's title many times shows the name of the file
+	 visited in the selected window's buffer, so it makes sense to
+	 support non-ASCII characters outside of the current system
+	 codepage in the title.  */
+      if (w32_unicode_filenames)
+	{
+	  Lisp_Object encoded_title = ENCODE_UTF_8 (name);
+	  wchar_t *title_w;
+	  int tlen = pMultiByteToWideChar (CP_UTF8, 0, SSDATA (encoded_title),
+					   -1, NULL, 0);
+
+	  if (tlen > 0)
+	    {
+	      /* Windows truncates the title text beyond what fits on
+		 a single line, so we can limit the length to some
+		 reasonably large value, and use alloca.  */
+	      if (tlen > 10000)
+		tlen = 10000;
+	      title_w = alloca ((tlen + 1) * sizeof (wchar_t));
+	      pMultiByteToWideChar (CP_UTF8, 0, SSDATA (encoded_title), -1,
+				    title_w, tlen);
+	      title_w[tlen] = L'\0';
+	      SetWindowTextW (FRAME_W32_WINDOW (f), title_w);
+	    }
+	  else	/* Conversion to UTF-16 failed, so we punt.  */
+	    SetWindowTextA (FRAME_W32_WINDOW (f),
+			    SSDATA (ENCODE_SYSTEM (name)));
+	}
+      else
+	SetWindowTextA (FRAME_W32_WINDOW (f), SSDATA (ENCODE_SYSTEM (name)));
+#endif
+      unblock_input ();
+    }
+}
 
 /* Change the name of frame F to NAME.  If NAME is nil, set F's name to
        w32_id_name.
@@ -1785,13 +1829,7 @@ struct frame *
   if (! NILP (f->title))
     name = f->title;
 
-  if (FRAME_W32_WINDOW (f))
-    {
-      block_input ();
-      GUI_FN (SetWindowText) (FRAME_W32_WINDOW (f),
-                              GUI_SDATA (GUI_ENCODE_SYSTEM (name)));
-      unblock_input ();
-    }
+  w32_set_title_bar_text (f, name);
 }
 
 /* This function should be called when the user's lisp code has
@@ -1829,13 +1867,7 @@ struct frame *
   if (NILP (name))
     name = f->name;
 
-  if (FRAME_W32_WINDOW (f))
-    {
-      block_input ();
-      GUI_FN (SetWindowText) (FRAME_W32_WINDOW (f),
-                              GUI_SDATA (GUI_ENCODE_SYSTEM (name)));
-      unblock_input ();
-    }
+  w32_set_title_bar_text (f, name);
 }
 
 void





      reply	other threads:[~2015-01-14 18:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-13 19:41 bug#19590: 24.4; Window titles non-Unicode Glenn Linderman
2015-01-14 18:17 ` Eli Zaretskii [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8361c9447n.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=19590-done@debbugs.gnu.org \
    --cc=v+python@g.nevcal.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).