win_set_[icon_]title: send a codepage along with the string.
While fixing the previous commit I noticed that window titles don't
actually _work_ properly if you change the terminal character set,
because the text accumulated in the OSC string buffer is sent to the
TermWin as raw bytes, with no indication of what character set it
should interpret them as. You might get lucky if you happened to
choose the right charset (in particular, UTF-8 is a common default),
but if you change the charset half way through a run, then there's
certainly no way the frontend will know to interpret two window titles
sent before and after the change in two different charsets.
So, now win_set_title() and win_set_icon_title() both include a
codepage parameter along with the byte string, and it's up to them to
translate the provided window title from that encoding to whatever the
local window system expects to receive.
On Windows, that's wide-string Unicode, so we can just use the
existing dup_mb_to_wc utility function. But in GTK, it's UTF-8, so I
had to write an extra utility function to encode a wide string as
UTF-8.
2021-10-16 12:20:44 +00:00
|
|
|
/*
|
2021-11-30 18:48:06 +00:00
|
|
|
* dup_mb_to_wc: memory-allocating wrapper on mb_to_wc.
|
|
|
|
*
|
|
|
|
* Also dup_mb_to_wc_c: same but you already know the length of the
|
|
|
|
* string.
|
win_set_[icon_]title: send a codepage along with the string.
While fixing the previous commit I noticed that window titles don't
actually _work_ properly if you change the terminal character set,
because the text accumulated in the OSC string buffer is sent to the
TermWin as raw bytes, with no indication of what character set it
should interpret them as. You might get lucky if you happened to
choose the right charset (in particular, UTF-8 is a common default),
but if you change the charset half way through a run, then there's
certainly no way the frontend will know to interpret two window titles
sent before and after the change in two different charsets.
So, now win_set_title() and win_set_icon_title() both include a
codepage parameter along with the byte string, and it's up to them to
translate the provided window title from that encoding to whatever the
local window system expects to receive.
On Windows, that's wide-string Unicode, so we can just use the
existing dup_mb_to_wc utility function. But in GTK, it's UTF-8, so I
had to write an extra utility function to encode a wide string as
UTF-8.
2021-10-16 12:20:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "putty.h"
|
|
|
|
#include "misc.h"
|
|
|
|
|
|
|
|
wchar_t *dup_mb_to_wc_c(int codepage, int flags, const char *string, int len)
|
|
|
|
{
|
|
|
|
int mult;
|
|
|
|
for (mult = 1 ;; mult++) {
|
|
|
|
wchar_t *ret = snewn(mult*len + 2, wchar_t);
|
|
|
|
int outlen;
|
|
|
|
outlen = mb_to_wc(codepage, flags, string, len, ret, mult*len + 1);
|
|
|
|
if (outlen < mult*len+1) {
|
|
|
|
ret[outlen] = L'\0';
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
sfree(ret);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wchar_t *dup_mb_to_wc(int codepage, int flags, const char *string)
|
|
|
|
{
|
|
|
|
return dup_mb_to_wc_c(codepage, flags, string, strlen(string));
|
|
|
|
}
|