mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-06-30 19:12: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:
@ -219,7 +219,7 @@ static bool pointer_indicates_raw_mouse = false;
|
||||
|
||||
static BusyStatus busy_status = BUSY_NOT;
|
||||
|
||||
static char *window_name, *icon_name;
|
||||
static wchar_t *window_name, *icon_name;
|
||||
|
||||
static int compose_state = 0;
|
||||
|
||||
@ -250,8 +250,9 @@ static void wintw_clip_write(
|
||||
static void wintw_clip_request_paste(TermWin *, int clipboard);
|
||||
static void wintw_refresh(TermWin *);
|
||||
static void wintw_request_resize(TermWin *, int w, int h);
|
||||
static void wintw_set_title(TermWin *, const char *title);
|
||||
static void wintw_set_icon_title(TermWin *, const char *icontitle);
|
||||
static void wintw_set_title(TermWin *, const char *title, int codepage);
|
||||
static void wintw_set_icon_title(TermWin *, const char *icontitle,
|
||||
int codepage);
|
||||
static void wintw_set_minimised(TermWin *, bool minimised);
|
||||
static void wintw_set_maximised(TermWin *, bool maximised);
|
||||
static void wintw_move(TermWin *, int x, int y);
|
||||
@ -416,8 +417,8 @@ static void close_session(void *ignored_context)
|
||||
|
||||
session_closed = true;
|
||||
newtitle = dupprintf("%s (inactive)", appname);
|
||||
win_set_icon_title(wintw, newtitle);
|
||||
win_set_title(wintw, newtitle);
|
||||
win_set_icon_title(wintw, newtitle, DEFAULT_CODEPAGE);
|
||||
win_set_title(wintw, newtitle, DEFAULT_CODEPAGE);
|
||||
sfree(newtitle);
|
||||
|
||||
if (ldisc) {
|
||||
@ -2955,11 +2956,11 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
|
||||
term, r.right - r.left, r.bottom - r.top);
|
||||
}
|
||||
if (wParam == SIZE_MINIMIZED)
|
||||
SetWindowText(hwnd,
|
||||
conf_get_bool(conf, CONF_win_name_always) ?
|
||||
window_name : icon_name);
|
||||
SetWindowTextW(hwnd,
|
||||
conf_get_bool(conf, CONF_win_name_always) ?
|
||||
window_name : icon_name);
|
||||
if (wParam == SIZE_RESTORED || wParam == SIZE_MAXIMIZED)
|
||||
SetWindowText(hwnd, window_name);
|
||||
SetWindowTextW(hwnd, window_name);
|
||||
if (wParam == SIZE_RESTORED) {
|
||||
processed_resize = false;
|
||||
clear_full_screen();
|
||||
@ -4707,20 +4708,20 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void wintw_set_title(TermWin *tw, const char *title)
|
||||
static void wintw_set_title(TermWin *tw, const char *title, int codepage)
|
||||
{
|
||||
sfree(window_name);
|
||||
window_name = dupstr(title);
|
||||
window_name = dup_mb_to_wc(codepage, 0, title);
|
||||
if (conf_get_bool(conf, CONF_win_name_always) || !IsIconic(wgs.term_hwnd))
|
||||
SetWindowText(wgs.term_hwnd, title);
|
||||
SetWindowTextW(wgs.term_hwnd, window_name);
|
||||
}
|
||||
|
||||
static void wintw_set_icon_title(TermWin *tw, const char *title)
|
||||
static void wintw_set_icon_title(TermWin *tw, const char *title, int codepage)
|
||||
{
|
||||
sfree(icon_name);
|
||||
icon_name = dupstr(title);
|
||||
icon_name = dup_mb_to_wc(codepage, 0, title);
|
||||
if (!conf_get_bool(conf, CONF_win_name_always) && IsIconic(wgs.term_hwnd))
|
||||
SetWindowText(wgs.term_hwnd, title);
|
||||
SetWindowTextW(wgs.term_hwnd, icon_name);
|
||||
}
|
||||
|
||||
static void wintw_set_scrollbar(TermWin *tw, int total, int start, int page)
|
||||
|
Reference in New Issue
Block a user