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.
This commit is contained in:
Daniel Eklöf 2024-06-30 19:44:17 +02:00
parent e11a4ab6af
commit 38461eef6f
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
6 changed files with 60 additions and 0 deletions

View file

@ -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);
}