Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/MacVim/MMBackend.m
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,11 @@ - (oneway void)processInput:(int)msgid data:(in bycopy NSData *)data
isTerminating = YES;
getout(0);
} else if (UpdateCellSizeMsgID == msgid) {
// Immediately handle simple state updates to they can be reflected in Vim.
// Handle this immediately so that it is picked up whenever the run
// loop is updated (e.g. during ":sleep"), not only when waiting for
// keys. This does modify Vim state, but only the cached cell size
// and reporting it to :terminal jobs, the same as what happens when a
// terminal reports its cell size in handle_csi().
[self handleCellSize:data];
} else {
// First remove previous instances of this message from the input
Expand Down Expand Up @@ -2773,9 +2777,14 @@ - (void)handleCellSize:(NSData *)data
const void *bytes = [data bytes];

// Don't use gui.char_width/height because for simplicity we set those to
// 1. We store the cell size separately (it's only used for
// getcellpixels()).
// 1. We store the cell size separately and let update_cell_size() pick it
// up, which updates cell_width/cell_height. This is more similar to
// terminal Vim than GUI Vim, due to the async multi-process architecture
// of MacVim.
memcpy(&_cellSize, bytes, sizeof(NSSize));
#if defined(FEAT_IMAGE) || defined(FEAT_EVAL)
update_cell_size();
#endif
}

- (void)handleDropFiles:(NSData *)data
Expand Down
10 changes: 2 additions & 8 deletions src/evalfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -6307,19 +6307,13 @@ f_getcellpixels(typval_T *argvars UNUSED, typval_T *rettv)
if (rettv_list_alloc(rettv) == FAIL)
return;

#if defined(FEAT_GUI)
// MacVim uses cell_width similar to terminal Vim.
#if defined(FEAT_GUI) && !defined(FEAT_GUI_MACVIM)
if (gui.in_use)
{
// success pixel size and no gui.
#ifdef FEAT_GUI_MACVIM
struct cellsize cs;
gui_mch_calc_cell_size(&cs);
list_append_number(rettv->vval.v_list, (varnumber_T)cs.cs_xpixel);
list_append_number(rettv->vval.v_list, (varnumber_T)cs.cs_ypixel);
#else
list_append_number(rettv->vval.v_list, (varnumber_T)gui.char_width);
list_append_number(rettv->vval.v_list, (varnumber_T)gui.char_height);
#endif
}
else
#endif
Expand Down
14 changes: 0 additions & 14 deletions src/os_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -4475,20 +4475,6 @@ mch_report_winsize(int fd, int rows, int cols)
ws.ws_xpixel = cols * cell_width;
ws.ws_ypixel = rows * cell_height;

#if defined(FEAT_GUI) && defined(FEAT_GUI_MACVIM)
if (gui.in_use)
{
// calculate and set tty pixel size
struct cellsize cs;
gui_mch_calc_cell_size(&cs);
if (cs.cs_xpixel != -1)
{
ws.ws_xpixel = cols * cs.cs_xpixel;
ws.ws_ypixel = rows * cs.cs_ypixel;
}
}
#endif

retval = ioctl(tty_fd, TIOCSWINSZ, &ws);
ch_log(NULL, "ioctl(TIOCSWINSZ) %s", retval == 0 ? "success" : "failed");
# elif defined(TIOCSSIZE)
Expand Down
13 changes: 13 additions & 0 deletions src/term.c
Original file line number Diff line number Diff line change
Expand Up @@ -3788,7 +3788,20 @@ update_cell_size(void)
{
# ifdef FEAT_GUI
if (gui.in_use)
{
# ifdef FEAT_GUI_MACVIM
// In MacVim, char_width/char_height are set to 1 always, and the cell
// size is updated asynchronously by the GUI, so we need to check
// whether we have a valid value first.
struct cellsize cs;

gui_mch_calc_cell_size(&cs);
if (cs.cs_xpixel > 0 && cs.cs_ypixel > 0)
set_cell_size(cs.cs_xpixel, cs.cs_ypixel);
# else
set_cell_size(gui.char_width, gui.char_height);
# endif
}
else
# endif
{
Expand Down
6 changes: 2 additions & 4 deletions src/terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -5104,10 +5104,8 @@ parse_csi(
if (gui.in_use)
{
#ifdef FEAT_GUI_MACVIM
struct cellsize cs;
gui_mch_calc_cell_size(&cs);
x += wp->w_wincol * cs.cs_xpixel;
y += W_WINROW(wp) * cs.cs_ypixel;
x += wp->w_wincol * cell_width;
y += W_WINROW(wp) * cell_height;
#else
x += wp->w_wincol * gui.char_width;
y += W_WINROW(wp) * gui.char_height;
Expand Down
4 changes: 2 additions & 2 deletions src/testdir/test_functions.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5242,8 +5242,8 @@ func Test_getcellpixels_macvim()
" deliberate design decision. Right now the caller has to wait for MacVim
" to update the state before getcellpixels() will reflect the correct
" value, hence the need for multiple wait's here.
call WaitForAssert({-> assert_notequal(0, getcellpixels()[0], 'Uninitialized getcellpixels')})
call assert_equal([7, 13], getcellpixels()) " Default font is Menlo:h11
" Until then the default 8x16 is returned, like in a terminal.
call WaitForAssert({-> assert_equal([7, 13], getcellpixels())}) " Default font is Menlo:h11
set guifont=Menlo:h13
call WaitForAssert({-> assert_equal([8, 15], getcellpixels())})

Expand Down
20 changes: 20 additions & 0 deletions src/testdir/test_macvim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,23 @@ func Test_macvim_invalid_options()

call assert_fails("let &fuoptions='abcdef'", 'E474:')
endfunc

" Test that a job in a terminal window gets the correct cell size when it
" queries it with CSI 16 t, after the font has changed.
func Test_macvim_terminal_cellsize()
CheckGui
CheckFeature terminal

" MacVim updates the cell size asynchronously, so wait for it.
set guifont=Menlo:h13
call WaitForAssert({-> assert_equal([8, 15], getcellpixels())})

let buf = term_start(['sh', '-c',
\ "stty raw -echo; printf '\\033[16t'; dd bs=64 count=1 2>/dev/null > Xcsireply"])
call WaitForAssert({-> assert_equal(["\<Esc>[6;15;8t"],
\ filereadable('Xcsireply') ? readfile('Xcsireply') : [])})

exe buf .. 'bwipe!'
call delete('Xcsireply')
set guifont&
endfunc
Loading