diff options
Diffstat (limited to 'input')
-rw-r--r-- | input/ar.c | 4 | ||||
-rw-r--r-- | input/ar.h | 2 | ||||
-rw-r--r-- | input/input.c | 51 | ||||
-rw-r--r-- | input/input.h | 8 | ||||
-rw-r--r-- | input/joystick.c | 2 | ||||
-rw-r--r-- | input/joystick.h | 2 |
6 files changed, 15 insertions, 54 deletions
diff --git a/input/ar.c b/input/ar.c index 7347b4c326..0f48a50716 100644 --- a/input/ar.c +++ b/input/ar.c @@ -321,7 +321,7 @@ int is_mplayer_front() return 0; } -int mp_input_ar_read(int fd) +int mp_input_ar_read(void *ctx, int fd) { int i, down = 0; int ret = MP_INPUT_NOTHING; @@ -445,7 +445,7 @@ int main(void) } while (1) { - switch ((ret = mp_input_ar_read(0)) & ~MP_KEY_DOWN) { + switch ((ret = mp_input_ar_read(NULL, 0)) & ~MP_KEY_DOWN) { case AR_PLAY: printf(" - AR_PLAY."); break; case AR_PLAY_HOLD: printf(" - AR_PLAY_HOLD."); break; case AR_NEXT: printf(" - AR_NEXT."); break; diff --git a/input/ar.h b/input/ar.h index 836ba089d1..ae763acdad 100644 --- a/input/ar.h +++ b/input/ar.h @@ -36,7 +36,7 @@ #define AR_VDOWN (AR_BASE + 9) int mp_input_ar_init(void); -int mp_input_ar_read(int fd); +int mp_input_ar_read(void *ctx, int fd); void mp_input_ar_close(int fd); #endif /* MPLAYER_AR_H */ diff --git a/input/input.c b/input/input.c index 5d11f71ed4..e539358a33 100644 --- a/input/input.c +++ b/input/input.c @@ -512,7 +512,6 @@ typedef struct mp_input_fd { 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; @@ -669,7 +668,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; @@ -683,41 +684,14 @@ mp_input_add_key_fd(int fd, int select, mp_key_func_t read_func, mp_close_func_t .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 *ctx), void *ctx) -{ - 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; - } - - key_fds[num_key_fd] = (struct mp_input_fd){ - .fd = fd, - .read_func = read_func, + .no_select = !select, .ctx = ctx, - .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; @@ -1226,17 +1200,8 @@ static mp_cmd_t *read_events(int time, int paused) continue; #endif - int code; - if (key_fds[i].no_readfunc_retval) { // getch2 handler special-cased for now - ((void (*)(void *))key_fds[i].read_func)(key_fds[i].ctx); - 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 = ((mp_key_func_t)key_fds[i].read_func)(key_fds[i].ctx, + key_fds[i].fd); if (code >= 0) { mp_cmd_t *ret = interpret_key(code, paused); if (ret) @@ -1730,7 +1695,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 @@ -1755,7 +1720,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 diff --git a/input/input.h b/input/input.h index 27c1bdb83f..4ee0376993 100644 --- a/input/input.h +++ b/input/input.h @@ -206,7 +206,7 @@ typedef struct mp_key_name { // the next key code or command. // These functions should return the key code or one of the error codes -typedef int (*mp_key_func_t)(int fd); +typedef int (*mp_key_func_t)(void *ctx, int fd); // These functions should act like read but they must use our error code (if needed ;-) typedef int (*mp_cmd_func_t)(int fd,char* dest,int size); // These are used to close the driver @@ -234,16 +234,12 @@ mp_input_rm_cmd_fd(int fd); // The args are the same as for the key's drivers. If you don't use any valid fd you MUST // give a read_func. 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); // As for the cmd one you usually don't need this function. void mp_input_rm_key_fd(int fd); -int mp_input_add_event_fd(int fd, void (*read_func)(void *ctx), void *ctx); - -void mp_input_rm_event_fd(int fd); - /// Get input key from its name. int mp_input_get_key_from_name(const char *name); diff --git a/input/joystick.c b/input/joystick.c index ec3720548d..02e00d207f 100644 --- a/input/joystick.c +++ b/input/joystick.c @@ -73,7 +73,7 @@ int mp_input_joystick_init(char* dev) { return fd; } -int mp_input_joystick_read(int fd) { +int mp_input_joystick_read(void *ctx, int fd) { struct js_event ev; int l=0; diff --git a/input/joystick.h b/input/joystick.h index 3a70f7cbd3..b318e9ec14 100644 --- a/input/joystick.h +++ b/input/joystick.h @@ -37,6 +37,6 @@ int mp_input_joystick_init(char* dev); -int mp_input_joystick_read(int fd); +int mp_input_joystick_read(void *ctx, int fd); #endif /* MPLAYER_JOYSTICK_H */ |