From 38461eef6f3b612277bf48e49b9cc6c3b79e25bb Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 30 Jun 2024 19:44:17 +0200 Subject: csi: in-band window resize notifications, private mode 2048 This implements https://gist.github.com/rockorager/e695fb2924d36b2bcf1fff4a3704bd83, in-band window resize notifications. When user enables private mode 2048 (in-band resize notifications), *always* send current size, even if the mode is already active. This ensures applications can rely on getting a reply from the terminal. --- terminal.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'terminal.c') diff --git a/terminal.c b/terminal.c index 6e83d9a0..e1da77f5 100644 --- a/terminal.c +++ b/terminal.c @@ -44,6 +44,7 @@ #include "util.h" #include "vt.h" #include "xmalloc.h" +#include "xsnprintf.h" #define PTMX_TIMING 0 @@ -4240,3 +4241,37 @@ term_set_user_mouse_cursor(struct terminal *term, const char *cursor) : NULL; term_xcursor_update(term); } + +void +term_enable_size_notifications(struct terminal *term) +{ + /* Note: always send current size upon activation, regardless of + previous state */ + term->size_notifications = true; + term_send_size_notification(term); +} + +void +term_disable_size_notifications(struct terminal *term) +{ + if (!term->size_notifications) + return; + + term->size_notifications = false; +} + +void +term_send_size_notification(struct terminal *term) +{ + if (!term->size_notifications) + return; + + const int height = term->height - term->margins.top - term->margins.bottom; + const int width = term->width - term->margins.left - term->margins.right; + + char buf[128]; + const int n = xsnprintf( + buf, sizeof(buf), "\033[48;%d;%d;%d;%dt", + term->rows, term->cols, height, width); + term_to_slave(term, buf, n); +} -- cgit v1.3