Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2d2fe93

Browse files
committed
fix(tui): schedule extra resize attempts on start
When the UI starts, it might not be fast enough to register SIGWINCH, oron first reception it might not be possible to determine the terminalsize correctly. Let's schedule checks in the next second to resizecorrectly.Fixes#17285 and#15044Also refactor tui_guess_size to return if the size changed, to avoidscheduling unnecessary refresh.
1 parent2ab52bd commit2d2fe93

File tree

1 file changed

+52
-5
lines changed

1 file changed

+52
-5
lines changed

‎src/nvim/tui/tui.c‎

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ typedef struct {
8989
}output_handle;
9090
boolout_isatty;
9191
SignalWatcherwinch_handle,cont_handle;
92+
uv_timer_tinitial_resize_timer;
9293
boolcont_received;
9394
UGridgrid;
9495
kvec_t(Rect)invalid_regions;
@@ -170,6 +171,8 @@ UI *tui_start(void)
170171
ui->screenshot=tui_screenshot;
171172
ui->option_set=tui_option_set;
172173
ui->raw_line=tui_raw_line;
174+
ui->height=0;
175+
ui->width=0;
173176

174177
memset(ui->ui_ext,0,sizeof(ui->ui_ext));
175178
ui->ui_ext[kUILinegrid]= true;
@@ -227,6 +230,9 @@ static void terminfo_start(UI *ui)
227230
data->unibi_ext.set_underline_color=-1;
228231
data->out_fd=STDOUT_FILENO;
229232
data->out_isatty=os_isatty(data->out_fd);
233+
// Resizing at startup
234+
uv_timer_init(&data->loop->uv,&data->initial_resize_timer);
235+
uv_handle_set_data((uv_handle_t*)&data->initial_resize_timer,ui);
230236

231237
constchar*term=os_getenv("TERM");
232238
#ifdefWIN32
@@ -474,6 +480,7 @@ static void tui_main(UIBridgeData *bridge, UI *ui)
474480
signal_watcher_stop(&data->cont_handle);
475481
signal_watcher_close(&data->cont_handle,NULL);
476482
signal_watcher_close(&data->winch_handle,NULL);
483+
uv_close((uv_handle_t*)&data->initial_resize_timer,NULL);
477484
loop_close(&tui_loop, false);
478485
kv_destroy(data->invalid_regions);
479486
kv_destroy(data->attrs);
@@ -496,16 +503,40 @@ static void sigcont_cb(SignalWatcher *watcher, int signum, void *data)
496503
}
497504
#endif
498505

499-
staticvoidsigwinch_cb(SignalWatcher*watcher,intsignum,void*data)
506+
staticvoidresize_timer_cb(uv_timer_t*timer)
507+
{
508+
staticintcounter=0;
509+
counter++;
510+
if (handle_sigwinch(timer->data)||counter >=2) {
511+
// Don't try again if the size changed.
512+
uv_timer_stop(timer);
513+
}
514+
}
515+
516+
/// Resize and conditionally refresh
517+
///
518+
/// @return true if the size changed and refresh was scheduled
519+
staticboolhandle_sigwinch(void*data)
500520
{
501521
got_winch= true;
502522
UI*ui=data;
503523
if (tui_is_stopped(ui)) {
504-
return;
524+
return false;
505525
}
506526

507-
tui_guess_size(ui);
508-
ui_schedule_refresh();
527+
if (tui_guess_size(ui)) {
528+
ui_schedule_refresh();
529+
return true;
530+
}else {
531+
// tui_grid_resize() won't be called, take care of resetting got_winch
532+
got_winch= false;
533+
return false;
534+
}
535+
}
536+
537+
staticvoidsigwinch_cb(SignalWatcher*watcher,intsignum,void*data)
538+
{
539+
handle_sigwinch(data);
509540
}
510541

511542
staticboolattrs_differ(UI*ui,intid1,intid2,boolrgb)
@@ -935,10 +966,17 @@ static void reset_scroll_region(UI *ui, bool fullwidth)
935966

936967
staticvoidtui_grid_resize(UI*ui,Integerg,Integerwidth,Integerheight)
937968
{
969+
staticbooldid_first_resize= true;
938970
TUIData*data=ui->data;
939971
UGrid*grid=&data->grid;
940972
ugrid_resize(grid, (int)width, (int)height);
941973

974+
// When the UI starts, it might not be possible to resize correctly #15044
975+
if (did_first_resize) {
976+
did_first_resize= false;
977+
uv_timer_start(&data->initial_resize_timer,resize_timer_cb,500,500);
978+
}
979+
942980
xfree(data->space_buf);
943981
data->space_buf=xmalloc((size_t)width*sizeof(*data->space_buf));
944982
memset(data->space_buf,' ', (size_t)width);
@@ -1467,9 +1505,14 @@ static void invalidate(UI *ui, int top, int bot, int left, int right)
14671505

14681506
/// Tries to get the user's wanted dimensions (columns and rows) for the entire
14691507
/// application (i.e., the host terminal).
1470-
staticvoidtui_guess_size(UI*ui)
1508+
///
1509+
/// @param ui The UI.
1510+
/// @return true if the dimensions changed
1511+
staticbooltui_guess_size(UI*ui)
14711512
{
14721513
TUIData*data=ui->data;
1514+
intpre_width=ui->width;
1515+
intpre_height=ui->height;
14731516
intwidth=0,height=0;
14741517

14751518
// 1 - look for non-default 'columns' and 'lines' options during startup
@@ -1511,6 +1554,10 @@ static void tui_guess_size(UI *ui)
15111554

15121555
data->bridge->bridge.width=ui->width=width;
15131556
data->bridge->bridge.height=ui->height=height;
1557+
if (width!=pre_width||height!=pre_height) {
1558+
return true;
1559+
}
1560+
return false;
15141561
}
15151562

15161563
staticvoidunibi_goto(UI*ui,introw,intcol)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp