summaryrefslogtreecommitdiffstats
path: root/input/input.c
diff options
context:
space:
mode:
Diffstat (limited to 'input/input.c')
-rw-r--r--input/input.c97
1 files changed, 32 insertions, 65 deletions
diff --git a/input/input.c b/input/input.c
index 5d6cc08ed8..c8218c7b00 100644
--- a/input/input.c
+++ b/input/input.c
@@ -17,7 +17,6 @@
#include <assert.h>
#endif
#include "mp_fifo.h"
-#include "osdep/getch2.h"
#include "osdep/keycodes.h"
#include "osdep/timer.h"
#include "libavutil/avstring.h"
@@ -505,14 +504,17 @@ static const mp_cmd_bind_t gui_def_cmd_binds[] = {
typedef struct mp_input_fd {
int fd;
- void* read_func;
+ union {
+ mp_key_func_t key;
+ mp_cmd_func_t cmd;
+ } read_func;
mp_close_func_t close_func;
+ void *ctx;
unsigned eof : 1;
unsigned drop : 1;
unsigned dead : 1;
unsigned got_cmd : 1;
unsigned no_select : 1;
- unsigned no_readfunc_retval : 1;
// These fields are for the cmd fds.
char* buffer;
int pos,size;
@@ -577,7 +579,7 @@ static int mp_input_print_key_list(m_option_t* cfg);
static int mp_input_print_cmd_list(m_option_t* cfg);
// Our command line options
-static m_option_t input_conf[] = {
+static const m_option_t input_conf[] = {
{ "conf", &config_file, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL },
{ "ar-delay", &ar_delay, CONF_TYPE_INT, CONF_GLOBAL, 0, 0, NULL },
{ "ar-rate", &ar_rate, CONF_TYPE_INT, CONF_GLOBAL, 0, 0, NULL },
@@ -588,7 +590,7 @@ static m_option_t input_conf[] = {
{ NULL, NULL, 0, 0, 0, 0, NULL}
};
-static m_option_t mp_input_opts[] = {
+static const m_option_t mp_input_opts[] = {
{ "input", &input_conf, CONF_TYPE_SUBCONFIG, 0, 0, 0, NULL},
{ "nojoystick", &use_joystick, CONF_TYPE_FLAG, CONF_GLOBAL, 1, 0, NULL },
{ "joystick", &use_joystick, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL },
@@ -619,11 +621,12 @@ mp_input_add_cmd_fd(int fd, int select, mp_cmd_func_t read_func, mp_close_func_t
return 0;
}
- memset(&cmd_fds[num_cmd_fd],0,sizeof(mp_input_fd_t));
- cmd_fds[num_cmd_fd].fd = fd;
- cmd_fds[num_cmd_fd].read_func = read_func ? read_func : mp_input_default_cmd_func;
- cmd_fds[num_cmd_fd].close_func = close_func;
- cmd_fds[num_cmd_fd].no_select = !select;
+ cmd_fds[num_cmd_fd] = (struct mp_input_fd){
+ .fd = fd,
+ .read_func.cmd = read_func ? read_func : mp_input_default_cmd_func,
+ .close_func = close_func,
+ .no_select = !select
+ };
num_cmd_fd++;
return 1;
@@ -668,7 +671,9 @@ mp_input_rm_key_fd(int fd) {
}
int
-mp_input_add_key_fd(int fd, int select, mp_key_func_t read_func, mp_close_func_t close_func) {
+mp_input_add_key_fd(int fd, int select, mp_key_func_t read_func,
+ mp_close_func_t close_func, void *ctx)
+{
if(num_key_fd == MP_MAX_KEY_FD) {
mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrCantRegister2ManyKeyFds,fd);
return 0;
@@ -678,43 +683,18 @@ mp_input_add_key_fd(int fd, int select, mp_key_func_t read_func, mp_close_func_t
return 0;
}
- memset(&key_fds[num_key_fd],0,sizeof(mp_input_fd_t));
- key_fds[num_key_fd].fd = fd;
- key_fds[num_key_fd].read_func = read_func;
- key_fds[num_key_fd].close_func = close_func;
- key_fds[num_key_fd].no_select = !select;
+ key_fds[num_key_fd] = (struct mp_input_fd){
+ .fd = fd,
+ .read_func.key = read_func,
+ .close_func = close_func,
+ .no_select = !select,
+ .ctx = ctx,
+ };
num_key_fd++;
return 1;
}
-int
-mp_input_add_event_fd(int fd, void (*read_func)(void))
-{
- if(num_key_fd == MP_MAX_KEY_FD) {
- mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrCantRegister2ManyKeyFds,fd);
- return 0;
- }
- if (fd < 0) {
- mp_msg(MSGT_INPUT, MSGL_ERR, "Invalid fd %i in mp_input_add_event_fd", fd);
- return 0;
- }
-
- memset(&key_fds[num_key_fd],0,sizeof(mp_input_fd_t));
- key_fds[num_key_fd].fd = fd;
- key_fds[num_key_fd].read_func = read_func;
- key_fds[num_key_fd].close_func = NULL;
- key_fds[num_key_fd].no_readfunc_retval = 1;
- num_key_fd++;
-
- return 1;
-}
-
-void mp_input_rm_event_fd(int fd)
-{
- mp_input_rm_key_fd(fd);
-}
-
int mp_input_parse_and_queue_cmds(const char *str) {
int cmd_num = 0;
@@ -893,7 +873,8 @@ mp_input_read_cmd(mp_input_fd_t* mp_fd, char** ret) {
// Get some data if needed/possible
while (!mp_fd->got_cmd && !mp_fd->eof && (mp_fd->size - mp_fd->pos > 1) ) {
- int r = ((mp_cmd_func_t)mp_fd->read_func)(mp_fd->fd,mp_fd->buffer+mp_fd->pos,mp_fd->size - 1 - mp_fd->pos);
+ int r = mp_fd->read_func.cmd(mp_fd->fd, mp_fd->buffer+mp_fd->pos,
+ mp_fd->size - 1 - mp_fd->pos);
// Error ?
if(r < 0) {
switch(r) {
@@ -1161,10 +1142,6 @@ static mp_cmd_t *read_events(int time, int paused)
{
int i;
int got_cmd = 0;
- mp_cmd_t *autorepeat_cmd;
-#ifdef HAVE_POSIX_SELECT
- fd_set fds;
-#endif
for (i = 0; i < num_key_fd; i++)
if (key_fds[i].dead) {
mp_input_rm_key_fd(key_fds[i].fd);
@@ -1178,6 +1155,7 @@ static mp_cmd_t *read_events(int time, int paused)
else if (cmd_fds[i].got_cmd)
got_cmd = 1;
#ifdef HAVE_POSIX_SELECT
+ fd_set fds;
FD_ZERO(&fds);
if (!got_cmd) {
int max_fd = 0, num_fd = 0;
@@ -1221,22 +1199,12 @@ static mp_cmd_t *read_events(int time, int paused)
for (i = 0; i < num_key_fd; i++) {
- int code;
#ifdef HAVE_POSIX_SELECT
if (!key_fds[i].no_select && !FD_ISSET(key_fds[i].fd, &fds))
continue;
#endif
- if (key_fds[i].no_readfunc_retval) { // getch2 handler special-cased for now
- ((void (*)(void))key_fds[i].read_func)();
- if (cmd_queue_length)
- return NULL;
- code = mplayer_get_key(0);
- if (code < 0)
- code = MP_INPUT_NOTHING;
- }
- else
- code = ((mp_key_func_t)key_fds[i].read_func)(key_fds[i].fd);
+ int code = key_fds[i].read_func.key(key_fds[i].ctx, key_fds[i].fd);
if (code >= 0) {
mp_cmd_t *ret = interpret_key(code, paused);
if (ret)
@@ -1251,19 +1219,18 @@ static mp_cmd_t *read_events(int time, int paused)
key_fds[i].dead = 1;
}
}
- autorepeat_cmd = check_autorepeat(paused);
+ mp_cmd_t *autorepeat_cmd = check_autorepeat(paused);
if (autorepeat_cmd)
return autorepeat_cmd;
for (i = 0; i < num_cmd_fd; i++) {
- char *cmd;
- int r;
#ifdef HAVE_POSIX_SELECT
if (!cmd_fds[i].no_select && !FD_ISSET(cmd_fds[i].fd, &fds) &&
!cmd_fds[i].got_cmd)
continue;
#endif
- r = mp_input_read_cmd(&cmd_fds[i], &cmd);
+ char *cmd;
+ int r = mp_input_read_cmd(&cmd_fds[i], &cmd);
if (r >= 0) {
mp_cmd_t *ret = mp_input_parse_cmd(cmd);
free(cmd);
@@ -1731,7 +1698,7 @@ mp_input_init(int use_gui) {
if(fd < 0)
mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrCantInitJoystick);
else
- mp_input_add_key_fd(fd,1,mp_input_joystick_read,(mp_close_func_t)close);
+ mp_input_add_key_fd(fd,1,mp_input_joystick_read,(mp_close_func_t)close,NULL);
}
#endif
@@ -1756,7 +1723,7 @@ mp_input_init(int use_gui) {
if(mp_input_ar_init() < 0)
mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrCantInitAppleRemote);
else
- mp_input_add_key_fd(-1,0,mp_input_ar_read,mp_input_ar_close);
+ mp_input_add_key_fd(-1,0,mp_input_ar_read,mp_input_ar_close, NULL);
}
#endif