From 55938684711fa31d59479a74026f4b36a6b169b2 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 16 Aug 2020 16:38:57 +0200 Subject: csi: add xtsave() This function stores the current state of DECSET private modes. --- terminal.h | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'terminal.h') diff --git a/terminal.h b/terminal.h index 983c80a0..22cea4bf 100644 --- a/terminal.h +++ b/terminal.h @@ -228,6 +228,7 @@ struct terminal { tll(struct ptmx_buffer) ptmx_buffer; + enum cursor_origin origin; enum cursor_keys cursor_keys_mode; enum keypad_keys keypad_keys_mode; bool reverse; @@ -240,6 +241,32 @@ struct terminal { enum mouse_tracking mouse_tracking; enum mouse_reporting mouse_reporting; + struct { + bool esc_prefix; + bool eight_bit; + } meta; + + /* Saved DECSET modes */ + struct { + enum cursor_origin origin; + enum cursor_keys cursor_keys_mode; + //enum keypad_keys keypad_keys_mode; + bool reverse; + bool hide_cursor; + bool auto_margin; + bool insert_mode; + bool bracketed_paste; + bool focus_events; + bool alt_scrolling; + enum mouse_tracking mouse_tracking; + enum mouse_reporting mouse_reporting; + struct { + bool esc_prefix; + bool eight_bit; + } meta; + bool alt_screen; + } xtsave; + struct charsets charsets; struct charsets saved_charsets; /* For save/restore cursor + attributes */ @@ -288,7 +315,6 @@ struct terminal { uint32_t default_table[256]; } colors; - enum cursor_origin origin; enum cursor_style default_cursor_style; enum cursor_style cursor_style; struct { @@ -328,11 +354,6 @@ struct terminal { size_t match_len; } search; - struct { - bool esc_prefix; - bool eight_bit; - } meta; - tll(int) tab_stops; struct wayland *wl; -- cgit v1.3 From b4f868e566954e6844bd74754782d0aca8bf4631 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 16 Aug 2020 16:57:39 +0200 Subject: csi: xtsave: store modes' SET state, not the current state --- csi.c | 22 +++++++++++----------- terminal.h | 25 ++++++++++++++----------- 2 files changed, 25 insertions(+), 22 deletions(-) (limited to 'terminal.h') diff --git a/csi.c b/csi.c index cd581c19..20790892 100644 --- a/csi.c +++ b/csi.c @@ -530,26 +530,26 @@ static void xtsave(struct terminal *term, unsigned param) { switch (param) { - case 1: term->xtsave.cursor_keys_mode = term->cursor_keys_mode; break; + case 1: term->xtsave.application_cursor_keys = term->cursor_keys_mode == CURSOR_KEYS_APPLICATION; break; case 3: break; case 4: break; case 5: term->xtsave.reverse = term->reverse; break; case 6: term->xtsave.origin = term->origin; break; case 7: term->xtsave.auto_margin = term->auto_margin; break; - case 9: if (term->mouse_tracking == MOUSE_X10) term->xtsave.mouse_tracking = MOUSE_X10; break; + case 9: /* term->xtsave.mouse_x10 = term->mouse_tracking == MOUSE_X10; */ break; case 12: break; - case 25: term->xtsave.hide_cursor = term->hide_cursor; break; - case 1000: if (term->mouse_tracking == MOUSE_CLICK) term->xtsave.mouse_tracking = MOUSE_CLICK; break; + case 25: term->xtsave.show_cursor = !term->hide_cursor; break; + case 1000: term->xtsave.mouse_click = term->mouse_tracking == MOUSE_CLICK; break; case 1001: break; - case 1002: if (term->mouse_tracking == MOUSE_DRAG) term->xtsave.mouse_tracking = MOUSE_DRAG; break; - case 1003: if (term->mouse_tracking == MOUSE_MOTION) term->xtsave.mouse_tracking = MOUSE_MOTION; break; + case 1002: term->xtsave.mouse_drag = term->mouse_tracking == MOUSE_DRAG; break; + case 1003: term->xtsave.mouse_motion = term->mouse_tracking == MOUSE_MOTION; break; case 1004: term->xtsave.focus_events = term->focus_events; break; - case 1005: /* if (term->mouse_reporting == MOUSE_UTF8) term->xtsave.mouse_reporting = MOUSE_UTF8; break; */ - case 1006: if (term->mouse_reporting == MOUSE_SGR) term->xtsave.mouse_reporting = MOUSE_SGR; break; + case 1005: /* term->xtsave.mouse_utf8 = term->mouse_reporting == MOUSE_UTF8; */ break; + case 1006: term->xtsave.mouse_sgr = term->mouse_reporting == MOUSE_SGR; break; case 1007: term->xtsave.alt_scrolling = term->alt_scrolling; break; - case 1015: if (term->mouse_reporting == MOUSE_URXVT) term->xtsave.mouse_reporting = MOUSE_URXVT; break; - case 1034: term->xtsave.meta.eight_bit = term->meta.eight_bit; break; - case 1036: term->xtsave.meta.esc_prefix = term->meta.esc_prefix; break; + case 1015: term->xtsave.mouse_urxvt = term->mouse_reporting == MOUSE_URXVT; break; + case 1034: term->xtsave.meta_eight_bit = term->meta.eight_bit; break; + case 1036: term->xtsave.meta_esc_prefix = term->meta.esc_prefix; break; case 1049: term->xtsave.alt_screen = term->grid == &term->alt; break; case 2004: term->xtsave.bracketed_paste = term->bracketed_paste; break; } diff --git a/terminal.h b/terminal.h index 22cea4bf..8f3416e6 100644 --- a/terminal.h +++ b/terminal.h @@ -246,24 +246,27 @@ struct terminal { bool eight_bit; } meta; - /* Saved DECSET modes */ + /* Saved DECSET modes - we save the SET state */ struct { - enum cursor_origin origin; - enum cursor_keys cursor_keys_mode; - //enum keypad_keys keypad_keys_mode; + bool origin; + bool application_cursor_keys; bool reverse; - bool hide_cursor; + bool show_cursor; bool auto_margin; + //bool cursor_blink; bool insert_mode; bool bracketed_paste; bool focus_events; bool alt_scrolling; - enum mouse_tracking mouse_tracking; - enum mouse_reporting mouse_reporting; - struct { - bool esc_prefix; - bool eight_bit; - } meta; + //bool mouse_x10; + bool mouse_click; + bool mouse_drag; + bool mouse_motion; + //bool mouse_utf8; + bool mouse_sgr; + bool mouse_urxvt; + bool meta_eight_bit; + bool meta_esc_prefix; bool alt_screen; } xtsave; -- cgit v1.3 From d4473c4e67bd10dfb7ee4816d34c50bfb33d0138 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Sun, 16 Aug 2020 16:58:32 +0200 Subject: term: xtsave: store state in a bitfield These shouldn't be accessed in any performance critical paths, so lets save some memory and use a bitfield. --- terminal.h | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'terminal.h') diff --git a/terminal.h b/terminal.h index 8f3416e6..86b5e80b 100644 --- a/terminal.h +++ b/terminal.h @@ -248,26 +248,26 @@ struct terminal { /* Saved DECSET modes - we save the SET state */ struct { - bool origin; - bool application_cursor_keys; - bool reverse; - bool show_cursor; - bool auto_margin; - //bool cursor_blink; - bool insert_mode; - bool bracketed_paste; - bool focus_events; - bool alt_scrolling; - //bool mouse_x10; - bool mouse_click; - bool mouse_drag; - bool mouse_motion; - //bool mouse_utf8; - bool mouse_sgr; - bool mouse_urxvt; - bool meta_eight_bit; - bool meta_esc_prefix; - bool alt_screen; + uint32_t origin:1; + uint32_t application_cursor_keys:1; + uint32_t reverse:1; + uint32_t show_cursor:1; + uint32_t auto_margin:1; + //uint32_t cursor_blink:1; + uint32_t insert_mode:1; + uint32_t bracketed_paste:1; + uint32_t focus_events:1; + uint32_t alt_scrolling:1; + //uint32_t mouse_x10:1; + uint32_t mouse_click:1; + uint32_t mouse_drag:1; + uint32_t mouse_motion:1; + //uint32_t mouse_utf8:1; + uint32_t mouse_sgr:1; + uint32_t mouse_urxvt:1; + uint32_t meta_eight_bit:1; + uint32_t meta_esc_prefix:1; + uint32_t alt_screen:1; } xtsave; struct charsets charsets; -- cgit v1.3 From 22dcbeacb702fd3600a4644996f1420cd778db3a Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 18 Aug 2020 07:00:26 +0200 Subject: csi: xtsave/xtrestore: implement \E[?12s and \E[?12r I.e. save/restore cursor-blink state. --- csi.c | 20 ++++++++++++++++++-- terminal.h | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) (limited to 'terminal.h') diff --git a/csi.c b/csi.c index fe5460e3..9c998cb4 100644 --- a/csi.c +++ b/csi.c @@ -4,11 +4,14 @@ #include #include #include +#include #if defined(_DEBUG) #include #endif +#include + #define LOG_MODULE "csi" #define LOG_ENABLE_DBG 0 #include "log.h" @@ -552,7 +555,20 @@ xtsave(struct terminal *term, unsigned param) case 6: term->xtsave.origin = term->origin; break; case 7: term->xtsave.auto_margin = term->auto_margin; break; case 9: /* term->xtsave.mouse_x10 = term->mouse_tracking == MOUSE_X10; */ break; - case 12: break; + + case 12: { + struct itimerspec current_value; + if (timerfd_gettime(term->cursor_blink.fd, ¤t_value) < 0) + LOG_WARN("xtsave: failed to read cursor blink timer: %s", strerror(errno)); + else { + const struct timespec zero = {}; + term->xtsave.cursor_blink = + !(memcmp(¤t_value.it_interval, &zero, sizeof(zero)) == 0 && + memcmp(¤t_value.it_value, &zero, sizeof(zero)) == 0); + } + break; + } + case 25: term->xtsave.show_cursor = !term->hide_cursor; break; case 1000: term->xtsave.mouse_click = term->mouse_tracking == MOUSE_CLICK; break; case 1001: break; @@ -582,7 +598,7 @@ xtrestore(struct terminal *term, unsigned param) case 6: enable = term->xtsave.origin; break; case 7: enable = term->xtsave.auto_margin; break; case 9: /* enable = term->xtsave.mouse_x10; break; */ return; - case 12: return; + case 12: enable = term->xtsave.cursor_blink; break; case 25: enable = term->xtsave.show_cursor; break; case 1000: enable = term->xtsave.mouse_click; break; case 1001: return; diff --git a/terminal.h b/terminal.h index 86b5e80b..d1235c2f 100644 --- a/terminal.h +++ b/terminal.h @@ -253,7 +253,7 @@ struct terminal { uint32_t reverse:1; uint32_t show_cursor:1; uint32_t auto_margin:1; - //uint32_t cursor_blink:1; + uint32_t cursor_blink:1; uint32_t insert_mode:1; uint32_t bracketed_paste:1; uint32_t focus_events:1; -- cgit v1.3