From c4766dc3c6233d3353b79fbd226202e7b8e3fc46 Mon Sep 17 00:00:00 2001 From: wm4 Date: Mon, 1 Jul 2013 23:54:59 +0200 Subject: input: require VOs to send key up events, redo input key lookup Making key up events implicit was sort-of a nice idea, but it's too tricky and unreliable and makes the key lookup code (interpret_keys()) hard to reason about. See e.g. previous commit for subtle bugs and issues this caused. Make key-up events explicit instead. Add key up events to all VOs. Any time MP_KEY_STATE_DOWN is used, the matching key up event must use MP_KEY_STATE_UP. Rewrite the key lookup code. It should be simpler and more robust now. (Even though the LOC increases, because the new code is less "compact".) --- video/out/cocoa_common.m | 4 ++-- video/out/vo_caca.c | 2 +- video/out/vo_sdl.c | 2 +- video/out/w32_common.c | 7 ++++--- video/out/wayland_common.c | 7 ++++--- video/out/x11_common.c | 3 ++- 6 files changed, 14 insertions(+), 11 deletions(-) (limited to 'video') diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m index 84d8e29b86..dd166e03e1 100644 --- a/video/out/cocoa_common.m +++ b/video/out/cocoa_common.m @@ -893,14 +893,14 @@ int vo_cocoa_cgl_color_size(struct vo *vo) // doing the second click in a double click. Put in the key_fifo // the key that would be put from the MouseUp handling code. if([theEvent clickCount] == 2) { - cocoa_put_key(MP_MOUSE_BTN0 + buttonNumber); + cocoa_put_key((MP_MOUSE_BTN0 + buttonNumber) | MP_KEY_STATE_UP); self.mouseDown = NO; } break; case NSLeftMouseUp: case NSRightMouseUp: case NSOtherMouseUp: - cocoa_put_key(MP_MOUSE_BTN0 + buttonNumber); + cocoa_put_key((MP_MOUSE_BTN0 + buttonNumber) | MP_KEY_STATE_UP); self.mouseDown = NO; break; } diff --git a/video/out/vo_caca.c b/video/out/vo_caca.c index fcb0bc4322..78eaf2b395 100644 --- a/video/out/vo_caca.c +++ b/video/out/vo_caca.c @@ -182,7 +182,7 @@ static void check_events(struct vo *vo) case CACA_EVENT_MOUSE_RELEASE: if (!vo->opts->nomouse_input) mplayer_put_key(vo->key_fifo, - MP_MOUSE_BTN0 + cev.data.mouse.button - 1); + (MP_MOUSE_BTN0 + cev.data.mouse.button - 1) | MP_KEY_STATE_UP); break; case CACA_EVENT_KEY_PRESS: { diff --git a/video/out/vo_sdl.c b/video/out/vo_sdl.c index 66013e01f2..dd1e4a5053 100644 --- a/video/out/vo_sdl.c +++ b/video/out/vo_sdl.c @@ -541,7 +541,7 @@ static void check_events(struct vo *vo) break; case SDL_MOUSEBUTTONUP: mplayer_put_key(vo->key_fifo, - (MP_MOUSE_BTN0 + ev.button.button - 1)); + (MP_MOUSE_BTN0 + ev.button.button - 1) | MP_KEY_STATE_UP); break; case SDL_MOUSEWHEEL: break; diff --git a/video/out/w32_common.c b/video/out/w32_common.c index 77433db885..13ec8e7053 100644 --- a/video/out/w32_common.c +++ b/video/out/w32_common.c @@ -225,19 +225,19 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, mouse_button = MP_MOUSE_BTN0 | MP_KEY_STATE_DOWN; break; case WM_LBUTTONUP: - mouse_button = MP_MOUSE_BTN0; + mouse_button = MP_MOUSE_BTN0 | MP_KEY_STATE_UP; break; case WM_MBUTTONDOWN: mouse_button = MP_MOUSE_BTN1 | MP_KEY_STATE_DOWN; break; case WM_MBUTTONUP: - mouse_button = MP_MOUSE_BTN1; + mouse_button = MP_MOUSE_BTN1 | MP_KEY_STATE_UP; break; case WM_RBUTTONDOWN: mouse_button = MP_MOUSE_BTN2 | MP_KEY_STATE_DOWN; break; case WM_RBUTTONUP: - mouse_button = MP_MOUSE_BTN2; + mouse_button = MP_MOUSE_BTN2 | MP_KEY_STATE_UP; break; case WM_MOUSEWHEEL: { int x = GET_WHEEL_DELTA_WPARAM(wParam); @@ -250,6 +250,7 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, break; case WM_XBUTTONUP: mouse_button = HIWORD(wParam) == 1 ? MP_MOUSE_BTN5 : MP_MOUSE_BTN6; + mouse_button |= MP_KEY_STATE_UP; break; } diff --git a/video/out/wayland_common.c b/video/out/wayland_common.c index a627100477..f3d18efc1d 100644 --- a/video/out/wayland_common.c +++ b/video/out/wayland_common.c @@ -278,7 +278,7 @@ static void keyboard_handle_key(void *data, 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); + mplayer_put_key(wl->vo->key_fifo, mpkey | MP_KEY_STATE_UP); } } @@ -320,7 +320,7 @@ static void pointer_handle_enter(void *data, /* Release the left button on pointer enter again * because after moving the shell surface no release event is sent */ - mplayer_put_key(wl->vo->key_fifo, MP_MOUSE_BTN0); + mplayer_put_key(wl->vo->key_fifo, MP_MOUSE_BTN0 | MP_KEY_STATE_UP); show_cursor(wl); } @@ -355,7 +355,8 @@ static void pointer_handle_button(void *data, struct vo_wayland_state *wl = data; mplayer_put_key(wl->vo->key_fifo, MP_MOUSE_BTN0 + (button - BTN_LEFT) | - ((state == WL_POINTER_BUTTON_STATE_PRESSED) ? MP_KEY_STATE_DOWN : 0)); + ((state == WL_POINTER_BUTTON_STATE_PRESSED) + ? MP_KEY_STATE_DOWN : MP_KEY_STATE_UP)); if ((button == BTN_LEFT) && (state == WL_POINTER_BUTTON_STATE_PRESSED)) wl_shell_surface_move(wl->window->shell_surface, wl->input->seat, serial); diff --git a/video/out/x11_common.c b/video/out/x11_common.c index bbb6fca997..648f1d57eb 100644 --- a/video/out/x11_common.c +++ b/video/out/x11_common.c @@ -766,7 +766,8 @@ int vo_x11_check_events(struct vo *vo) break; case ButtonRelease: mplayer_put_key(vo->key_fifo, - MP_MOUSE_BTN0 + Event.xbutton.button - 1); + (MP_MOUSE_BTN0 + Event.xbutton.button - 1) + | MP_KEY_STATE_UP); break; case PropertyNotify: { char *name = XGetAtomName(display, Event.xproperty.atom); -- cgit v1.2.3