diff options
author | Josh Rahm <joshuarahm@gmail.com> | 2023-11-29 21:52:58 +0000 |
---|---|---|
committer | Josh Rahm <joshuarahm@gmail.com> | 2023-11-29 21:52:58 +0000 |
commit | 931bffbda3668ddc609fc1da8f9eb576b170aa52 (patch) | |
tree | d8c1843a95da5ea0bb4acc09f7e37843d9995c86 /src/nvim/ui_compositor.c | |
parent | 142d9041391780ac15b89886a54015fdc5c73995 (diff) | |
parent | 4a8bf24ac690004aedf5540fa440e788459e5e34 (diff) | |
download | rneovim-userreg.tar.gz rneovim-userreg.tar.bz2 rneovim-userreg.zip |
Merge remote-tracking branch 'upstream/master' into userreguserreg
Diffstat (limited to 'src/nvim/ui_compositor.c')
-rw-r--r-- | src/nvim/ui_compositor.c | 66 |
1 files changed, 28 insertions, 38 deletions
diff --git a/src/nvim/ui_compositor.c b/src/nvim/ui_compositor.c index 9ff9eabff8..b698e017dc 100644 --- a/src/nvim/ui_compositor.c +++ b/src/nvim/ui_compositor.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - // Compositor: merge floating grids with the main grid for display in // TUI and non-multigrid UIs. // @@ -10,28 +7,26 @@ #include <inttypes.h> #include <limits.h> #include <stdbool.h> -#include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sys/types.h> #include "klib/kvec.h" #include "nvim/api/private/defs.h" -#include "nvim/ascii.h" -#include "nvim/buffer_defs.h" +#include "nvim/ascii_defs.h" #include "nvim/globals.h" #include "nvim/grid.h" #include "nvim/highlight.h" #include "nvim/highlight_group.h" #include "nvim/log.h" -#include "nvim/macros.h" +#include "nvim/macros_defs.h" #include "nvim/memory.h" #include "nvim/message.h" -#include "nvim/option_defs.h" +#include "nvim/option_vars.h" #include "nvim/os/time.h" -#include "nvim/types.h" +#include "nvim/types_defs.h" #include "nvim/ui.h" #include "nvim/ui_compositor.h" -#include "nvim/vim.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "ui_compositor.c.generated.h" @@ -55,7 +50,7 @@ static int msg_current_row = INT_MAX; static bool msg_was_scrolled = false; static int msg_sep_row = -1; -static schar_T msg_sep_char = { ' ', NUL }; +static schar_T msg_sep_char = schar_from_ascii(' '); static int dbghl_normal, dbghl_clear, dbghl_composed, dbghl_recompose; @@ -318,7 +313,6 @@ static void compose_line(Integer row, Integer startcol, Integer endcol, LineFlag sattr_T *bg_attrs = &default_grid.attrs[default_grid.line_offset[row] + (size_t)startcol]; - int grid_width, grid_height; while (col < endcol) { int until = 0; for (size_t i = 0; i < kv_size(layers); i++) { @@ -328,8 +322,8 @@ static void compose_line(Integer row, Integer startcol, Integer endcol, LineFlag // first check to see if any grids have pending updates to width/height, // to ensure that we don't accidentally put any characters into `linebuf` // that have been invalidated. - grid_width = MIN(g->cols, g->comp_width); - grid_height = MIN(g->rows, g->comp_height); + int grid_width = MIN(g->cols, g->comp_width); + int grid_height = MIN(g->rows, g->comp_height); if (g->comp_row > row || row >= g->comp_row + grid_height || g->comp_disabled) { continue; @@ -354,7 +348,7 @@ static void compose_line(Integer row, Integer startcol, Integer endcol, LineFlag grid = &msg_grid; sattr_T msg_sep_attr = (sattr_T)HL_ATTR(HLF_MSGSEP); for (int i = col; i < until; i++) { - memcpy(linebuf[i - startcol], msg_sep_char, sizeof(*linebuf)); + linebuf[i - startcol] = msg_sep_char; attrbuf[i - startcol] = msg_sep_attr; } } else { @@ -363,9 +357,8 @@ static void compose_line(Integer row, Integer startcol, Integer endcol, LineFlag memcpy(linebuf + (col - startcol), grid->chars + off, n * sizeof(*linebuf)); memcpy(attrbuf + (col - startcol), grid->attrs + off, n * sizeof(*attrbuf)); if (grid->comp_col + grid->cols > until - && grid->chars[off + n][0] == NUL) { - linebuf[until - 1 - startcol][0] = ' '; - linebuf[until - 1 - startcol][1] = '\0'; + && grid->chars[off + n] == NUL) { + linebuf[until - 1 - startcol] = schar_from_ascii(' '); if (col == startcol && n == 1) { skipstart = 0; } @@ -378,10 +371,10 @@ static void compose_line(Integer row, Integer startcol, Integer endcol, LineFlag for (int i = col - (int)startcol; i < until - startcol; i += width) { width = 1; // negative space - bool thru = strequal((char *)linebuf[i], " ") && bg_line[i][0] != NUL; - if (i + 1 < endcol - startcol && bg_line[i + 1][0] == NUL) { + bool thru = linebuf[i] == schar_from_ascii(' ') && bg_line[i] != NUL; + if (i + 1 < endcol - startcol && bg_line[i + 1] == NUL) { width = 2; - thru &= strequal((char *)linebuf[i + 1], " "); + thru &= linebuf[i + 1] == schar_from_ascii(' '); } attrbuf[i] = (sattr_T)hl_blend_attrs(bg_attrs[i], attrbuf[i], &thru); if (width == 2) { @@ -396,28 +389,25 @@ static void compose_line(Integer row, Integer startcol, Integer endcol, LineFlag // Tricky: if overlap caused a doublewidth char to get cut-off, must // replace the visible half with a space. - if (linebuf[col - startcol][0] == NUL) { - linebuf[col - startcol][0] = ' '; - linebuf[col - startcol][1] = NUL; + if (linebuf[col - startcol] == NUL) { + linebuf[col - startcol] = schar_from_ascii(' '); if (col == endcol - 1) { skipend = 0; } - } else if (n > 1 && linebuf[col - startcol + 1][0] == NUL) { + } else if (col == startcol && n > 1 && linebuf[1] == NUL) { skipstart = 0; } col = until; } - if (linebuf[endcol - startcol - 1][0] == NUL) { + if (linebuf[endcol - startcol - 1] == NUL) { skipend = 0; } assert(endcol <= chk_width); assert(row < chk_height); - if (!(grid && grid == &default_grid)) { - // TODO(bfredl): too conservative, need check - // grid->line_wraps if grid->Width == Width + if (!(grid && (grid == &default_grid || (grid->comp_col == 0 && grid->cols == Columns)))) { flags = flags & ~kLineFlagWrap; } @@ -439,7 +429,7 @@ static void compose_line(Integer row, Integer startcol, Integer endcol, LineFlag static void compose_debug(Integer startrow, Integer endrow, Integer startcol, Integer endcol, int syn_id, bool delay) { - if (!(rdb_flags & RDB_COMPOSITOR)) { + if (!(rdb_flags & RDB_COMPOSITOR) || startcol >= endcol) { return; } @@ -465,9 +455,9 @@ static void compose_debug(Integer startrow, Integer endrow, Integer startcol, In static void debug_delay(Integer lines) { ui_call_flush(); - uint64_t wd = (uint64_t)labs(p_wd); + uint64_t wd = (uint64_t)llabs(p_wd); uint64_t factor = (uint64_t)MAX(MIN(lines, 5), 1); - os_microdelay(factor * wd * 1000U, true); + os_sleep(factor * wd); } static void compose_area(Integer startrow, Integer endrow, Integer startcol, Integer endcol) @@ -537,7 +527,7 @@ void ui_comp_raw_line(Integer grid, Integer row, Integer startcol, Integer endco compose_debug(row, row + 1, startcol, clearcol, dbghl_composed, true); compose_line(row, startcol, clearcol, flags); } else { - compose_debug(row, row + 1, startcol, endcol, dbghl_normal, false); + compose_debug(row, row + 1, startcol, endcol, dbghl_normal, endcol >= clearcol); compose_debug(row, row + 1, endcol, clearcol, dbghl_clear, true); #ifndef NDEBUG for (int i = 0; i < endcol - startcol; i++) { @@ -568,7 +558,7 @@ void ui_comp_msg_set_pos(Integer grid, Integer row, Boolean scrolled, String sep if (scrolled && row > 0) { msg_sep_row = (int)row - 1; if (sep_char.data) { - xstrlcpy(msg_sep_char, sep_char.data, sizeof(msg_sep_char)); + msg_sep_char = schar_from_buf(sep_char.data, sep_char.size); } } else { msg_sep_row = -1; @@ -580,11 +570,11 @@ void ui_comp_msg_set_pos(Integer grid, Integer row, Boolean scrolled, String sep && (msg_current_row < Rows || (scrolled && !msg_was_scrolled))) { int delta = msg_current_row - (int)row; if (msg_grid.blending) { - int first_row = MAX((int)row - (scrolled?1:0), 0); + int first_row = MAX((int)row - (scrolled ? 1 : 0), 0); compose_area(first_row, Rows - delta, 0, Columns); } else { // scroll separator together with message text - int first_row = MAX((int)row - (msg_was_scrolled?1:0), 0); + int first_row = MAX((int)row - (msg_was_scrolled ? 1 : 0), 0); ui_composed_call_grid_scroll(1, first_row, Rows, 0, Columns, delta, 0); if (scrolled && !msg_was_scrolled && row > 0) { compose_area(row - 1, row, 0, Columns); @@ -602,8 +592,8 @@ void ui_comp_msg_set_pos(Integer grid, Integer row, Boolean scrolled, String sep static bool curgrid_covered_above(int row) { bool above_msg = (kv_A(layers, kv_size(layers) - 1) == &msg_grid - && row < msg_current_row - (msg_was_scrolled?1:0)); - return kv_size(layers) - (above_msg?1:0) > curgrid->comp_index + 1; + && row < msg_current_row - (msg_was_scrolled ? 1 : 0)); + return kv_size(layers) - (above_msg ? 1 : 0) > curgrid->comp_index + 1; } void ui_comp_grid_scroll(Integer grid, Integer top, Integer bot, Integer left, Integer right, |