summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2013-04-04 01:13:56 +0200
committerwm4 <wm4@nowhere>2013-04-24 18:07:01 +0200
commitd853abafc3e0f3de06e6cf86908f5bf2aba8f7c0 (patch)
treedf7cd78ebaddfe158cd64bc2fcf5e8225004cb87 /video
parent97be5ead1401f48571a073d63a75fad7d29b4d56 (diff)
downloadmpv-d853abafc3e0f3de06e6cf86908f5bf2aba8f7c0.tar.bz2
mpv-d853abafc3e0f3de06e6cf86908f5bf2aba8f7c0.tar.xz
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.
Diffstat (limited to 'video')
-rw-r--r--video/out/x11_common.c25
-rw-r--r--video/out/x11_common.h1
2 files changed, 24 insertions, 2 deletions
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 <X11/Xutil.h>
#include <X11/Xatom.h>
#include <X11/keysym.h>
+#include <X11/XKBlib.h>
#ifdef CONFIG_XSS
#include <X11/extensions/scrnsaver.h>
@@ -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