1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-01 03:22:48 -05:00

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.
This commit is contained in:
Simon Tatham
2021-10-16 13:20:44 +01:00
parent 4f41bc04ab
commit c35d8b8328
10 changed files with 111 additions and 29 deletions

View File

@ -1433,11 +1433,13 @@ void term_update(Terminal *term)
term->win_maximise_pending = false;
}
if (term->win_title_pending) {
win_set_title(term->win, term->window_title);
win_set_title(term->win, term->window_title,
term->wintitle_codepage);
term->win_title_pending = false;
}
if (term->win_icon_title_pending) {
win_set_icon_title(term->win, term->icon_title);
win_set_icon_title(term->win, term->icon_title,
term->icontitle_codepage);
term->win_icon_title_pending = false;
}
if (term->win_pointer_shape_pending) {
@ -1670,6 +1672,7 @@ void term_reconfig(Terminal *term, Conf *conf)
if (strcmp(old_title, new_title)) {
sfree(term->window_title);
term->window_title = dupstr(new_title);
term->wintitle_codepage = DEFAULT_CODEPAGE;
term->win_title_pending = true;
term_schedule_update(term);
}
@ -1807,6 +1810,7 @@ void term_setup_window_titles(Terminal *term, const char *title_hostname)
term->window_title = dupstr(appname);
term->icon_title = dupstr(term->window_title);
}
term->wintitle_codepage = term->icontitle_codepage = DEFAULT_CODEPAGE;
term->win_title_pending = true;
term->win_icon_title_pending = true;
}
@ -2032,6 +2036,7 @@ Terminal *term_init(Conf *myconf, struct unicode_data *ucsdata, TermWin *win)
term->window_title = dupstr("");
term->icon_title = dupstr("");
term->wintitle_codepage = term->icontitle_codepage = DEFAULT_CODEPAGE;
term->minimised = false;
term->winpos_x = term->winpos_y = 0;
term->winpixsize_x = term->winpixsize_y = 0;
@ -3117,6 +3122,7 @@ static void do_osc(Terminal *term)
if (!term->no_remote_wintitle) {
sfree(term->icon_title);
term->icon_title = dupstr(term->osc_string);
term->icontitle_codepage = term->ucsdata->line_codepage;
term->win_icon_title_pending = true;
term_schedule_update(term);
}
@ -3128,6 +3134,7 @@ static void do_osc(Terminal *term)
if (!term->no_remote_wintitle) {
sfree(term->window_title);
term->window_title = dupstr(term->osc_string);
term->wintitle_codepage = term->ucsdata->line_codepage;
term->win_title_pending = true;
term_schedule_update(term);
}

View File

@ -351,6 +351,7 @@ struct terminal_tag {
int mouse_paste_clipboard;
char *window_title, *icon_title;
int wintitle_codepage, icontitle_codepage;
bool minimised;
BidiContext *bidi_ctx;