History

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.

Christoph Heinrich committed 3 years ago

Commit 0c8f3bc1 parent 0230a0c3 files · +33 −0Browse files

Unified · Split

3 files
  1. DOCS/interface-changes/term-size.txt +1 −0
  2. DOCS/man/input.rst +13 −0
  3. player/command.c +19 −0
DOCS/interface-changes/term-size.txt+1−0
@@ -0,0 +1 @@
1add `term-size` property
DOCS/man/input.rst+13−0
@@ -2804,6 +2804,19 @@ Property list · 2803 unmodified lines
2804 Any of these properties may be unavailable or set to dummy values if the2804 Any of these properties may be unavailable or set to dummy values if the
2805 VO window is not created or visible.2805 VO window is not created or visible.
2806 2806
2807``term-size``
2808 The current terminal size.
2809
2810 This has two sub-properties.
2811
2812 ``term-size/w``
2813 width of the terminal in cells
2814 ``term-size/h``
2815 height of the terminal in cells
2816
2817 This property is not observable. Reacting to size changes requires
2818 polling.
2819
2807``window-id``2820``window-id``
2808 Read-only - mpv's window id. May not always be available, i.e due to window2821 Read-only - mpv's window id. May not always be available, i.e due to window
2809 not being opened yet or not being supported by the VO.2822 not being opened yet or not being supported by the VO.
player/command.c+19−0
@@ -74,6 +74,7 @@ · 73 unmodified lines
74 74
75#include "osdep/io.h"75#include "osdep/io.h"
76#include "osdep/subprocess.h"76#include "osdep/subprocess.h"
77#include "osdep/terminal.h"
77 78
78#include "core.h"79#include "core.h"
79 80
@@ -2886,6 +2887,23 @@ static int mp_property_osd_ass(void *ctx, struct m_property *prop, · 2806 unmodified lines
2886 return m_property_read_sub(props, action, arg);2887 return m_property_read_sub(props, action, arg);
2887}2888}
2888 2889
2890static int mp_property_term_size(void *ctx, struct m_property *prop,
2891 int action, void *arg)
2892{
2893 int w = -1, h = -1;
2894 terminal_get_size(&w, &h);
2895 if (w == -1 || h == -1)
2896 return M_PROPERTY_UNAVAILABLE;
2897
2898 struct m_sub_property props[] = {
2899 {"w", SUB_PROP_INT(w)},
2900 {"h", SUB_PROP_INT(h)},
2901 {0}
2902 };
2903
2904 return m_property_read_sub(props, action, arg);
2905}
2906
2889static int mp_property_mouse_pos(void *ctx, struct m_property *prop,2907static int mp_property_mouse_pos(void *ctx, struct m_property *prop,
2890 int action, void *arg)2908 int action, void *arg)
2891{2909{
@@ -4092,6 +4110,7 @@ static const struct m_property mp_properties_base[] = { · 1200 unmodified lines
4092 {"input-bindings", mp_property_bindings},4110 {"input-bindings", mp_property_bindings},
4093 4111
4094 {"user-data", mp_property_udata},4112 {"user-data", mp_property_udata},
4113 {"term-size", mp_property_term_size},
4095 4114
4096 M_PROPERTY_ALIAS("video", "vid"),4115 M_PROPERTY_ALIAS("video", "vid"),
4097 M_PROPERTY_ALIAS("audio", "aid"),4116 M_PROPERTY_ALIAS("audio", "aid"),

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t