Skip to content

Commit

Permalink
Added getcellpixels() for Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikoto2000 committed Nov 11, 2024
1 parent ab6443a commit 2fb4877
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 7 deletions.
8 changes: 1 addition & 7 deletions src/evalfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2078,13 +2078,7 @@ static funcentry_T global_functions[] =
{"getbufvar", 2, 3, FEARG_1, arg3_buffer_string_any,
ret_any, f_getbufvar},
{"getcellpixels", 0, 0, 0, NULL,
ret_list_any,
#if (defined(UNIX) || defined(VMS)) && (defined(FEAT_EVAL) || defined(PROTO))
f_getcellpixels
#else
NULL
#endif
},
ret_list_any, f_getcellpixels},
{"getcellwidths", 0, 0, 0, NULL,
ret_list_any, f_getcellwidths},
{"getchangelist", 0, 1, FEARG_1, arg1_buffer,
Expand Down
51 changes: 51 additions & 0 deletions src/os_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -9050,3 +9050,54 @@ start_timeout(long msec)
return timeout_flag;
}
#endif

#if defined(FEAT_EVAL) || defined(PROTO)
void
f_getcellpixels(typval_T *argvars UNUSED, typval_T *rettv)
{
struct cellsize cs;
mch_calc_cell_size(&cs);

if (rettv_list_alloc(rettv) == FAIL)
return;

list_append_number(rettv->vval.v_list, (varnumber_T)cs.cs_xpixel);
list_append_number(rettv->vval.v_list, (varnumber_T)cs.cs_ypixel);
}
#endif

/*
* Try to get the current terminal cell size.
* If faile get cell size, fallback 5x10 pixel.
*/
void
mch_calc_cell_size(struct cellsize *cs_out)
{
#if defined(FEAT_GUI)
if (!gui.in_use)
{
#endif

HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_FONT_INFO info;
if (GetCurrentConsoleFont(console, FALSE, &info))
{
cs_out->cs_xpixel = info.dwFontSize.X;
cs_out->cs_ypixel = info.dwFontSize.Y;
}
else
{
cs_out->cs_xpixel = -1;
cs_out->cs_ypixel = -1;
}

#if defined(FEAT_GUI)
}
else
{
cs_out->cs_xpixel = -1;
cs_out->cs_ypixel = -1;
}
#endif
}

6 changes: 6 additions & 0 deletions src/os_win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,9 @@ Trace(char *pszFormat, ...);
#endif
#define mch_getenv(x) (char_u *)getenv((char *)(x))
#define vim_mkdir(x, y) mch_mkdir(x)

struct cellsize {
unsigned int cs_xpixel;
unsigned int cs_ypixel;
};

2 changes: 2 additions & 0 deletions src/proto/os_win32.pro
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,6 @@ void resize_console_buf(void);
char *GetWin32Error(void);
void stop_timeout(void);
volatile sig_atomic_t *start_timeout(long msec);
void f_getcellpixels(typval_T *argvars UNUSED, typval_T *rettv);
void mch_calc_cell_size(struct cellsize *cs_out);
/* vim: set ft=c : */

0 comments on commit 2fb4877

Please sign in to comment.