From 61571376cc19f160c31b4cc4315b4318606821c5 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 7 Feb 2021 19:59:20 +0000 Subject: [PATCH] Remove TermWin's is_minimised method. Again, I've replaced it with a push-based notification going in the other direction, so that when the terminal output stream includes a query for 'is the window minimised?', the Terminal doesn't have to consult the TermWin, because it already knows the answer. The GTK API I'm using here (getting a GdkEventWindowState via GtkWidget's window-state-event) is not present in GTK 1. The API I was previously using (gdk_window_is_viewable) _is_, but it turns out that that API doesn't reliably give the right answer: it only checks visibility of GDK window ancestors, not X window ancestors. So in fact GTK 1 PuTTY/pterm was only ever _pretending_ to reliably support the 'am I minimised' terminal query. Now it won't pretend any more. --- fuzzterm.c | 2 -- putty.h | 2 +- terminal.c | 9 +++++++-- terminal.h | 1 + unix/gtkwin.c | 26 ++++++++++++++++---------- windows/window.c | 11 +---------- 6 files changed, 26 insertions(+), 25 deletions(-) diff --git a/fuzzterm.c b/fuzzterm.c index 4a6b745c..8fe4663f 100644 --- a/fuzzterm.c +++ b/fuzzterm.c @@ -88,7 +88,6 @@ static void fuzz_request_resize(TermWin *tw, int w, int h) {} static void fuzz_set_title(TermWin *tw, const char *title) {} static void fuzz_set_icon_title(TermWin *tw, const char *icontitle) {} static void fuzz_set_minimised(TermWin *tw, bool minimised) {} -static bool fuzz_is_minimised(TermWin *tw) { return false; } static void fuzz_set_maximised(TermWin *tw, bool maximised) {} static void fuzz_move(TermWin *tw, int x, int y) {} static void fuzz_set_zorder(TermWin *tw, bool top) {} @@ -117,7 +116,6 @@ static const TermWinVtable fuzz_termwin_vt = { .set_title = fuzz_set_title, .set_icon_title = fuzz_set_icon_title, .set_minimised = fuzz_set_minimised, - .is_minimised = fuzz_is_minimised, .set_maximised = fuzz_set_maximised, .move = fuzz_move, .set_zorder = fuzz_set_zorder, diff --git a/putty.h b/putty.h index fd00019f..b5b1e7c7 100644 --- a/putty.h +++ b/putty.h @@ -1138,7 +1138,6 @@ struct TermWinVtable { * the window it remembers whether to go back to normal or * maximised. */ void (*set_minimised)(TermWin *, bool minimised); - bool (*is_minimised)(TermWin *); void (*set_maximised)(TermWin *, bool maximised); void (*move)(TermWin *, int x, int y); void (*set_zorder)(TermWin *, bool top); @@ -1638,6 +1637,7 @@ void term_keyinput(Terminal *, int codepage, const void *buf, int len); void term_keyinputw(Terminal *, const wchar_t * widebuf, int len); void term_get_cursor_position(Terminal *term, int *x, int *y); void term_setup_window_titles(Terminal *term, const char *title_hostname); +void term_notify_minimised(Terminal *term, bool minimised); typedef enum SmallKeypadKey { SKK_HOME, SKK_END, SKK_INSERT, SKK_DELETE, SKK_PGUP, SKK_PGDN, diff --git a/terminal.c b/terminal.c index b1f6bc60..97c79839 100644 --- a/terminal.c +++ b/terminal.c @@ -1792,6 +1792,7 @@ Terminal *term_init(Conf *myconf, struct unicode_data *ucsdata, TermWin *win) term->window_title = dupstr(""); term->icon_title = dupstr(""); + term->minimised = false; return term; } @@ -4425,8 +4426,7 @@ static void term_out(Terminal *term) break; case 11: if (term->ldisc) - ldisc_send(term->ldisc, - win_is_minimised(term->win) ? + ldisc_send(term->ldisc, term->minimised ? "\033[2t" : "\033[1t", 4, false); break; @@ -7322,3 +7322,8 @@ int term_get_userpass_input(Terminal *term, prompts_t *p, bufchain *input) return +1; /* all done */ } } + +void term_notify_minimised(Terminal *term, bool minimised) +{ + term->minimised = minimised; +} diff --git a/terminal.h b/terminal.h index 281e9f24..40c31963 100644 --- a/terminal.h +++ b/terminal.h @@ -344,6 +344,7 @@ struct terminal_tag { int mouse_paste_clipboard; char *window_title, *icon_title; + bool minimised; }; static inline bool in_utf(Terminal *term) diff --git a/unix/gtkwin.c b/unix/gtkwin.c index fc69c454..153f133b 100644 --- a/unix/gtkwin.c +++ b/unix/gtkwin.c @@ -565,15 +565,6 @@ static void gtkwin_set_maximised(TermWin *tw, bool maximised) #endif } -/* - * Report whether the window is minimised, for terminal reports. - */ -static bool gtkwin_is_minimised(TermWin *tw) -{ - GtkFrontend *inst = container_of(tw, GtkFrontend, termwin); - return !gdk_window_is_viewable(gtk_widget_get_window(inst->window)); -} - /* * Report the window's position, for terminal reports. */ @@ -670,6 +661,16 @@ gint delete_window(GtkWidget *widget, GdkEvent *event, GtkFrontend *inst) return false; } +#if GTK_CHECK_VERSION(2,0,0) +static void window_state_event(GtkWidget *widget, GdkEventWindowState *event, + gpointer user_data) +{ + GtkFrontend *inst = (GtkFrontend *)user_data; + term_notify_minimised( + inst->term, event->new_window_state & GDK_WINDOW_STATE_ICONIFIED); +} +#endif + static void update_mouseptr(GtkFrontend *inst) { switch (inst->busy_status) { @@ -5148,7 +5149,6 @@ static const TermWinVtable gtk_termwin_vt = { .set_title = gtkwin_set_title, .set_icon_title = gtkwin_set_icon_title, .set_minimised = gtkwin_set_minimised, - .is_minimised = gtkwin_is_minimised, .set_maximised = gtkwin_set_maximised, .move = gtkwin_move, .set_zorder = gtkwin_set_zorder, @@ -5506,6 +5506,12 @@ void new_session_window(Conf *conf, const char *geometry_string) term_size(inst->term, inst->height, inst->width, conf_get_int(inst->conf, CONF_savelines)); +#if GTK_CHECK_VERSION(2,0,0) + /* Delay this signal connection until after inst->term exists */ + g_signal_connect(G_OBJECT(inst->window), "window_state_event", + G_CALLBACK(window_state_event), inst); +#endif + inst->exited = false; start_backend(inst); diff --git a/windows/window.c b/windows/window.c index 7ec9aa82..6a32a9e0 100644 --- a/windows/window.c +++ b/windows/window.c @@ -244,7 +244,6 @@ 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_minimised(TermWin *, bool minimised); -static bool wintw_is_minimised(TermWin *); static void wintw_set_maximised(TermWin *, bool maximised); static void wintw_move(TermWin *, int x, int y); static void wintw_set_zorder(TermWin *, bool top); @@ -272,7 +271,6 @@ static const TermWinVtable windows_termwin_vt = { .set_title = wintw_set_title, .set_icon_title = wintw_set_icon_title, .set_minimised = wintw_set_minimised, - .is_minimised = wintw_is_minimised, .set_maximised = wintw_set_maximised, .move = wintw_move, .set_zorder = wintw_set_zorder, @@ -2980,6 +2978,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, "...", LOWORD(lParam), HIWORD(lParam)); #endif + term_notify_minimised(term, wParam == SIZE_MINIMIZED); if (wParam == SIZE_MINIMIZED) SetWindowText(hwnd, conf_get_bool(conf, CONF_win_name_always) ? @@ -5611,14 +5610,6 @@ static void wintw_set_maximised(TermWin *tw, bool maximised) } } -/* - * Report whether the window is iconic, for terminal reports. - */ -static bool wintw_is_minimised(TermWin *tw) -{ - return IsIconic(wgs.term_hwnd); -} - /* * Report the window's position, for terminal reports. */