summaryrefslogtreecommitdiffstats
path: root/player/command.c
diff options
context:
space:
mode:
authorChristoph Heinrich <christoph.heinrich@student.tugraz.at>2023-08-31 22:51:15 +0200
committerKacper Michajłow <kasper93@gmail.com>2024-03-21 03:08:52 +0100
commit0c8f3bc73ca3edf1970dd68aa5e085064968bdfd (patch)
treef2584e2750a2c97ae95c0054e8f6878be44c3836 /player/command.c
parent0230a0c25a767f7d285efc2e26d068d4110a0eb3 (diff)
downloadmpv-0c8f3bc73ca3edf1970dd68aa5e085064968bdfd.tar.bz2
mpv-0c8f3bc73ca3edf1970dd68aa5e085064968bdfd.tar.xz
player/command: add term-size/[w,h] property
There was no way for scripts to know the current size of the terminal, which is essintial if they want to provide a good user experience even without a window.
Diffstat (limited to 'player/command.c')
-rw-r--r--player/command.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/player/command.c b/player/command.c
index 82801131a8..27fadf91b1 100644
--- a/player/command.c
+++ b/player/command.c
@@ -74,6 +74,7 @@
#include "osdep/io.h"
#include "osdep/subprocess.h"
+#include "osdep/terminal.h"
#include "core.h"
@@ -2886,6 +2887,23 @@ static int mp_property_osd_ass(void *ctx, struct m_property *prop,
return m_property_read_sub(props, action, arg);
}
+static int mp_property_term_size(void *ctx, struct m_property *prop,
+ int action, void *arg)
+{
+ int w = -1, h = -1;
+ terminal_get_size(&w, &h);
+ if (w == -1 || h == -1)
+ return M_PROPERTY_UNAVAILABLE;
+
+ struct m_sub_property props[] = {
+ {"w", SUB_PROP_INT(w)},
+ {"h", SUB_PROP_INT(h)},
+ {0}
+ };
+
+ return m_property_read_sub(props, action, arg);
+}
+
static int mp_property_mouse_pos(void *ctx, struct m_property *prop,
int action, void *arg)
{
@@ -4092,6 +4110,7 @@ static const struct m_property mp_properties_base[] = {
{"input-bindings", mp_property_bindings},
{"user-data", mp_property_udata},
+ {"term-size", mp_property_term_size},
M_PROPERTY_ALIAS("video", "vid"),
M_PROPERTY_ALIAS("audio", "aid"),