aboutsummaryrefslogtreecommitdiff
path: root/terminal.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2024-06-30 17:44:17 +0000
committerDaniel Eklöf <daniel@ekloef.se>2024-07-19 04:54:32 +0000
commit38461eef6f3b612277bf48e49b9cc6c3b79e25bb (patch)
treef73114e3853bbd55c717b0555724d353f6839b16 /terminal.c
parentwayland: #ifdef guard code related to wl_shm_release() (diff)
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.
Diffstat (limited to 'terminal.c')
-rw-r--r--terminal.c35
1 files changed, 35 insertions, 0 deletions
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);
+}