@@ -4358,55 +4358,56 @@ f_getcellpixels(typval_T *argvars UNUSED, typval_T *rettv)
43584358 if (rettv_list_alloc (rettv ) == FAIL )
43594359 return ;
43604360
4361+ // failed get pixel size.
4362+ if (cs .cs_xpixel == -1 )
4363+ return ;
4364+
4365+ #if defined(FEAT_GUI )
4366+ // gui return [].
4367+ if (gui .in_use )
4368+ return ;
4369+ #endif
4370+
4371+ // success pixel size and no gui.
43614372 list_append_number (rettv -> vval .v_list , (varnumber_T )cs .cs_xpixel );
43624373 list_append_number (rettv -> vval .v_list , (varnumber_T )cs .cs_ypixel );
43634374}
43644375#endif
43654376
43664377/*
43674378 * Try to get the current terminal cell size.
4368- * If faile get cell size, fallback 5x10 pixel.
4379+ * On failure, returns -1x-1
43694380 */
43704381 void
43714382mch_calc_cell_size (struct cellsize * cs_out )
43724383{
4373- #if defined(FEAT_GUI )
4374- if (!gui .in_use )
4375- {
4384+ // get current tty size.
4385+ struct winsize ws ;
4386+ int fd = 1 ;
4387+ int retval = -1 ;
4388+ retval = ioctl (fd , TIOCGWINSZ , & ws );
4389+
4390+ #ifdef FEAT_EVAL
4391+ ch_log (NULL , "ioctl(TIOCGWINSZ) %s" , retval == 0 ? "success" : "failed" );
43764392#endif
4377- // get current tty size.
4378- struct winsize ws ;
4379- int fd = 1 ;
4380- int retval = -1 ;
4381- retval = ioctl (fd , TIOCGWINSZ , & ws );
4382- # ifdef FEAT_EVAL
4383- ch_log (NULL , "ioctl(TIOCGWINSZ) %s" , retval == 0 ? "success" : "failed" );
4384- # endif
4385- if (retval == -1 )
4386- {
4387- cs_out -> cs_xpixel = -1 ;
4388- cs_out -> cs_ypixel = -1 ;
4389- return ;
4390- }
43914393
4392- // calculate parent tty's pixel per cell.
4393- int x_cell_size = ws .ws_xpixel / ws .ws_col ;
4394- int y_cell_size = ws .ws_ypixel / ws .ws_row ;
4394+ if (retval == -1 )
4395+ {
4396+ cs_out -> cs_xpixel = -1 ;
4397+ cs_out -> cs_ypixel = -1 ;
4398+ return ;
4399+ }
43954400
4396- // calculate current tty's pixel
4397- cs_out -> cs_xpixel = x_cell_size ;
4398- cs_out -> cs_ypixel = y_cell_size ;
4401+ // calculate parent tty's pixel per cell.
4402+ int x_cell_size = ws . ws_xpixel / ws . ws_col ;
4403+ int y_cell_size = ws . ws_ypixel / ws . ws_row ;
43994404
4400- # ifdef FEAT_EVAL
4401- ch_log (NULL , "Got cell pixel size with TIOCGWINSZ: %d x %d" , x_cell_size , y_cell_size );
4402- # endif
4403- #if defined(FEAT_GUI )
4404- }
4405- else
4406- {
4407- cs_out -> cs_xpixel = -1 ;
4408- cs_out -> cs_ypixel = -1 ;
4409- }
4405+ // calculate current tty's pixel
4406+ cs_out -> cs_xpixel = x_cell_size ;
4407+ cs_out -> cs_ypixel = y_cell_size ;
4408+
4409+ #ifdef FEAT_EVAL
4410+ ch_log (NULL , "Got cell pixel size with TIOCGWINSZ: %d x %d" , x_cell_size , y_cell_size );
44104411#endif
44114412}
44124413
@@ -4433,8 +4434,18 @@ mch_report_winsize(int fd, int rows, int cols)
44334434 // calcurate and set tty pixel size
44344435 struct cellsize cs ;
44354436 mch_calc_cell_size (& cs );
4436- ws .ws_xpixel = cols * cs .cs_xpixel ;
4437- ws .ws_ypixel = rows * cs .cs_ypixel ;
4437+
4438+ if (cs .cs_xpixel == -1 )
4439+ {
4440+ // failed get pixel size.
4441+ ws .ws_xpixel = 0 ;
4442+ ws .ws_ypixel = 0 ;
4443+ }
4444+ else
4445+ {
4446+ ws .ws_xpixel = cols * cs .cs_xpixel ;
4447+ ws .ws_ypixel = rows * cs .cs_ypixel ;
4448+ }
44384449
44394450 retval = ioctl (tty_fd , TIOCSWINSZ , & ws );
44404451 ch_log (NULL , "ioctl(TIOCSWINSZ) %s" , retval == 0 ? "success" : "failed" );
0 commit comments