1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-27 01:22:30 +00:00

terminal-win: implement terminal_get_size2

The size of the console font can be acquired with GetCurrentConsoleFont,
and the terminal size can be calculated from the rols, cols, and font
size.
This commit is contained in:
nanahi 2024-03-31 16:05:14 -04:00 committed by Kacper Michajłow
parent eff18a8a11
commit 8a2892a68f

View File

@ -111,15 +111,35 @@ static bool is_native_out_vt(HANDLE hOut)
void terminal_get_size(int *w, int *h)
{
CONSOLE_SCREEN_BUFFER_INFO cinfo;
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
HANDLE hOut = hSTDOUT;
if (GetConsoleScreenBufferInfo(hOut, &cinfo)) {
*w = cinfo.dwMaximumWindowSize.X - (is_native_out_vt(hOut) ? 0 : 1);
*h = cinfo.dwMaximumWindowSize.Y;
}
}
static bool get_font_size(int *w, int *h)
{
CONSOLE_FONT_INFO finfo;
HANDLE hOut = hSTDOUT;
BOOL res = GetCurrentConsoleFont(hOut, FALSE, &finfo);
if (res) {
*w = finfo.dwFontSize.X;
*h = finfo.dwFontSize.Y;
}
return res;
}
void terminal_get_size2(int *rows, int *cols, int *px_width, int *px_height)
{
int w = 0, h = 0, fw = 0, fh = 0;
terminal_get_size(&w, &h);
if (get_font_size(&fw, &fh)) {
*px_width = fw * w;
*px_height = fh * h;
*rows = w;
*cols = h;
}
}
static bool has_input_events(HANDLE h)