diff options
Diffstat (limited to 'src/nvim/ui_compositor.c')
-rw-r--r-- | src/nvim/ui_compositor.c | 143 |
1 files changed, 71 insertions, 72 deletions
diff --git a/src/nvim/ui_compositor.c b/src/nvim/ui_compositor.c index e356960cc8..60ad8609a4 100644 --- a/src/nvim/ui_compositor.c +++ b/src/nvim/ui_compositor.c @@ -141,15 +141,15 @@ bool ui_comp_put_grid(ScreenGrid *grid, int row, int col, int height, int width, grid->comp_col, grid->comp_col + grid->Columns); if (grid->comp_col < col) { compose_area(MAX(row, grid->comp_row), - MIN(row+height, grid->comp_row+grid->Rows), + MIN(row + height, grid->comp_row + grid->Rows), grid->comp_col, col); } - if (col+width < grid->comp_col+grid->Columns) { + if (col + width < grid->comp_col + grid->Columns) { compose_area(MAX(row, grid->comp_row), - MIN(row+height, grid->comp_row+grid->Rows), - col+width, grid->comp_col+grid->Columns); + MIN(row + height, grid->comp_row + grid->Rows), + col + width, grid->comp_col + grid->Columns); } - compose_area(row+height, grid->comp_row+grid->Rows, + compose_area(row + height, grid->comp_row + grid->Rows, grid->comp_col, grid->comp_col + grid->Columns); grid->comp_disabled = false; } @@ -166,19 +166,19 @@ bool ui_comp_put_grid(ScreenGrid *grid, int row, int col, int height, int width, #endif size_t insert_at = kv_size(layers); - while (insert_at > 0 && kv_A(layers, insert_at-1)->zindex > grid->zindex) { + while (insert_at > 0 && kv_A(layers, insert_at - 1)->zindex > grid->zindex) { insert_at--; } - if (curwin && kv_A(layers, insert_at-1) == &curwin->w_grid_alloc - && kv_A(layers, insert_at-1)->zindex == grid->zindex + if (curwin && kv_A(layers, insert_at - 1) == &curwin->w_grid_alloc + && kv_A(layers, insert_at - 1)->zindex == grid->zindex && !on_top) { insert_at--; } // not found: new grid kv_pushp(layers); - for (size_t i = kv_size(layers)-1; i > insert_at; i--) { - kv_A(layers, i) = kv_A(layers, i-1); + for (size_t i = kv_size(layers) - 1; i > insert_at; i--) { + kv_A(layers, i) = kv_A(layers, i - 1); kv_A(layers, i)->comp_index = i; } kv_A(layers, insert_at) = grid; @@ -188,8 +188,8 @@ bool ui_comp_put_grid(ScreenGrid *grid, int row, int col, int height, int width, grid->comp_index = insert_at; } if (moved && valid && ui_comp_should_draw()) { - compose_area(grid->comp_row, grid->comp_row+grid->Rows, - grid->comp_col, grid->comp_col+grid->Columns); + compose_area(grid->comp_row, grid->comp_row + grid->Rows, + grid->comp_col, grid->comp_col + grid->Columns); } return moved; } @@ -206,8 +206,8 @@ void ui_comp_remove_grid(ScreenGrid *grid) curgrid = &default_grid; } - for (size_t i = grid->comp_index; i < kv_size(layers)-1; i++) { - kv_A(layers, i) = kv_A(layers, i+1); + for (size_t i = grid->comp_index; i < kv_size(layers) - 1; i++) { + kv_A(layers, i) = kv_A(layers, i + 1); kv_A(layers, i)->comp_index = i; } (void)kv_pop(layers); @@ -241,7 +241,7 @@ static void ui_comp_raise_grid(ScreenGrid *grid, size_t new_index) { size_t old_index = grid->comp_index; for (size_t i = old_index; i < new_index; i++) { - kv_A(layers, i) = kv_A(layers, i+1); + kv_A(layers, i) = kv_A(layers, i + 1); kv_A(layers, i)->comp_index = i; } kv_A(layers, new_index) = grid; @@ -249,10 +249,10 @@ static void ui_comp_raise_grid(ScreenGrid *grid, size_t new_index) for (size_t i = old_index; i < new_index; i++) { ScreenGrid *grid2 = kv_A(layers, i); int startcol = MAX(grid->comp_col, grid2->comp_col); - int endcol = MIN(grid->comp_col+grid->Columns, - grid2->comp_col+grid2->Columns); + int endcol = MIN(grid->comp_col + grid->Columns, + grid2->comp_col + grid2->Columns); compose_area(MAX(grid->comp_row, grid2->comp_row), - MIN(grid->comp_row+grid->Rows, grid2->comp_row+grid2->Rows), + MIN(grid->comp_row + grid->Rows, grid2->comp_row + grid2->Rows), startcol, endcol); } } @@ -262,13 +262,13 @@ static void ui_comp_grid_cursor_goto(UI *ui, Integer grid_handle, Integer r, Int if (!ui_comp_should_draw() || !ui_comp_set_grid((int)grid_handle)) { return; } - int cursor_row = curgrid->comp_row+(int)r; - int cursor_col = curgrid->comp_col+(int)c; + int cursor_row = curgrid->comp_row + (int)r; + int cursor_col = curgrid->comp_col + (int)c; // TODO(bfredl): maybe not the best time to do this, for efficiency we // should configure all grids before entering win_update() if (curgrid != &default_grid) { - size_t new_index = kv_size(layers)-1; + size_t new_index = kv_size(layers) - 1; while (new_index > 1 && kv_A(layers, new_index)->zindex > curgrid->zindex) { new_index--; @@ -289,11 +289,11 @@ static void ui_comp_grid_cursor_goto(UI *ui, Integer grid_handle, Integer r, Int ScreenGrid *ui_comp_mouse_focus(int row, int col) { - for (ssize_t i = (ssize_t)kv_size(layers)-1; i > 0; i--) { + for (ssize_t i = (ssize_t)kv_size(layers) - 1; i > 0; i--) { ScreenGrid *grid = kv_A(layers, i); if (grid->focusable - && row >= grid->comp_row && row < grid->comp_row+grid->Rows - && col >= grid->comp_col && col < grid->comp_col+grid->Columns) { + && row >= grid->comp_row && row < grid->comp_row + grid->Rows + && col >= grid->comp_col && col < grid->comp_col + grid->Columns) { return grid; } } @@ -323,9 +323,9 @@ static void compose_line(Integer row, Integer startcol, Integer endcol, LineFlag int col = (int)startcol; ScreenGrid *grid = NULL; schar_T *bg_line = &default_grid.chars[default_grid.line_offset[row] - +(size_t)startcol]; + + (size_t)startcol]; sattr_T *bg_attrs = &default_grid.attrs[default_grid.line_offset[row] - +(size_t)startcol]; + + (size_t)startcol]; int grid_width, grid_height; while (col < endcol) { @@ -355,7 +355,7 @@ static void compose_line(Integer row, Integer startcol, Integer endcol, LineFlag assert(grid != NULL); assert(until > col); assert(until <= default_grid.Columns); - size_t n = (size_t)(until-col); + size_t n = (size_t)(until - col); if (row == msg_sep_row && grid->comp_index <= msg_grid.comp_index) { // TODO(bfredl): when we implement borders around floating windows, then @@ -363,18 +363,18 @@ 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)); - attrbuf[i-startcol] = msg_sep_attr; + memcpy(linebuf[i - startcol], msg_sep_char, sizeof(*linebuf)); + attrbuf[i - startcol] = msg_sep_attr; } } else { - size_t off = grid->line_offset[row-grid->comp_row] - + (size_t)(col-grid->comp_col); - 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->Columns > until - && grid->chars[off+n][0] == NUL) { - linebuf[until-1-startcol][0] = ' '; - linebuf[until-1-startcol][1] = '\0'; + size_t off = grid->line_offset[row - grid->comp_row] + + (size_t)(col - grid->comp_col); + 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->Columns > until + && grid->chars[off + n][0] == NUL) { + linebuf[until - 1 - startcol][0] = ' '; + linebuf[until - 1 - startcol][1] = '\0'; if (col == startcol && n == 1) { skipstart = 0; } @@ -384,18 +384,18 @@ static void compose_line(Integer row, Integer startcol, Integer endcol, LineFlag // 'pumblend' and 'winblend' if (grid->blending) { int width; - for (int i = col-(int)startcol; i < until-startcol; i += width) { + 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) { + if (i + 1 < endcol - startcol && bg_line[i + 1][0] == NUL) { width = 2; - thru &= strequal((char *)linebuf[i+1], " "); + thru &= strequal((char *)linebuf[i + 1], " "); } attrbuf[i] = (sattr_T)hl_blend_attrs(bg_attrs[i], attrbuf[i], &thru); if (width == 2) { - attrbuf[i+1] = (sattr_T)hl_blend_attrs(bg_attrs[i+1], - attrbuf[i+1], &thru); + attrbuf[i + 1] = (sattr_T)hl_blend_attrs(bg_attrs[i + 1], + attrbuf[i + 1], &thru); } if (thru) { memcpy(linebuf + i, bg_line + i, (size_t)width * sizeof(linebuf[i])); @@ -405,19 +405,19 @@ 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 (col == endcol-1) { + if (linebuf[col - startcol][0] == NUL) { + linebuf[col - startcol][0] = ' '; + linebuf[col - startcol][1] = NUL; + if (col == endcol - 1) { skipend = 0; } - } else if (n > 1 && linebuf[col-startcol+1][0] == NUL) { + } else if (n > 1 && linebuf[col - startcol + 1][0] == NUL) { skipstart = 0; } col = until; } - if (linebuf[endcol-startcol-1][0] == NUL) { + if (linebuf[endcol - startcol - 1][0] == NUL) { skipend = 0; } @@ -430,7 +430,7 @@ static void compose_line(Integer row, Integer startcol, Integer endcol, LineFlag flags = flags & ~kLineFlagWrap; } - for (int i = skipstart; i < (endcol-skipend)-startcol; i++) { + for (int i = skipstart; i < (endcol - skipend) - startcol; i++) { if (attrbuf[i] < 0) { if (rdb_flags & RDB_INVALID) { abort(); @@ -439,10 +439,10 @@ static void compose_line(Integer row, Integer startcol, Integer endcol, LineFlag } } } - ui_composed_call_raw_line(1, row, startcol+skipstart, - endcol-skipend, endcol-skipend, 0, flags, - (const schar_T *)linebuf+skipstart, - (const sattr_T *)attrbuf+skipstart); + ui_composed_call_raw_line(1, row, startcol + skipstart, + endcol - skipend, endcol - skipend, 0, flags, + (const schar_T *)linebuf + skipstart, + (const sattr_T *)attrbuf + skipstart); } static void compose_debug(Integer startrow, Integer endrow, Integer startcol, Integer endcol, @@ -464,7 +464,7 @@ static void compose_debug(Integer startrow, Integer endrow, Integer startcol, In if (delay) { - debug_delay(endrow-startrow); + debug_delay(endrow - startrow); } } @@ -497,8 +497,8 @@ static void compose_area(Integer startrow, Integer endrow, Integer startcol, Int void ui_comp_compose_grid(ScreenGrid *grid) { if (ui_comp_should_draw()) { - compose_area(grid->comp_row, grid->comp_row+grid->Rows, - grid->comp_col, grid->comp_col+grid->Columns); + compose_area(grid->comp_row, grid->comp_row + grid->Rows, + grid->comp_col, grid->comp_col + grid->Columns); } } @@ -541,13 +541,13 @@ static void ui_comp_raw_line(UI *ui, Integer grid, Integer row, Integer startcol // TODO(bfredl): eventually should just fix compose_line to respect clearing // and optimize it for uncovered lines. if (flags & kLineFlagInvalid || covered || curgrid->blending) { - compose_debug(row, row+1, startcol, clearcol, dbghl_composed, true); + 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, endcol, clearcol, dbghl_clear, true); + compose_debug(row, row + 1, startcol, endcol, dbghl_normal, false); + compose_debug(row, row + 1, endcol, clearcol, dbghl_clear, true); #ifndef NDEBUG - for (int i = 0; i < endcol-startcol; i++) { + for (int i = 0; i < endcol - startcol; i++) { assert(attrs[i] >= 0); } #endif @@ -572,7 +572,7 @@ static void ui_comp_msg_set_pos(UI *ui, Integer grid, Integer row, Boolean scrol { msg_grid.comp_row = (int)row; if (scrolled && row > 0) { - msg_sep_row = (int)row-1; + msg_sep_row = (int)row - 1; if (sep_char.data) { STRLCPY(msg_sep_char, sep_char.data, sizeof(msg_sep_char)); } @@ -581,19 +581,19 @@ static void ui_comp_msg_set_pos(UI *ui, Integer grid, Integer row, Boolean scrol } if (row > msg_current_row && ui_comp_should_draw()) { - compose_area(MAX(msg_current_row-1, 0), row, 0, default_grid.Columns); + compose_area(MAX(msg_current_row - 1, 0), row, 0, default_grid.Columns); } else if (row < msg_current_row && ui_comp_should_draw() && msg_current_row < Rows) { int delta = msg_current_row - (int)row; if (msg_grid.blending) { - int first_row = MAX((int)row-(scrolled?1:0), 0); - compose_area(first_row, Rows-delta, 0, Columns); + 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); + compose_area(row - 1, row, 0, Columns); } } } @@ -607,9 +607,9 @@ static void ui_comp_msg_set_pos(UI *ui, Integer grid, Integer row, Boolean scrol /// TODO(bfredl): currently this only handles message row 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; + 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; } static void ui_comp_grid_scroll(UI *ui, Integer grid, Integer top, Integer bot, Integer left, @@ -634,8 +634,8 @@ static void ui_comp_grid_scroll(UI *ui, Integer grid, Integer top, Integer bot, // row, where the latter might scroll invalid space created by the first. // ideally win_update() should keep track of this itself and not scroll // the invalid space. - if (curgrid->attrs[curgrid->line_offset[r-curgrid->comp_row] - +left-curgrid->comp_col] >= 0) { + if (curgrid->attrs[curgrid->line_offset[r - curgrid->comp_row] + + left - curgrid->comp_col] >= 0) { compose_line(r, left, right, 0); } } @@ -665,4 +665,3 @@ static void ui_comp_grid_resize(UI *ui, Integer grid, Integer width, Integer hei } } } - |