Repository: neovim/neovim
File: src/nvim/ui.c (C)

Code before:
    // The cursor move might change the composition order,
    // so flush again to update the windows that changed
    // TODO(bfredl): refactor the flow of information so that win_ui_flush()
    // only is called once. (as order state is exposed, it should be owned
    // by nvim core, not the compositor)
    win_ui_flush(false);
  }

  if (ui_comp_should_draw() && !(State & MODE_CMDLINE)) {
    int crow = curwin->w_winrow + curwin->w_winrow_off + curwin->w_wrow;
    int ccol = curwin->w_wincol + curwin->w_wincol_off +
               (curwin->w_p_rl ? curwin->w_view_width - curwin->w_wcol - 1 : curwin->w_wcol);
    if (curwin->w_cursor.coladd > 0) {
      ccol += curwin->w_cursor.coladd;
    }
    ScreenGrid *top_grid = ui_comp_get_grid_at_coord(crow, ccol);
    win_T *wp = (top_grid && top_grid != &curwin->w_grid_alloc
                 && top_grid != &default_grid) ? get_win_by_grid_handle(top_grid->handle) : NULL;
    int cur_z = curwin->w_floating ? curwin->w_config.zindex : 0;
    bool cursor_obscured = wp && wp->w_floating && wp->w_config.zindex > cur_z;

    int new_idx = cursor_obscured ? SHAPE_IDX_R : cursor_get_mode_idx();
    if (ui_mode_idx != new_idx) {
      ui_mode_idx = new_idx;
      pending_mode_update = true;
    }
  }

  if (pending_mode_info_update) {
    Arena arena = ARENA_EMPTY;
    Array style = mode_style_array(&arena);
    bool enabled = (*p_guicursor != NUL);
    ui_call_mode_info_set(enabled, style);
    arena_mem_free(arena_finish(&arena));
    pending_mode_info_update = false;
  }
  if (pending_mode_update && !starting) {
    char *full_name = shape_table[ui_mode_idx].full_name;
    ui_call_mode_change(cstr_as_string(full_name), ui_mode_idx);
    pending_mode_update = false;
  }
  if (pending_has_mouse != has_mouse) {
    (has_mouse ? ui_call_mouse_on : ui_call_mouse_off)();
    pending_has_mouse = has_mouse;
  }
  ui_call_flush();

  if (p_wd && (rdb_flags & kOptRdbFlagFlush)) {
    os_sleep((uint64_t)llabs(p_wd));
  }
}

Review comment (suggestion):
should this logic live in a new function like `ui_cursor_is_behind_floatwin`, just below `ui_cursor_shape`

Code after:
    // The cursor move might change the composition order,
    // so flush again to update the windows that changed
    // TODO(bfredl): refactor the flow of information so that win_ui_flush()
    // only is called once. (as order state is exposed, it should be owned
    // by nvim core, not the compositor)
    win_ui_flush(false);
  }

  // Show "empty box" (underline style) cursor if behind a floatwin.
  if (!(State & MODE_CMDLINE)) {
    bool cursor_obscured = ui_cursor_is_behind_floatwin();
    int new_idx = cursor_obscured ? SHAPE_IDX_R : cursor_get_mode_idx();
    if (ui_mode_idx != new_idx) {
      ui_mode_idx = new_idx;
      pending_mode_update = true;
    }
  }

  if (pending_mode_info_update) {
    Arena arena = ARENA_EMPTY;
    Array style = mode_style_array(&arena);
    bool enabled = (*p_guicursor != NUL);
    ui_call_mode_info_set(enabled, style);
    arena_mem_free(arena_finish(&arena));
    pending_mode_info_update = false;
  }
  if (pending_mode_update && !starting) {
    char *full_name = shape_table[ui_mode_idx].full_name;
    ui_call_mode_change(cstr_as_string(full_name), ui_mode_idx);
    pending_mode_update = false;
  }
  if (pending_has_mouse != has_mouse) {
    (has_mouse ? ui_call_mouse_on : ui_call_mouse_off)();
    pending_has_mouse = has_mouse;
  }
  ui_call_flush();

  if (p_wd && (rdb_flags & kOptRdbFlagFlush)) {
    os_sleep((uint64_t)llabs(p_wd));
  }
}

/// Check if 'mouse' is active for the current mode
///
/// TODO(bfredl): precompute the State -> active mapping when 'mouse' changes,
/// then this can be checked directly in ui_flush()
void ui_check_mouse(void)
{
  has_mouse = false;
  // Be quick when mouse is off.
  if (*p_mouse == NUL) {