From cdc7834ba447eb8a6a029bb72f1d54927ac8012c Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Wed, 30 May 2012 20:49:39 +0200 Subject: [PATCH] vte: allow setting margins Support changing margin size of the terminal. Signed-off-by: David Herrmann --- src/console.c | 25 +++++++++++++++++++++++++ src/console.h | 2 ++ src/vte.c | 12 +++++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/console.c b/src/console.c index 4288389..da4a728 100644 --- a/src/console.c +++ b/src/console.c @@ -1071,6 +1071,31 @@ unsigned int kmscon_console_get_height(struct kmscon_console *con) return con->cells->size_y; } +int kmscon_console_set_margins(struct kmscon_console *con, + unsigned int top, unsigned int bottom) +{ + unsigned int upper, lower; + + if (!con) + return -EINVAL; + + if (!top) + top = 1; + + if (bottom <= top) { + upper = 0; + lower = 0; + } else if (bottom > con->cells->size_y) { + upper = 0; + lower = 0; + } else { + upper = top - 1; + lower = con->cells->size_y - bottom; + } + + return kmscon_buffer_set_margins(con->cells, upper, lower); +} + void kmscon_console_reset(struct kmscon_console *con) { if (!con) diff --git a/src/console.h b/src/console.h index f425139..f867fbe 100644 --- a/src/console.h +++ b/src/console.h @@ -60,6 +60,8 @@ unsigned int kmscon_console_get_width(struct kmscon_console *con); unsigned int kmscon_console_get_height(struct kmscon_console *con); int kmscon_console_resize(struct kmscon_console *con, unsigned int x, unsigned int y, unsigned int height); +int kmscon_console_set_margins(struct kmscon_console *con, + unsigned int top, unsigned int bottom); void kmscon_console_reset(struct kmscon_console *con); void kmscon_console_set_flags(struct kmscon_console *con, unsigned int flags); void kmscon_console_reset_flags(struct kmscon_console *con, unsigned int flags); diff --git a/src/vte.c b/src/vte.c index 8d42ee5..4b8b256 100644 --- a/src/vte.c +++ b/src/vte.c @@ -979,7 +979,7 @@ static void csi_dev_attr(struct kmscon_vte *vte) static void do_csi(struct kmscon_vte *vte, uint32_t data) { - int num, x, y; + int num, x, y, upper, lower; if (vte->csi_argc < CSI_ARG_MAX) vte->csi_argc++; @@ -1073,6 +1073,16 @@ static void do_csi(struct kmscon_vte *vte, uint32_t data) case 'l': /* RM: Reset Mode */ csi_mode(vte, false); break; + case 'r': /* DECSTBM */ + /* set margin size */ + upper = vte->csi_argv[0]; + if (upper < 0) + upper = 0; + lower = vte->csi_argv[1]; + if (lower < 0) + lower = 0; + kmscon_console_set_margins(vte->con, upper, lower); + break; case 'c': /* DA */ /* device attributes */ csi_dev_attr(vte);