forked from aniani/vim
patch 8.0.0921: terminal window cursor shape not supported in the GUI
Problem: Terminal window cursor shape not supported in the GUI. Solution: Use the terminal window cursor shape in the GUI.
This commit is contained in:
47
src/gui.c
47
src/gui.c
@@ -1051,8 +1051,12 @@ gui_update_cursor(
|
|||||||
int cur_width = 0;
|
int cur_width = 0;
|
||||||
int cur_height = 0;
|
int cur_height = 0;
|
||||||
int old_hl_mask;
|
int old_hl_mask;
|
||||||
int idx;
|
cursorentry_T *shape;
|
||||||
int id;
|
int id;
|
||||||
|
#ifdef FEAT_TERMINAL
|
||||||
|
guicolor_T shape_fg = INVALCOLOR;
|
||||||
|
guicolor_T shape_bg = INVALCOLOR;
|
||||||
|
#endif
|
||||||
guicolor_T cfg, cbg, cc; /* cursor fore-/background color */
|
guicolor_T cfg, cbg, cc; /* cursor fore-/background color */
|
||||||
int cattr; /* cursor attributes */
|
int cattr; /* cursor attributes */
|
||||||
int attr;
|
int attr;
|
||||||
@@ -1094,20 +1098,35 @@ gui_update_cursor(
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* How the cursor is drawn depends on the current mode.
|
* How the cursor is drawn depends on the current mode.
|
||||||
|
* When in a terminal window use the shape/color specified there.
|
||||||
*/
|
*/
|
||||||
idx = get_shape_idx(FALSE);
|
#ifdef FEAT_TERMINAL
|
||||||
if (State & LANGMAP)
|
if (use_terminal_cursor())
|
||||||
id = shape_table[idx].id_lm;
|
shape = term_get_cursor_shape(&shape_fg, &shape_bg);
|
||||||
else
|
else
|
||||||
id = shape_table[idx].id;
|
#endif
|
||||||
|
shape = &shape_table[get_shape_idx(FALSE)];
|
||||||
|
if (State & LANGMAP)
|
||||||
|
id = shape->id_lm;
|
||||||
|
else
|
||||||
|
id = shape->id;
|
||||||
|
|
||||||
/* get the colors and attributes for the cursor. Default is inverted */
|
/* get the colors and attributes for the cursor. Default is inverted */
|
||||||
cfg = INVALCOLOR;
|
cfg = INVALCOLOR;
|
||||||
cbg = INVALCOLOR;
|
cbg = INVALCOLOR;
|
||||||
cattr = HL_INVERSE;
|
cattr = HL_INVERSE;
|
||||||
gui_mch_set_blinking(shape_table[idx].blinkwait,
|
gui_mch_set_blinking(shape->blinkwait,
|
||||||
shape_table[idx].blinkon,
|
shape->blinkon,
|
||||||
shape_table[idx].blinkoff);
|
shape->blinkoff);
|
||||||
|
#ifdef FEAT_TERMINAL
|
||||||
|
if (shape_bg != INVALCOLOR)
|
||||||
|
{
|
||||||
|
cattr = 0;
|
||||||
|
cfg = shape_fg;
|
||||||
|
cbg = shape_bg;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
if (id > 0)
|
if (id > 0)
|
||||||
{
|
{
|
||||||
cattr = syn_id2colors(id, &cfg, &cbg);
|
cattr = syn_id2colors(id, &cfg, &cbg);
|
||||||
@@ -1202,7 +1221,7 @@ gui_update_cursor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
old_hl_mask = gui.highlight_mask;
|
old_hl_mask = gui.highlight_mask;
|
||||||
if (shape_table[idx].shape == SHAPE_BLOCK
|
if (shape->shape == SHAPE_BLOCK
|
||||||
#ifdef FEAT_HANGULIN
|
#ifdef FEAT_HANGULIN
|
||||||
|| composing_hangul
|
|| composing_hangul
|
||||||
#endif
|
#endif
|
||||||
@@ -1242,16 +1261,14 @@ gui_update_cursor(
|
|||||||
* First draw the partial cursor, then overwrite with the text
|
* First draw the partial cursor, then overwrite with the text
|
||||||
* character, using a transparent background.
|
* character, using a transparent background.
|
||||||
*/
|
*/
|
||||||
if (shape_table[idx].shape == SHAPE_VER)
|
if (shape->shape == SHAPE_VER)
|
||||||
{
|
{
|
||||||
cur_height = gui.char_height;
|
cur_height = gui.char_height;
|
||||||
cur_width = (gui.char_width * shape_table[idx].percentage
|
cur_width = (gui.char_width * shape->percentage + 99) / 100;
|
||||||
+ 99) / 100;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cur_height = (gui.char_height * shape_table[idx].percentage
|
cur_height = (gui.char_height * shape->percentage + 99) / 100;
|
||||||
+ 99) / 100;
|
|
||||||
cur_width = gui.char_width;
|
cur_width = gui.char_width;
|
||||||
}
|
}
|
||||||
#ifdef FEAT_MBYTE
|
#ifdef FEAT_MBYTE
|
||||||
@@ -1259,7 +1276,7 @@ gui_update_cursor(
|
|||||||
LineOffset[gui.row] + screen_Columns) > 1)
|
LineOffset[gui.row] + screen_Columns) > 1)
|
||||||
{
|
{
|
||||||
/* Double wide character. */
|
/* Double wide character. */
|
||||||
if (shape_table[idx].shape != SHAPE_VER)
|
if (shape->shape != SHAPE_VER)
|
||||||
cur_width += gui.char_width;
|
cur_width += gui.char_width;
|
||||||
# ifdef FEAT_RIGHTLEFT
|
# ifdef FEAT_RIGHTLEFT
|
||||||
if (CURSOR_BAR_RIGHT)
|
if (CURSOR_BAR_RIGHT)
|
||||||
|
@@ -32,6 +32,7 @@ char_u *hl_get_font_name(void);
|
|||||||
void hl_set_font_name(char_u *font_name);
|
void hl_set_font_name(char_u *font_name);
|
||||||
void hl_set_bg_color_name(char_u *name);
|
void hl_set_bg_color_name(char_u *name);
|
||||||
void hl_set_fg_color_name(char_u *name);
|
void hl_set_fg_color_name(char_u *name);
|
||||||
|
guicolor_T color_name2handle(char_u *name);
|
||||||
int get_cterm_attr_idx(int attr, int fg, int bg);
|
int get_cterm_attr_idx(int attr, int fg, int bg);
|
||||||
int get_tgc_attr_idx(int attr, guicolor_T fg, guicolor_T bg);
|
int get_tgc_attr_idx(int attr, guicolor_T fg, guicolor_T bg);
|
||||||
int get_gui_attr_idx(int attr, guicolor_T fg, guicolor_T bg);
|
int get_gui_attr_idx(int attr, guicolor_T fg, guicolor_T bg);
|
||||||
|
@@ -6,6 +6,8 @@ int term_job_running(term_T *term);
|
|||||||
int term_in_normal_mode(void);
|
int term_in_normal_mode(void);
|
||||||
void term_enter_job_mode(void);
|
void term_enter_job_mode(void);
|
||||||
int send_keys_to_term(term_T *term, int c, int typed);
|
int send_keys_to_term(term_T *term, int c, int typed);
|
||||||
|
int use_terminal_cursor(void);
|
||||||
|
cursorentry_T *term_get_cursor_shape(guicolor_T *fg, guicolor_T *bg);
|
||||||
int term_use_loop(void);
|
int term_use_loop(void);
|
||||||
int terminal_loop(void);
|
int terminal_loop(void);
|
||||||
void term_job_ended(job_T *job);
|
void term_job_ended(job_T *job);
|
||||||
|
@@ -103,7 +103,6 @@ static void highlight_clear(int idx);
|
|||||||
|
|
||||||
#if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
|
#if defined(FEAT_GUI) || defined(FEAT_TERMGUICOLORS)
|
||||||
static void gui_do_one_color(int idx, int do_menu, int do_tooltip);
|
static void gui_do_one_color(int idx, int do_menu, int do_tooltip);
|
||||||
static guicolor_T color_name2handle(char_u *name);
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef FEAT_GUI
|
#ifdef FEAT_GUI
|
||||||
static int set_group_colors(char_u *name, guicolor_T *fgp, guicolor_T *bgp, int do_menu, int use_norm, int do_tooltip);
|
static int set_group_colors(char_u *name, guicolor_T *fgp, guicolor_T *bgp, int do_menu, int use_norm, int do_tooltip);
|
||||||
@@ -8622,7 +8621,7 @@ hl_do_font(
|
|||||||
* Return the handle for a color name.
|
* Return the handle for a color name.
|
||||||
* Returns INVALCOLOR when failed.
|
* Returns INVALCOLOR when failed.
|
||||||
*/
|
*/
|
||||||
static guicolor_T
|
guicolor_T
|
||||||
color_name2handle(char_u *name)
|
color_name2handle(char_u *name)
|
||||||
{
|
{
|
||||||
if (STRCMP(name, "NONE") == 0)
|
if (STRCMP(name, "NONE") == 0)
|
||||||
|
@@ -1163,11 +1163,57 @@ term_paste_register(int prev_c UNUSED)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(FEAT_GUI) || defined(PROTO)
|
||||||
|
/*
|
||||||
|
* Return TRUE when the cursor of the terminal should be displayed.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
use_terminal_cursor()
|
||||||
|
{
|
||||||
|
return in_terminal_loop != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
cursorentry_T *
|
||||||
|
term_get_cursor_shape(guicolor_T *fg, guicolor_T *bg)
|
||||||
|
{
|
||||||
|
term_T *term = in_terminal_loop;
|
||||||
|
static cursorentry_T entry;
|
||||||
|
|
||||||
|
vim_memset(&entry, 0, sizeof(entry));
|
||||||
|
entry.shape = entry.mshape =
|
||||||
|
term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_UNDERLINE ? SHAPE_HOR :
|
||||||
|
term->tl_cursor_shape == VTERM_PROP_CURSORSHAPE_BAR_LEFT ? SHAPE_VER :
|
||||||
|
SHAPE_BLOCK;
|
||||||
|
entry.percentage = 20;
|
||||||
|
if (term->tl_cursor_blink)
|
||||||
|
{
|
||||||
|
entry.blinkwait = 700;
|
||||||
|
entry.blinkon = 400;
|
||||||
|
entry.blinkon = 250;
|
||||||
|
}
|
||||||
|
*fg = gui.back_pixel;
|
||||||
|
if (term->tl_cursor_color == NULL)
|
||||||
|
*bg = gui.norm_pixel;
|
||||||
|
else
|
||||||
|
*bg = color_name2handle(term->tl_cursor_color);
|
||||||
|
entry.name = "n";
|
||||||
|
entry.used_for = SHAPE_CURSOR;
|
||||||
|
|
||||||
|
return &entry;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static int did_change_cursor = FALSE;
|
static int did_change_cursor = FALSE;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
may_set_cursor_props(term_T *term)
|
may_set_cursor_props(term_T *term)
|
||||||
{
|
{
|
||||||
|
#ifdef FEAT_GUI
|
||||||
|
/* For the GUI the cursor properties are obtained with
|
||||||
|
* term_get_cursor_shape(). */
|
||||||
|
if (gui.in_use)
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
if (in_terminal_loop == term)
|
if (in_terminal_loop == term)
|
||||||
{
|
{
|
||||||
did_change_cursor = TRUE;
|
did_change_cursor = TRUE;
|
||||||
@@ -1184,6 +1230,10 @@ may_set_cursor_props(term_T *term)
|
|||||||
static void
|
static void
|
||||||
may_restore_cursor_props(void)
|
may_restore_cursor_props(void)
|
||||||
{
|
{
|
||||||
|
#ifdef FEAT_GUI
|
||||||
|
if (gui.in_use)
|
||||||
|
return;
|
||||||
|
#endif
|
||||||
if (did_change_cursor)
|
if (did_change_cursor)
|
||||||
{
|
{
|
||||||
did_change_cursor = FALSE;
|
did_change_cursor = FALSE;
|
||||||
@@ -1241,6 +1291,8 @@ terminal_loop(void)
|
|||||||
if (!term_use_loop())
|
if (!term_use_loop())
|
||||||
/* job finished while waiting for a character */
|
/* job finished while waiting for a character */
|
||||||
break;
|
break;
|
||||||
|
if (c == K_IGNORE)
|
||||||
|
continue;
|
||||||
|
|
||||||
#ifdef UNIX
|
#ifdef UNIX
|
||||||
may_send_sigint(c, curbuf->b_term->tl_job->jv_pid, 0);
|
may_send_sigint(c, curbuf->b_term->tl_job->jv_pid, 0);
|
||||||
@@ -1447,6 +1499,9 @@ handle_settermprop(
|
|||||||
|
|
||||||
case VTERM_PROP_CURSORCOLOR:
|
case VTERM_PROP_CURSORCOLOR:
|
||||||
vim_free(term->tl_cursor_color);
|
vim_free(term->tl_cursor_color);
|
||||||
|
if (*value->string == NUL)
|
||||||
|
term->tl_cursor_color = NULL;
|
||||||
|
else
|
||||||
term->tl_cursor_color = vim_strsave((char_u *)value->string);
|
term->tl_cursor_color = vim_strsave((char_u *)value->string);
|
||||||
may_set_cursor_props(term);
|
may_set_cursor_props(term);
|
||||||
break;
|
break;
|
||||||
|
@@ -769,6 +769,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
921,
|
||||||
/**/
|
/**/
|
||||||
920,
|
920,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user