@@ -4348,6 +4348,68 @@ mch_get_shellsize(void)
43484348 return OK ;
43494349}
43504350
4351+ #if defined(FEAT_EVAL ) || defined(PROTO )
4352+ void
4353+ f_getcellpixels (typval_T * argvars UNUSED , typval_T * rettv )
4354+ {
4355+ struct cellsize cs ;
4356+ mch_calc_cell_size (& cs );
4357+
4358+ if (rettv_list_alloc (rettv ) == FAIL )
4359+ return ;
4360+
4361+ list_append_number (rettv -> vval .v_list , (varnumber_T )cs .cs_xpixel );
4362+ list_append_number (rettv -> vval .v_list , (varnumber_T )cs .cs_ypixel );
4363+ }
4364+ #endif
4365+
4366+ /*
4367+ * Try to get the current terminal cell size.
4368+ * If faile get cell size, fallback 5x10 pixel.
4369+ */
4370+ void
4371+ mch_calc_cell_size (struct cellsize * cs_out )
4372+ {
4373+ #if defined(FEAT_GUI )
4374+ if (!gui .in_use )
4375+ {
4376+ #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+ }
4391+
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 ;
4395+
4396+ // calculate current tty's pixel
4397+ cs_out -> cs_xpixel = x_cell_size ;
4398+ cs_out -> cs_ypixel = y_cell_size ;
4399+
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+ }
4410+ #endif
4411+ }
4412+
43514413#if defined(FEAT_TERMINAL ) || defined(PROTO )
43524414/*
43534415 * Report the windows size "rows" and "cols" to tty "fd".
@@ -4367,8 +4429,13 @@ mch_report_winsize(int fd, int rows, int cols)
43674429
43684430 ws .ws_col = cols ;
43694431 ws .ws_row = rows ;
4370- ws .ws_xpixel = cols * 5 ;
4371- ws .ws_ypixel = rows * 10 ;
4432+
4433+ // calcurate and set tty pixel size
4434+ struct cellsize cs ;
4435+ mch_calc_cell_size (& cs );
4436+ ws .ws_xpixel = cols * cs .cs_xpixel ;
4437+ ws .ws_ypixel = rows * cs .cs_ypixel ;
4438+
43724439 retval = ioctl (tty_fd , TIOCSWINSZ , & ws );
43734440 ch_log (NULL , "ioctl(TIOCSWINSZ) %s" , retval == 0 ? "success" : "failed" );
43744441# elif defined(TIOCSSIZE )
0 commit comments