From 048c68e5c22c6e2db54f228c6af7acfacad2d880 Mon Sep 17 00:00:00 2001 From: Alexander Preisinger Date: Wed, 1 May 2013 13:34:59 +0200 Subject: wayland: use mpv internal key auto-repeat handling This removes a good chunk of code trying to recreate key repeat. Because the wayland protocol and xkbcommon don't have an interface for auto-repeating pressed keys. --- video/out/wayland_common.c | 58 ++++------------------------------------------ video/out/wayland_common.h | 8 ------- 2 files changed, 5 insertions(+), 61 deletions(-) (limited to 'video') diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index b1f08fce4d..3c81f829b9 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -290,8 +290,7 @@ static void keyboard_handle_key(void *data, struct vo_wayland_state *wl = data; struct vo_wayland_input *input = wl->input; uint32_t code, num_syms; - - struct itimerspec its = {{0, 0}, {0, 0}}; + int mpkey; const xkb_keysym_t *syms; xkb_keysym_t sym; @@ -315,35 +314,12 @@ static void keyboard_handle_key(void *data, if (num_syms == 1) sym = syms[0]; - if (sym != XKB_KEY_NoSymbol && state == WL_KEYBOARD_KEY_STATE_PRESSED) { - int mpkey = lookupkey(sym); - if (mpkey) + if (sym != XKB_KEY_NoSymbol && (mpkey = lookupkey(sym))) { + if (state == WL_KEYBOARD_KEY_STATE_PRESSED) + mplayer_put_key(wl->vo->key_fifo, mpkey | MP_KEY_STATE_DOWN); + else mplayer_put_key(wl->vo->key_fifo, mpkey); } - - if (state == WL_KEYBOARD_KEY_STATE_RELEASED && key == input->repeat.key) { - input->repeat.sym = 0; - input->repeat.key = 0; - input->repeat.time = 0; - } - else if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { - if (input->repeat.key == key) { - its.it_interval.tv_sec = 0; - its.it_interval.tv_nsec = 20 * 1000 * 1000; - its.it_value.tv_sec = 0; - its.it_value.tv_nsec = 100 * 1000 * 1000; - } - else { - input->repeat.sym = sym; - input->repeat.key = key; - input->repeat.time = time; - its.it_interval.tv_sec = 0; - its.it_interval.tv_nsec = 25 * 1000 * 1000; - its.it_value.tv_sec = 0; - its.it_value.tv_nsec = 400 * 1000 * 1000; - } - } - timerfd_settime(input->repeat.timer_fd, 0, &its, NULL); } static void keyboard_handle_modifiers(void *data, @@ -713,23 +689,6 @@ static void cursor_timer_func(struct vo_wayland_task *task, hide_cursor(wl); } -static void keyboard_timer_func(struct vo_wayland_task *task, - uint32_t events, - struct vo_wayland_state *wl) -{ - struct vo_wayland_input *input = wl->input; - uint64_t exp; - - if (read(input->repeat.timer_fd, &exp, sizeof exp) != sizeof exp) - /* If we change the timer between the fd becoming - * readable and getting here, there'll be nothing to - * read and we get EAGAIN. */ - return; - - keyboard_handle_key(wl, input->keyboard, 0, input->repeat.time, - input->repeat.key, WL_KEYBOARD_KEY_STATE_PRESSED); -} - static bool create_display (struct vo_wayland_state *wl) { struct vo_wayland_display *d = wl->display; @@ -842,22 +801,15 @@ static void destroy_input (struct vo_wayland_state *wl) static void create_timers (struct vo_wayland_state *wl) { struct vo_wayland_display *d = wl->display; - struct vo_wayland_input *i = wl->input; d->cursor.task.run = cursor_timer_func; d->cursor.timer_fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK); display_watch_fd(d, d->cursor.timer_fd, EPOLLIN, &d->cursor.task); - - i->repeat.task.run = keyboard_timer_func; - i->repeat.timer_fd = timerfd_create(CLOCK_MONOTONIC, - TFD_CLOEXEC | TFD_NONBLOCK); - display_watch_fd(d, i->repeat.timer_fd, EPOLLIN, &i->repeat.task); } static void destroy_timers (struct vo_wayland_state *wl) { - close(wl->input->repeat.timer_fd); close(wl->display->cursor.timer_fd); } diff --git a/video/out/wayland_common.h b/video/out/wayland_common.h index abcaa8be2f..20d3853fcf 100644 --- a/video/out/wayland_common.h +++ b/video/out/wayland_common.h @@ -121,14 +121,6 @@ struct vo_wayland_input { } xkb; int modifiers; - - struct { - uint32_t sym; - uint32_t key; - uint32_t time; - int timer_fd; - struct vo_wayland_task task; - } repeat; }; struct vo_wayland_state { -- cgit v1.2.3