summaryrefslogtreecommitdiffstats
path: root/input/input.h
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-12-21 19:33:45 +0100
committerwm4 <wm4@nowhere>2013-12-21 20:50:13 +0100
commited71606e65e697ea6bc9fc78caf2dd4089dc0aeb (patch)
treed3b80546a8e40c821ee7575c236d813021b8b7c8 /input/input.h
parentdadf3a9a46d31a101aeaa1256b0d6f914eb32f1e (diff)
downloadmpv-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 'input/input.h')
-rw-r--r--input/input.h25
1 files changed, 13 insertions, 12 deletions
diff --git a/input/input.h b/input/input.h
index 62892dc15a..3a1d3f6116 100644
--- a/input/input.h
+++ b/input/input.h
@@ -171,25 +171,26 @@ typedef struct mp_cmd {
bool mp_input_is_abort_cmd(int cmd_id);
/* Add a new command input source.
- * "fd" is a file descriptor (use a negative value if you don't use any fd)
+ * "fd" is a file descriptor (use -1 if you don't use any fd)
* "select" tells whether to use select() on the fd to determine when to
* try reading.
- * "read_func" is optional. If NULL a default function which reads data
- * directly from the fd will be used. It must return either text data
- * or one of the MP_INPUT error codes above.
+ * "read_cmd_func" is optional. It must return either text data or one of the
+ * MP_INPUT error codes above. For return values >= 0, it behaves like UNIX
+ * read() and returns the number of bytes copied to the dest buffer.
+ * "read_key_func" is optional. It returns either key codes (ASCII, keycodes.h),
+ * or MP_INPUT error codes.
* "close_func" will be called when closing. Can be NULL. Its return value
* is ignored (it's only there to allow using standard close() as the func).
+ * "ctx" is for free use, and is passed to the callbacks.
*/
-int mp_input_add_cmd_fd(struct input_ctx *ictx, int fd, int select,
- int read_func(int fd, char *dest, int size),
- int close_func(int fd));
+int mp_input_add_fd(struct input_ctx *ictx, int fd, int select,
+ int read_cmd_func(void *ctx, int fd, char *dest, int size),
+ int read_key_func(void *ctx, int fd),
+ int close_func(void *ctx, int fd), void *ctx);
-/* The args are similar to the cmd version above, except you must give
- * a read_func, and it should return key codes (ASCII plus keycodes.h).
+/* Can be passed as read_func for above function in order to read() from the FD.
*/
-int mp_input_add_key_fd(struct input_ctx *ictx, int fd, int select,
- int read_func(void *ctx, int fd),
- int close_func(int fd), void *ctx);
+int input_default_read_cmd(void *ctx, int fd, char *buf, int l);
// Process keyboard input. code is a key code from keycodes.h, possibly
// with modifiers applied. MP_INPUT_RELEASE_ALL is also a valid value.