From d853abafc3e0f3de06e6cf86908f5bf2aba8f7c0 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 4 Apr 2013 01:13:56 +0200 Subject: x11: use mpv internal key auto-repeat handling if possible Block X11's native key repeat, and use mpv's key repeat handling in input.c instead. No configure check for XKB. Even though it's an extension, it has been part of most (all?) xlibs since 1996. If XKB appears to be missing, just refuse enabling x11. This is a potentially controversial change. mpv will use its own key repeat rate, instead of X11's. This should be better, because seeking will have a standardized "speed" (seek events per seconds when keeping a seek key held down). It will also allow disabling key repears for certain commands, though this is not done anywhere yet. The new behavior can be disabled with the --native-keyrepeat option. --- video/out/x11_common.c | 25 +++++++++++++++++++++++-- video/out/x11_common.h | 1 + 2 files changed, 24 insertions(+), 2 deletions(-) (limited to 'video') diff --git a/video/out/x11_common.c b/video/out/x11_common.c index a08f95d822..2e5f14f8d1 100644 --- a/video/out/x11_common.c +++ b/video/out/x11_common.c @@ -44,6 +44,7 @@ #include #include #include +#include #ifdef CONFIG_XSS #include @@ -450,6 +451,12 @@ int vo_x11_init(struct vo *vo) x11->screen = DefaultScreen(x11->display); // screen ID x11->rootwin = RootWindow(x11->display, x11->screen); // root window ID + if (!opts->native_keyrepeat) { + Bool ok = False; + XkbSetDetectableAutoRepeat(x11->display, True, &ok); + x11->no_autorepeat = ok; + } + x11->xim = XOpenIM(x11->display, NULL, NULL, NULL); init_atoms(vo->x11); @@ -629,6 +636,8 @@ void vo_x11_uninit(struct vo *vo) struct vo_x11_state *x11 = vo->x11; assert(x11); + mplayer_put_key(vo->key_fifo, MP_INPUT_RELEASE_ALL); + saver_on(x11); if (x11->window != None) vo_showcursor(vo, x11->display, x11->window); @@ -721,6 +730,8 @@ int vo_x11_check_events(struct vo *vo) char buf[100]; KeySym keySym = 0; int modifiers = 0; + if (x11->no_autorepeat) + modifiers |= MP_KEY_STATE_DOWN; if (Event.xkey.state & ShiftMask) modifiers |= MP_KEY_MODIFIER_SHIFT; if (Event.xkey.state & ControlMask) @@ -747,8 +758,17 @@ int vo_x11_check_events(struct vo *vo) if (mpkey) mplayer_put_key(vo->key_fifo, mpkey | modifiers); } + break; + } + // Releasing all keys in these situations is simpler and ensures no + // keys can be get "stuck". + case FocusOut: + case KeyRelease: + { + if (x11->no_autorepeat) + mplayer_put_key(vo->key_fifo, MP_INPUT_RELEASE_ALL); + break; } - break; case MotionNotify: vo_mouse_movement(vo, Event.xmotion.x, Event.xmotion.y); vo_x11_unhide_cursor(vo); @@ -981,7 +1001,8 @@ static void vo_x11_map_window(struct vo *vo, int x, int y, int w, int h) vo_x11_decoration(vo, 0); // map window vo_x11_selectinput_witherr(vo, x11->display, x11->window, - StructureNotifyMask | KeyPressMask | + StructureNotifyMask | + KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask | ExposureMask); XMapWindow(x11->display, x11->window); diff --git a/video/out/x11_common.h b/video/out/x11_common.h index 2ac3da2864..88a52e1953 100644 --- a/video/out/x11_common.h +++ b/video/out/x11_common.h @@ -44,6 +44,7 @@ struct vo_x11_state { XIM xim; XIC xic; + bool no_autorepeat; GC f_gc; // used to paint background GC vo_gc; // used to paint video -- cgit v1.2.3