summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShreesh Adiga <16567adigashreesh@gmail.com>2020-11-11 15:30:08 +0530
committeravih <avih@users.noreply.github.com>2020-11-22 13:34:25 +0200
commit670f23f1698bb19ea2869e8f82198b2f9083ef88 (patch)
tree92185b9d21b3a85a7cf5e21e9e58c91bc1cb4747
parent38275338ee3d52fa703067ad8375077b1e4850a2 (diff)
downloadmpv-670f23f1698bb19ea2869e8f82198b2f9083ef88.tar.bz2
mpv-670f23f1698bb19ea2869e8f82198b2f9083ef88.tar.xz
osdep/terminal: Add function to get terminal pixel dimensions
-rw-r--r--osdep/terminal-dummy.c4
-rw-r--r--osdep/terminal-unix.c13
-rw-r--r--osdep/terminal-win.c4
-rw-r--r--osdep/terminal.h3
4 files changed, 24 insertions, 0 deletions
diff --git a/osdep/terminal-dummy.c b/osdep/terminal-dummy.c
index 4a3787e0fa..4b33d786a8 100644
--- a/osdep/terminal-dummy.c
+++ b/osdep/terminal-dummy.c
@@ -21,6 +21,10 @@ void terminal_get_size(int *w, int *h)
{
}
+void terminal_get_size2(int *rows, int *cols, int *px_width, int *px_height)
+{
+}
+
void mp_write_console_ansi(void *wstream, char *buf)
{
}
diff --git a/osdep/terminal-unix.c b/osdep/terminal-unix.c
index 8e4d75f78b..78eb4c4618 100644
--- a/osdep/terminal-unix.c
+++ b/osdep/terminal-unix.c
@@ -493,6 +493,19 @@ void terminal_get_size(int *w, int *h)
*h = ws.ws_row;
}
+void terminal_get_size2(int *rows, int *cols, int *px_width, int *px_height)
+{
+ struct winsize ws;
+ if (ioctl(tty_in, TIOCGWINSZ, &ws) < 0 || !ws.ws_row || !ws.ws_col
+ || !ws.ws_xpixel || !ws.ws_ypixel)
+ return;
+
+ *rows = ws.ws_row;
+ *cols = ws.ws_col;
+ *px_width = ws.ws_xpixel;
+ *px_height = ws.ws_ypixel;
+}
+
void terminal_init(void)
{
assert(!getch2_enabled);
diff --git a/osdep/terminal-win.c b/osdep/terminal-win.c
index 3672f3a763..dab3fabc80 100644
--- a/osdep/terminal-win.c
+++ b/osdep/terminal-win.c
@@ -106,6 +106,10 @@ void terminal_get_size(int *w, int *h)
}
}
+void terminal_get_size2(int *rows, int *cols, int *px_width, int *px_height)
+{
+}
+
static bool has_input_events(HANDLE h)
{
DWORD num_events;
diff --git a/osdep/terminal.h b/osdep/terminal.h
index ccf6a02c7c..db1e2a4dd2 100644
--- a/osdep/terminal.h
+++ b/osdep/terminal.h
@@ -40,6 +40,9 @@ bool terminal_in_background(void);
/* Get terminal-size in columns/rows. */
void terminal_get_size(int *w, int *h);
+/* Get terminal-size in columns/rows and width/height in pixels. */
+void terminal_get_size2(int *rows, int *cols, int *px_width, int *px_height);
+
// Windows only.
void mp_write_console_ansi(void *wstream, char *buf);