summaryrefslogtreecommitdiffstats
path: root/osdep
diff options
context:
space:
mode:
authornanahi <130121847+na-na-hi@users.noreply.github.com>2024-03-31 16:05:14 -0400
committerKacper Michajłow <kasper93@gmail.com>2024-04-18 01:03:33 +0200
commit8a2892a68fa0f166a69f8887edb6b86373b0ab1a (patch)
tree652ea140b0f619abbb6c1d20255827e37d6bf06f /osdep
parenteff18a8a11b865a7992c9c6cd740a3ef178ea9b7 (diff)
downloadmpv-8a2892a68fa0f166a69f8887edb6b86373b0ab1a.tar.bz2
mpv-8a2892a68fa0f166a69f8887edb6b86373b0ab1a.tar.xz
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.
Diffstat (limited to 'osdep')
-rw-r--r--osdep/terminal-win.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/osdep/terminal-win.c b/osdep/terminal-win.c
index 37f5164e46..2846463038 100644
--- a/osdep/terminal-win.c
+++ b/osdep/terminal-win.c
@@ -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)