aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/api/ui.c6
-rw-r--r--src/nvim/cursor_shape.c6
-rw-r--r--src/nvim/tui/tui.c48
-rw-r--r--src/nvim/ui.c3
-rw-r--r--src/nvim/ui.h2
-rw-r--r--src/nvim/ui_bridge.c22
-rw-r--r--test/functional/ui/cursor_spec.lua1
-rw-r--r--test/functional/ui/screen.lua3
8 files changed, 49 insertions, 42 deletions
diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c
index a95be0fabb..de60339e5f 100644
--- a/src/nvim/api/ui.c
+++ b/src/nvim/api/ui.c
@@ -300,11 +300,11 @@ static void remote_ui_scroll(UI *ui, int count)
push_call(ui, "scroll", args);
}
-static void remote_ui_cursor_style_set(UI *ui, Dictionary styles)
+static void remote_ui_cursor_style_set(UI *ui, bool enabled, Dictionary data)
{
Array args = ARRAY_DICT_INIT;
- Object copy = copy_object(DICTIONARY_OBJ(styles));
- ADD(args, copy);
+ ADD(args, BOOLEAN_OBJ(enabled));
+ ADD(args, copy_object(DICTIONARY_OBJ(data)));
push_call(ui, "cursor_style_set", args);
}
diff --git a/src/nvim/cursor_shape.c b/src/nvim/cursor_shape.c
index 7ec70bb724..34ee53bf75 100644
--- a/src/nvim/cursor_shape.c
+++ b/src/nvim/cursor_shape.c
@@ -89,10 +89,8 @@ char_u *parse_shape_opt(int what)
int found_ve = false; /* found "ve" flag */
int round;
- /*
- * First round: check for errors; second round: do it for real.
- */
- for (round = 1; round <= 2; ++round) {
+ // First round: check for errors; second round: do it for real.
+ for (round = 1; round <= 2; round++) {
// Repeat for all comma separated parts.
modep = p_guicursor;
if (*p_guicursor == NUL) {
diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c
index badc0cd870..f34f5f1bc4 100644
--- a/src/nvim/tui/tui.c
+++ b/src/nvim/tui/tui.c
@@ -84,6 +84,7 @@ typedef struct {
} TUIData;
static bool volatile got_winch = false;
+static bool cursor_style_enabled = false;
#ifdef INCLUDE_GENERATED_DECLARATIONS
# include "tui/tui.c.generated.h"
@@ -151,6 +152,7 @@ static void terminfo_start(UI *ui)
// Set 't_Co' from the result of unibilium & fix_terminfo.
t_colors = unibi_get_num(data->ut, unibi_max_colors);
// Enter alternate screen and clear
+ // NOTE: Do this *before* changing terminal settings. #6433
unibi_out(ui, unibi_enter_ca_mode);
unibi_out(ui, unibi_clear_screen);
// Enable bracketed paste
@@ -437,11 +439,11 @@ static void tui_cursor_goto(UI *ui, int row, int col)
CursorShape tui_cursor_decode_shape(const char *shape_str)
{
CursorShape shape = 0;
- if (strcmp(shape_str, "block") == 0) {
+ if (strequal(shape_str, "block")) {
shape = SHAPE_BLOCK;
- } else if (strcmp(shape_str, "vertical") == 0) {
+ } else if (strequal(shape_str, "vertical")) {
shape = SHAPE_VER;
- } else if (strcmp(shape_str, "horizontal") == 0) {
+ } else if (strequal(shape_str, "horizontal")) {
shape = SHAPE_HOR;
} else {
EMSG2(_(e_invarg2), shape_str);
@@ -454,40 +456,41 @@ static cursorentry_T decode_cursor_entry(Dictionary args)
cursorentry_T r;
for (size_t i = 0; i < args.size; i++) {
- char *keyStr = args.items[i].key.data;
+ char *key = args.items[i].key.data;
Object value = args.items[i].value;
- if (strcmp(keyStr, "cursor_shape") == 0) {
+ if (strequal(key, "cursor_shape")) {
r.shape = tui_cursor_decode_shape(args.items[i].value.data.string.data);
- } else if (strcmp(keyStr, "blinkon") == 0) {
+ } else if (strequal(key, "blinkon")) {
r.blinkon = (int)value.data.integer;
- } else if (strcmp(keyStr, "blinkoff") == 0) {
+ } else if (strequal(key, "blinkoff")) {
r.blinkoff = (int)value.data.integer;
- } else if (strcmp(keyStr, "hl_id") == 0) {
+ } else if (strequal(key, "hl_id")) {
r.id = (int)value.data.integer;
}
}
return r;
}
-static void tui_cursor_style_set(UI *ui, Dictionary args)
+static void tui_cursor_style_set(UI *ui, bool enabled, Dictionary args)
{
+ cursor_style_enabled = enabled;
+ if (!enabled) {
+ return; // Do not send cursor style control codes.
+ }
TUIData *data = ui->data;
+ assert(args.size);
+ // Keys: as defined by `shape_table`.
for (size_t i = 0; i < args.size; i++) {
char *mode_name = args.items[i].key.data;
const int mode_id = cursor_mode_str2int(mode_name);
-
- if (mode_id < 0) {
- WLOG("Unknown mode '%s'", mode_name);
- continue;
- }
+ assert(mode_id >= 0);
cursorentry_T r = decode_cursor_entry(args.items[i].value.data.dictionary);
r.full_name = mode_name;
data->cursor_shapes[mode_id] = r;
}
- // force redraw
MouseMode cursor_mode = tui_mode2cursor(data->showing_mode);
tui_set_cursor(ui, cursor_mode);
}
@@ -528,6 +531,9 @@ static void tui_mouse_off(UI *ui)
/// @param mode one of SHAPE_XXX
static void tui_set_cursor(UI *ui, MouseMode mode)
{
+ if (!cursor_style_enabled) {
+ return;
+ }
TUIData *data = ui->data;
cursorentry_T c = data->cursor_shapes[mode];
int shape = c.shape;
@@ -536,17 +542,15 @@ static void tui_set_cursor(UI *ui, MouseMode mode)
# define TMUX_WRAP(seq) (inside_tmux ? "\x1bPtmux;\x1b" seq "\x1b\\" : seq)
// Support changing cursor shape on some popular terminals.
- const char *term_prog = os_getenv("TERM_PROGRAM");
const char *vte_version = os_getenv("VTE_VERSION");
- if ((term_prog && !strcmp(term_prog, "Konsole"))
- || os_getenv("KONSOLE_DBUS_SESSION") != NULL) {
+ if (os_getenv("KONSOLE_PROFILE_NAME") || os_getenv("KONSOLE_DBUS_SESSION")) {
// Konsole uses a proprietary escape code to set the cursor shape
// and does not support DECSCUSR.
switch (shape) {
case SHAPE_BLOCK: shape = 0; break;
case SHAPE_VER: shape = 1; break;
- case SHAPE_HOR: shape = 3; break;
+ case SHAPE_HOR: shape = 2; break;
default: WLOG("Unknown shape value %d", shape); break;
}
data->params[0].i = shape;
@@ -1102,15 +1106,15 @@ static const char *tui_tk_ti_getstr(const char *name, const char *value,
stty_erase = tui_get_stty_erase();
}
- if (strcmp(name, "key_backspace") == 0) {
+ if (strequal(name, "key_backspace")) {
ILOG("libtermkey:kbs=%s", value);
if (stty_erase != NULL && stty_erase[0] != 0) {
return stty_erase;
}
- } else if (strcmp(name, "key_dc") == 0) {
+ } else if (strequal(name, "key_dc")) {
ILOG("libtermkey:kdch1=%s", value);
// Vim: "If <BS> and <DEL> are now the same, redefine <DEL>."
- if (stty_erase != NULL && value != NULL && strcmp(stty_erase, value) == 0) {
+ if (stty_erase != NULL && value != NULL && strequal(stty_erase, value)) {
return stty_erase[0] == DEL ? CTRL_H_STR : DEL_STR;
}
}
diff --git a/src/nvim/ui.c b/src/nvim/ui.c
index babb4efa96..28f71b7ef2 100644
--- a/src/nvim/ui.c
+++ b/src/nvim/ui.c
@@ -381,7 +381,8 @@ void ui_cursor_goto(int new_row, int new_col)
void ui_cursor_style_set(void)
{
Dictionary style = cursor_shape_dict();
- UI_CALL(cursor_style_set, style);
+ bool enabled = (*p_guicursor != NUL);
+ UI_CALL(cursor_style_set, enabled, style);
api_free_dictionary(style);
}
diff --git a/src/nvim/ui.h b/src/nvim/ui.h
index 0af0c0db65..8ffc5a45a6 100644
--- a/src/nvim/ui.h
+++ b/src/nvim/ui.h
@@ -22,7 +22,7 @@ struct ui_t {
void (*clear)(UI *ui);
void (*eol_clear)(UI *ui);
void (*cursor_goto)(UI *ui, int row, int col);
- void (*cursor_style_set)(UI *ui, Dictionary cursor_shapes);
+ void (*cursor_style_set)(UI *ui, bool enabled, Dictionary cursor_styles);
void (*update_menu)(UI *ui);
void (*busy_start)(UI *ui);
void (*busy_stop)(UI *ui);
diff --git a/src/nvim/ui_bridge.c b/src/nvim/ui_bridge.c
index c9bad6b254..9f780663ac 100644
--- a/src/nvim/ui_bridge.c
+++ b/src/nvim/ui_bridge.c
@@ -60,7 +60,7 @@ UI *ui_bridge_attach(UI *ui, ui_main_fn ui_main, event_scheduler scheduler)
rv->bridge.clear = ui_bridge_clear;
rv->bridge.eol_clear = ui_bridge_eol_clear;
rv->bridge.cursor_goto = ui_bridge_cursor_goto;
- rv->bridge.cursor_style_set = ui_bridge_cursor_styleset;
+ rv->bridge.cursor_style_set = ui_bridge_cursor_style_set;
rv->bridge.update_menu = ui_bridge_update_menu;
rv->bridge.busy_start = ui_bridge_busy_start;
rv->bridge.busy_stop = ui_bridge_busy_stop;
@@ -180,19 +180,21 @@ static void ui_bridge_cursor_goto_event(void **argv)
ui->cursor_goto(ui, PTR2INT(argv[1]), PTR2INT(argv[2]));
}
-static void ui_bridge_cursor_styleset(UI *b, Dictionary style)
+static void ui_bridge_cursor_style_set(UI *b, bool enabled, Dictionary styles)
{
- Object copy = copy_object(DICTIONARY_OBJ(style));
- Object *pobj = xmalloc(sizeof(copy));
- *pobj = copy;
- UI_CALL(b, cursor_styleset, 2, b, pobj);
+ bool *enabledp = xmalloc(sizeof(*enabledp));
+ Object *stylesp = xmalloc(sizeof(*stylesp));
+ *enabledp = enabled;
+ *stylesp = copy_object(DICTIONARY_OBJ(styles));
+ UI_CALL(b, cursor_style_set, 3, b, enabledp, stylesp);
}
-static void ui_bridge_cursor_styleset_event(void **argv)
+static void ui_bridge_cursor_style_set_event(void **argv)
{
UI *ui = UI(argv[0]);
- Object *styles = (Object *)argv[1];
-
- ui->cursor_style_set(ui, styles->data.dictionary);
+ bool *enabled = argv[1];
+ Object *styles = argv[2];
+ ui->cursor_style_set(ui, *enabled, styles->data.dictionary);
+ xfree(enabled);
api_free_object(*styles);
xfree(styles);
}
diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua
index 1e3a9fcb60..c022a5649e 100644
--- a/test/functional/ui/cursor_spec.lua
+++ b/test/functional/ui/cursor_spec.lua
@@ -144,6 +144,7 @@ describe('ui/cursor', function()
}
-- Default 'guicursor' published on startup.
eq(expected_cursor_style, screen._cursor_style)
+ eq(true, screen._cursor_style_enabled)
eq('normal', screen.mode)
-- Event is published ONLY if the cursor style changed.
diff --git a/test/functional/ui/screen.lua b/test/functional/ui/screen.lua
index 3f8173c8e2..ff71194dab 100644
--- a/test/functional/ui/screen.lua
+++ b/test/functional/ui/screen.lua
@@ -345,7 +345,8 @@ function Screen:_handle_resize(width, height)
}
end
-function Screen:_handle_cursor_style_set(style)
+function Screen:_handle_cursor_style_set(enabled, style)
+ self._cursor_style_enabled = enabled
self._cursor_style = style
end