diff options
Diffstat (limited to 'input')
-rw-r--r-- | input/input.c | 42 | ||||
-rw-r--r-- | input/input.h | 2 |
2 files changed, 24 insertions, 20 deletions
diff --git a/input/input.c b/input/input.c index 5d6cc08ed8..74312bbb7f 100644 --- a/input/input.c +++ b/input/input.c @@ -507,6 +507,7 @@ typedef struct mp_input_fd { int fd; void* read_func; mp_close_func_t close_func; + void *ctx; unsigned eof : 1; unsigned drop : 1; unsigned dead : 1; @@ -577,7 +578,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 +589,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 +620,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 = read_func ? read_func : mp_input_default_cmd_func, + .close_func = close_func, + .no_select = !select + }; num_cmd_fd++; return 1; @@ -678,18 +680,19 @@ 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 = read_func, + .close_func = close_func, + .no_select = !select + }; num_key_fd++; return 1; } int -mp_input_add_event_fd(int fd, void (*read_func)(void)) +mp_input_add_event_fd(int fd, void (*read_func)(void *ctx), void *ctx) { if(num_key_fd == MP_MAX_KEY_FD) { mp_msg(MSGT_INPUT,MSGL_ERR,MSGTR_INPUT_INPUT_ErrCantRegister2ManyKeyFds,fd); @@ -700,11 +703,12 @@ mp_input_add_event_fd(int fd, void (*read_func)(void)) 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; + key_fds[num_key_fd] = (struct mp_input_fd){ + .fd = fd, + .read_func = read_func, + .ctx = ctx, + .no_readfunc_retval = 1, + }; num_key_fd++; return 1; @@ -1228,7 +1232,7 @@ static mp_cmd_t *read_events(int time, int paused) #endif if (key_fds[i].no_readfunc_retval) { // getch2 handler special-cased for now - ((void (*)(void))key_fds[i].read_func)(); + ((void (*)(void *))key_fds[i].read_func)(key_fds[i].ctx); if (cmd_queue_length) return NULL; code = mplayer_get_key(0); diff --git a/input/input.h b/input/input.h index e6381b3e34..27c1bdb83f 100644 --- a/input/input.h +++ b/input/input.h @@ -240,7 +240,7 @@ mp_input_add_key_fd(int fd, int select, mp_key_func_t read_func, mp_close_func_t void mp_input_rm_key_fd(int fd); -int mp_input_add_event_fd(int fd, void (*read_func)(void)); +int mp_input_add_event_fd(int fd, void (*read_func)(void *ctx), void *ctx); void mp_input_rm_event_fd(int fd); |