forked from aniani/vim
patch 8.2.3761: focus change is not passed on to a terminal window
Problem: Focus change is not passed on to a terminal window. Solution: If the current window is a terminal and focus events are enabled send a focus event escape sequence to the terminal.
This commit is contained in:
parent
48873aebc0
commit
a48d4e44a2
@ -18,6 +18,7 @@ int terminal_is_active(void);
|
|||||||
cursorentry_T *term_get_cursor_shape(guicolor_T *fg, guicolor_T *bg);
|
cursorentry_T *term_get_cursor_shape(guicolor_T *fg, guicolor_T *bg);
|
||||||
int term_use_loop(void);
|
int term_use_loop(void);
|
||||||
void term_win_entered(void);
|
void term_win_entered(void);
|
||||||
|
void term_focus_change(int in_focus);
|
||||||
int terminal_loop(int blocking);
|
int terminal_loop(int blocking);
|
||||||
int may_close_term_popup(void);
|
int may_close_term_popup(void);
|
||||||
void term_channel_closing(channel_T *ch);
|
void term_channel_closing(channel_T *ch);
|
||||||
|
@ -1127,6 +1127,21 @@ get_tty_part(term_T *term UNUSED)
|
|||||||
return PART_IN;
|
return PART_IN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Read any vterm output and send it on the channel.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
term_forward_output(term_T *term)
|
||||||
|
{
|
||||||
|
VTerm *vterm = term->tl_vterm;
|
||||||
|
char buf[KEY_BUF_LEN];
|
||||||
|
size_t curlen = vterm_output_read(vterm, buf, KEY_BUF_LEN);
|
||||||
|
|
||||||
|
if (curlen > 0)
|
||||||
|
channel_send(term->tl_job->jv_channel, get_tty_part(term),
|
||||||
|
(char_u *)buf, (int)curlen, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Write job output "msg[len]" to the vterm.
|
* Write job output "msg[len]" to the vterm.
|
||||||
*/
|
*/
|
||||||
@ -1154,14 +1169,7 @@ term_write_job_output(term_T *term, char_u *msg_arg, size_t len_arg)
|
|||||||
|
|
||||||
// flush vterm buffer when vterm responded to control sequence
|
// flush vterm buffer when vterm responded to control sequence
|
||||||
if (prevlen != vterm_output_get_buffer_current(vterm))
|
if (prevlen != vterm_output_get_buffer_current(vterm))
|
||||||
{
|
term_forward_output(term);
|
||||||
char buf[KEY_BUF_LEN];
|
|
||||||
size_t curlen = vterm_output_read(vterm, buf, KEY_BUF_LEN);
|
|
||||||
|
|
||||||
if (curlen > 0)
|
|
||||||
channel_send(term->tl_job->jv_channel, get_tty_part(term),
|
|
||||||
(char_u *)buf, (int)curlen, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
// this invokes the damage callbacks
|
// this invokes the damage callbacks
|
||||||
vterm_screen_flush_damage(vterm_obtain_screen(vterm));
|
vterm_screen_flush_damage(vterm_obtain_screen(vterm));
|
||||||
@ -2490,6 +2498,23 @@ term_win_entered()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
term_focus_change(int in_focus)
|
||||||
|
{
|
||||||
|
term_T *term = curbuf->b_term;
|
||||||
|
|
||||||
|
if (term != NULL && term->tl_vterm != NULL)
|
||||||
|
{
|
||||||
|
VTermState *state = vterm_obtain_state(term->tl_vterm);
|
||||||
|
|
||||||
|
if (in_focus)
|
||||||
|
vterm_state_focus_in(state);
|
||||||
|
else
|
||||||
|
vterm_state_focus_out(state);
|
||||||
|
term_forward_output(term);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vgetc() may not include CTRL in the key when modify_other_keys is set.
|
* vgetc() may not include CTRL in the key when modify_other_keys is set.
|
||||||
* Return the Ctrl-key value in that case.
|
* Return the Ctrl-key value in that case.
|
||||||
|
6
src/testdir/dumps/Test_terminal_focus_1.dump
Normal file
6
src/testdir/dumps/Test_terminal_focus_1.dump
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
> +0&#ffffff0@74
|
||||||
|
|~+0#4040ff13&| @73
|
||||||
|
|~| @73
|
||||||
|
|~| @73
|
||||||
|
|~| @73
|
||||||
|
|I+0#0000000&| |a|m| |l|o|s|t| @65
|
6
src/testdir/dumps/Test_terminal_focus_2.dump
Normal file
6
src/testdir/dumps/Test_terminal_focus_2.dump
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
> +0&#ffffff0@74
|
||||||
|
|~+0#4040ff13&| @73
|
||||||
|
|~| @73
|
||||||
|
|~| @73
|
||||||
|
|~| @73
|
||||||
|
|I+0#0000000&| |a|m| |b|a|c|k| @65
|
@ -1124,6 +1124,40 @@ func Test_terminal_response_to_control_sequence()
|
|||||||
unlet g:job
|
unlet g:job
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_terminal_focus_events()
|
||||||
|
CheckNotGui
|
||||||
|
CheckUnix
|
||||||
|
CheckRunVimInTerminal
|
||||||
|
|
||||||
|
let save_term = &term
|
||||||
|
let save_ttymouse = &ttymouse
|
||||||
|
set term=xterm ttymouse=xterm2
|
||||||
|
|
||||||
|
let lines =<< trim END
|
||||||
|
set term=xterm ttymouse=xterm2
|
||||||
|
au FocusLost * echo 'I am lost'
|
||||||
|
au FocusGained * echo 'I am back'
|
||||||
|
" FIXME: sometimes this job hangs, exit after a couple of seconds
|
||||||
|
call timer_start(2000, {id -> execute('qall')})
|
||||||
|
END
|
||||||
|
call writefile(lines, 'XtermFocus')
|
||||||
|
let buf = RunVimInTerminal('-S XtermFocus', #{rows: 6})
|
||||||
|
|
||||||
|
" Send a focus event to ourselves, it should be forwarded to the terminal
|
||||||
|
call feedkeys("\<Esc>[O", "Lx!")
|
||||||
|
call TermWait(buf)
|
||||||
|
call VerifyScreenDump(buf, 'Test_terminal_focus_1', {})
|
||||||
|
|
||||||
|
call feedkeys("\<Esc>[I", "Lx!")
|
||||||
|
call TermWait(buf)
|
||||||
|
call VerifyScreenDump(buf, 'Test_terminal_focus_2', {})
|
||||||
|
|
||||||
|
call StopVimInTerminal(buf)
|
||||||
|
call delete('XtermFocus')
|
||||||
|
let &term = save_term
|
||||||
|
let &ttymouse = save_ttymouse
|
||||||
|
endfunc
|
||||||
|
|
||||||
" Run Vim, start a terminal in that Vim with the kill argument,
|
" Run Vim, start a terminal in that Vim with the kill argument,
|
||||||
" :qall works.
|
" :qall works.
|
||||||
func Run_terminal_qall_kill(line1, line2)
|
func Run_terminal_qall_kill(line1, line2)
|
||||||
|
4
src/ui.c
4
src/ui.c
@ -1145,6 +1145,10 @@ ui_focus_change(
|
|||||||
last_time = time(NULL);
|
last_time = time(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef FEAT_TERMINAL
|
||||||
|
term_focus_change(in_focus);
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fire the focus gained/lost autocommand.
|
* Fire the focus gained/lost autocommand.
|
||||||
*/
|
*/
|
||||||
|
@ -753,6 +753,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 */
|
||||||
|
/**/
|
||||||
|
3761,
|
||||||
/**/
|
/**/
|
||||||
3760,
|
3760,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user