diff options
author | wm4 <wm4@nowhere> | 2013-12-21 19:33:45 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-12-21 20:50:13 +0100 |
commit | ed71606e65e697ea6bc9fc78caf2dd4089dc0aeb (patch) | |
tree | d3b80546a8e40c821ee7575c236d813021b8b7c8 /osdep/terminal-unix.c | |
parent | dadf3a9a46d31a101aeaa1256b0d6f914eb32f1e (diff) | |
download | mpv-ed71606e65e697ea6bc9fc78caf2dd4089dc0aeb.tar.bz2 mpv-ed71606e65e697ea6bc9fc78caf2dd4089dc0aeb.tar.xz |
input: rework how input sources are added
Until now, there were two functions to add input sources (stuff like
stdin input, slave mode, lirc, joystick). Unify them to a single
function (mp_input_add_fd()), and make sure the associated callbacks
always have a context parameter.
Change the lirc and joystick code such that they take store their state
in a context struct (probably worthless), and use the new mp_msg
replacements (the point of this refactoring).
Additionally, get rid of the ugly USE_FD0_CMD_SELECT etc. ifdeffery in
the terminal handling code.
Diffstat (limited to 'osdep/terminal-unix.c')
-rw-r--r-- | osdep/terminal-unix.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/osdep/terminal-unix.c b/osdep/terminal-unix.c index f61cb5e367..03f2360916 100644 --- a/osdep/terminal-unix.c +++ b/osdep/terminal-unix.c @@ -358,7 +358,7 @@ static void walk_buf(unsigned int count) { getch2_pos = 0; } -bool getch2(struct input_ctx *input_ctx) +static bool getch2(struct input_ctx *input_ctx) { int retval = read(0, &getch2_buf[getch2_pos], BUF_LEN - getch2_len - getch2_pos); /* Return false on EOF to stop running select() on the FD, as it'd @@ -437,6 +437,18 @@ bool getch2(struct input_ctx *input_ctx) return true; } +static int read_keys(void *ctx, int fd) +{ + if (getch2(ctx)) + return MP_INPUT_NOTHING; + return MP_INPUT_DEAD; +} + +void terminal_setup_getch(struct input_ctx *ictx) +{ + mp_input_add_fd(ictx, 0, 1, NULL, read_keys, NULL, ictx); +} + static volatile int getch2_active = 0; static volatile int getch2_enabled = 0; @@ -593,6 +605,11 @@ void terminal_set_foreground_color(FILE *stream, int c) } } +void terminal_setup_stdin_cmd_input(struct input_ctx *ictx) +{ + mp_input_add_fd(ictx, 0, 1, input_default_read_cmd, NULL, NULL, NULL); +} + int terminal_init(void) { load_termcap(NULL); |