To: vim_dev@googlegroups.com Subject: Patch 8.0.1477 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.1477 Problem: Redraw flicker when moving the mouse outside of terminal window. Solution: Instead of updating the cursor color and shape every time leaving and entering a terminal window, only update when different from the previously used cursor. Files: src/terminal.c *** ../vim-8.0.1476/src/terminal.c 2018-01-30 22:31:13.751952708 +0100 --- src/terminal.c 2018-02-08 22:26:42.299566620 +0100 *************** *** 193,198 **** --- 193,208 ---- static int term_default_cterm_fg = -1; static int term_default_cterm_bg = -1; + /* Store the last set and the desired cursor properties, so that we only update + * them when needed. Doing it unnecessary may result in flicker. */ + static char_u *last_set_cursor_color = (char_u *)""; + static char_u *desired_cursor_color = (char_u *)""; + static int last_set_cursor_shape = -1; + static int desired_cursor_shape = -1; + static int last_set_cursor_blink = -1; + static int desired_cursor_blink = -1; + + /************************************** * 1. Generic code for all systems. */ *************** *** 630,636 **** { if (term->tl_job->jv_status != JOB_ENDED && term->tl_job->jv_status != JOB_FINISHED ! && term->tl_job->jv_status != JOB_FAILED) job_stop(term->tl_job, NULL, "kill"); job_unref(term->tl_job); } --- 640,646 ---- { if (term->tl_job->jv_status != JOB_ENDED && term->tl_job->jv_status != JOB_FINISHED ! && term->tl_job->jv_status != JOB_FAILED) job_stop(term->tl_job, NULL, "kill"); job_unref(term->tl_job); } *************** *** 642,647 **** --- 652,659 ---- vim_free(term->tl_status_text); vim_free(term->tl_opencmd); vim_free(term->tl_eof_chars); + if (desired_cursor_color == term->tl_cursor_color) + desired_cursor_color = (char_u *)""; vim_free(term->tl_cursor_color); vim_free(term); buf->b_term = NULL; *************** *** 1472,1479 **** } #endif ! static int did_change_cursor = FALSE; static void may_set_cursor_props(term_T *term) { --- 1484,1511 ---- } #endif ! static void ! may_output_cursor_props(void) ! { ! if (STRCMP(last_set_cursor_color, desired_cursor_color) != 0 ! || last_set_cursor_shape != desired_cursor_shape ! || last_set_cursor_blink != desired_cursor_blink) ! { ! last_set_cursor_color = desired_cursor_color; ! last_set_cursor_shape = desired_cursor_shape; ! last_set_cursor_blink = desired_cursor_blink; ! term_cursor_color(desired_cursor_color); ! if (desired_cursor_shape == -1 || desired_cursor_blink == -1) ! /* this will restore the initial cursor style, if possible */ ! ui_cursor_shape_forced(TRUE); ! else ! term_cursor_shape(desired_cursor_shape, desired_cursor_blink); ! } ! } + /* + * Set the cursor color and shape, if not last set to these. + */ static void may_set_cursor_props(term_T *term) { *************** *** 1485,1513 **** #endif if (in_terminal_loop == term) { - did_change_cursor = TRUE; if (term->tl_cursor_color != NULL) ! term_cursor_color(term->tl_cursor_color); else ! term_cursor_color((char_u *)""); ! term_cursor_shape(term->tl_cursor_shape, term->tl_cursor_blink); } } static void ! may_restore_cursor_props(void) { #ifdef FEAT_GUI if (gui.in_use) return; #endif ! if (did_change_cursor) ! { ! did_change_cursor = FALSE; ! term_cursor_color((char_u *)""); ! /* this will restore the initial cursor style, if possible */ ! ui_cursor_shape_forced(TRUE); ! } } /* --- 1517,1546 ---- #endif if (in_terminal_loop == term) { if (term->tl_cursor_color != NULL) ! desired_cursor_color = term->tl_cursor_color; else ! desired_cursor_color = (char_u *)""; ! desired_cursor_shape = term->tl_cursor_shape; ! desired_cursor_blink = term->tl_cursor_blink; ! may_output_cursor_props(); } } + /* + * Reset the desired cursor properties and restore them when needed. + */ static void ! prepare_restore_cursor_props(void) { #ifdef FEAT_GUI if (gui.in_use) return; #endif ! desired_cursor_color = (char_u *)""; ! desired_cursor_shape = -1; ! desired_cursor_blink = -1; ! may_output_cursor_props(); } /* *************** *** 1544,1549 **** --- 1577,1583 ---- int tty_fd = curbuf->b_term->tl_job->jv_channel ->ch_part[get_tty_part(curbuf->b_term)].ch_fd; #endif + int restore_cursor; /* Remember the terminal we are sending keys to. However, the terminal * might be closed while waiting for a character, e.g. typing "exit" in a *************** *** 1564,1569 **** --- 1598,1604 ---- if (update_screen(0) == FAIL) break; update_cursor(curbuf->b_term, FALSE); + restore_cursor = TRUE; c = term_vgetc(); if (!term_use_loop()) *************** *** 1672,1677 **** --- 1707,1717 ---- # endif if (send_keys_to_term(curbuf->b_term, c, TRUE) != OK) { + if (c == K_MOUSEMOVE) + /* We are sure to come back here, don't reset the cursor color + * and shape to avoid flickering. */ + restore_cursor = FALSE; + ret = OK; goto theend; } *************** *** 1680,1686 **** theend: in_terminal_loop = NULL; ! may_restore_cursor_props(); return ret; } --- 1720,1727 ---- theend: in_terminal_loop = NULL; ! if (restore_cursor) ! prepare_restore_cursor_props(); return ret; } *************** *** 2005,2010 **** --- 2046,2053 ---- break; case VTERM_PROP_CURSORCOLOR: + if (desired_cursor_color == term->tl_cursor_color) + desired_cursor_color = (char_u *)""; vim_free(term->tl_cursor_color); if (*value->string == NUL) term->tl_cursor_color = NULL; *************** *** 3292,3298 **** #define WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN 1ul #define WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN 2ull ! #define WINPTY_MOUSE_MODE_FORCE 2 void* (*winpty_config_new)(UINT64, void*); void* (*winpty_open)(void*, void*); --- 3335,3341 ---- #define WINPTY_SPAWN_FLAG_AUTO_SHUTDOWN 1ul #define WINPTY_SPAWN_FLAG_EXIT_AFTER_SHUTDOWN 2ull ! #define WINPTY_MOUSE_MODE_FORCE 2 void* (*winpty_config_new)(UINT64, void*); void* (*winpty_open)(void*, void*); *** ../vim-8.0.1476/src/version.c 2018-02-08 09:57:23.803488891 +0100 --- src/version.c 2018-02-08 22:02:55.921932878 +0100 *************** *** 773,774 **** --- 773,776 ---- { /* Add new patch number below this line */ + /**/ + 1477, /**/ -- ** Hello and Welcome to the Psychiatric Hotline ** If you are obsessive-compulsive, please press 1 repeatedly. If you are co-dependent, please ask someone to press 2. If you have multiple personalities, please press 3, 4, 5 and 6. If you are paranoid-delusional, we know who you are and what you want - just stay on the line so we can trace the call. If you are schizophrenic, listen carefully and a little voice will tell you which number to press next. If you are manic-depressive, it doesn't matter which number you press - no one will answer. If you suffer from panic attacks, push every button you can find. If you are sane, please hold on - we have the rest of humanity on the other line and they desparately want to ask you a few questions. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///