mirror of
https://github.com/mpv-player/mpv
synced 2025-03-25 04:38:01 +00:00
client API, X11: change default keyboard input handling again
Commit 64b7811c
tried to do the "right thing" with respect to whether
keyboard input should be enabled or not. It turns out that X11 does
something stupid by design. All modern toolkits work around this native
X11 behavior, but embedding breaks these workarounds.
The only way to handle this correctly is the XEmbed protocol. It needs
to be supported by the toolkit, and probably also some mpv support. But
Qt has inconsistent support for it. In Qt 4, a X11 specific embedding
widget was needed. Qt 5.0 doesn't support it at all. Qt 5.1 apparently
supports it via QWindow, but if it really does, I couldn't get it to
work.
So add a hack instead. The new --input-x11-keyboard option controls
whether mpv should enable keyboard input on the X11 window or not. In
the command line player, it's enabled by default, but in libmpv it's
disabled.
This hack has the same problem as all previous embedding had: move the
mouse outside of the window, and you don't get keyboard input anymore.
Likewise, mpv will steal all keyboard input from the parent application
as long as the mouse is inside of the mpv window.
Also see issue #1090.
This commit is contained in:
parent
aeaa1767e9
commit
3273db1ef7
@ -25,7 +25,12 @@ API changes
|
||||
|
||||
::
|
||||
|
||||
1.5 - change in X11 and "--wid" behavior again. The previous change didn't
|
||||
work as expected, and now the behavior can be explicitly controlled
|
||||
with the "input-x11-keyboard" option. This is only a temporary
|
||||
measure until XEmbed is implemented and confirmed working.
|
||||
1.4 - subtle change in X11 and "--wid" behavior
|
||||
(this change was added to 0.5.2, and broke some things, see #1090)
|
||||
--- mpv 0.5.0 is released ---
|
||||
1.3 - add MPV_MAKE_VERSION()
|
||||
1.2 - remove "stream-time-pos" property (no replacement)
|
||||
|
@ -53,6 +53,10 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
// mpv as backend would implement its own key bindings.
|
||||
mpv_set_option_string(mpv, "input-default-bindings", "yes");
|
||||
|
||||
// Enable keyboard input on the X11 window. For the messy details, see
|
||||
// --input-x11-keyboard on the manpage.
|
||||
mpv_set_option_string(mpv, "input-x11-keyboard", "yes");
|
||||
|
||||
// Let us receive property change events with MPV_EVENT_PROPERTY_CHANGE if
|
||||
// this property changes.
|
||||
mpv_observe_property(mpv, 0, "time-pos", MPV_FORMAT_DOUBLE);
|
||||
|
@ -21,6 +21,7 @@ int main(int argc, char *argv[])
|
||||
// Enable default key bindings, so the user can actually interact with
|
||||
// the player (and e.g. close the window).
|
||||
check_error(mpv_set_option_string(ctx, "input-default-bindings", "yes"));
|
||||
mpv_set_option_string(ctx, "input-x11-keyboard", "yes");
|
||||
int val = 1;
|
||||
check_error(mpv_set_option(ctx, "osc", MPV_FORMAT_FLAG, &val));
|
||||
|
||||
|
@ -2163,6 +2163,24 @@ Input
|
||||
Use the right Alt key as Alt Gr to produce special characters. If disabled,
|
||||
count the right Alt as an Alt modifier key. Enabled by default.
|
||||
|
||||
``--input-x11-keyboard=<yes|no>``
|
||||
Disable all keyboard input on the X11 VO window. Generally useful for
|
||||
embedding only.
|
||||
|
||||
On X11, a sub-window with input enabled grabs all keyboard input as long
|
||||
as it is 1. a child of a focused window, and 2. the mouse is inside of
|
||||
the sub-window. The can steal away all keyboard input from the
|
||||
application embedding the mpv window, and on the other hand, the mpv
|
||||
window will receive no input if the mouse is outside of the mpv window,
|
||||
even though mpv has focus. Modern toolkits work around this weird X11
|
||||
behavior, but naively embedding foreign windows breaks it.
|
||||
|
||||
The only way to handle this reasonably is using the XEmbed protocol, which
|
||||
was designed to solve these problems. But Qt has questionable support, and
|
||||
mpv doesn't implement it yet.
|
||||
|
||||
As a workaround, this option is disabled by default in libmpv. (Note that
|
||||
``input-default-bindings`` is disabled by default in libmpv as well.)
|
||||
|
||||
OSD
|
||||
---
|
||||
|
@ -175,6 +175,7 @@ struct input_opts {
|
||||
int use_media_keys;
|
||||
int default_bindings;
|
||||
int enable_mouse_movements;
|
||||
int x11_key_input;
|
||||
int test;
|
||||
};
|
||||
|
||||
@ -195,6 +196,7 @@ const struct m_sub_options input_config = {
|
||||
OPT_FLAG("right-alt-gr", use_alt_gr, CONF_GLOBAL),
|
||||
OPT_INTRANGE("key-fifo-size", key_fifo_size, CONF_GLOBAL, 2, 65000),
|
||||
OPT_FLAG("cursor", enable_mouse_movements, CONF_GLOBAL),
|
||||
OPT_FLAG("x11-keyboard", x11_key_input, CONF_GLOBAL),
|
||||
#if HAVE_LIRC
|
||||
OPT_STRING("lirc-conf", lirc_configfile, CONF_GLOBAL),
|
||||
#endif
|
||||
@ -218,6 +220,7 @@ const struct m_sub_options input_config = {
|
||||
.use_media_keys = 1,
|
||||
#endif
|
||||
.default_bindings = 1,
|
||||
.x11_key_input = 1,
|
||||
},
|
||||
};
|
||||
|
||||
@ -706,6 +709,14 @@ bool mp_input_mouse_enabled(struct input_ctx *ictx)
|
||||
return r;
|
||||
}
|
||||
|
||||
bool mp_input_x11_keyboard_enabled(struct input_ctx *ictx)
|
||||
{
|
||||
input_lock(ictx);
|
||||
bool r = ictx->opts->x11_key_input;
|
||||
input_unlock(ictx);
|
||||
return r;
|
||||
}
|
||||
|
||||
void mp_input_set_mouse_pos(struct input_ctx *ictx, int x, int y)
|
||||
{
|
||||
input_lock(ictx);
|
||||
|
@ -156,6 +156,8 @@ void mp_input_get_mouse_pos(struct input_ctx *ictx, int *x, int *y);
|
||||
// Return whether we want/accept mouse input.
|
||||
bool mp_input_mouse_enabled(struct input_ctx *ictx);
|
||||
|
||||
bool mp_input_x11_keyboard_enabled(struct input_ctx *ictx);
|
||||
|
||||
/* Make mp_input_set_mouse_pos() mangle the mouse coordinates. Hack for certain
|
||||
* VOs. dst=NULL, src=NULL reset it. src can be NULL.
|
||||
*/
|
||||
|
@ -162,7 +162,7 @@ extern "C" {
|
||||
* relational operators (<, >, <=, >=).
|
||||
*/
|
||||
#define MPV_MAKE_VERSION(major, minor) (((major) << 16) | (minor) | 0UL)
|
||||
#define MPV_CLIENT_API_VERSION MPV_MAKE_VERSION(1, 4)
|
||||
#define MPV_CLIENT_API_VERSION MPV_MAKE_VERSION(1, 5)
|
||||
|
||||
/**
|
||||
* Return the MPV_CLIENT_API_VERSION the mpv source has been compiled with.
|
||||
|
@ -403,6 +403,7 @@ mpv_handle *mpv_create(void)
|
||||
mpv_set_option_string(ctx, "terminal", "no");
|
||||
mpv_set_option_string(ctx, "osc", "no");
|
||||
mpv_set_option_string(ctx, "input-default-bindings", "no");
|
||||
mpv_set_option_string(ctx, "input-x11-keyboard", "no");
|
||||
mpv_set_option_string(ctx, "input-lirc", "no");
|
||||
} else {
|
||||
mp_destroy(mpctx);
|
||||
|
@ -1254,15 +1254,12 @@ static void vo_x11_map_window(struct vo *vo, struct mp_rect rc)
|
||||
}
|
||||
|
||||
// map window
|
||||
int events = StructureNotifyMask | ExposureMask | PropertyChangeMask;
|
||||
if (vo->opts->WinID > 0) {
|
||||
XWindowAttributes attribs;
|
||||
if (XGetWindowAttributes(x11->display, vo->opts->WinID, &attribs))
|
||||
events |= attribs.your_event_mask;
|
||||
} else {
|
||||
events |= KeyPressMask | KeyReleaseMask | ButtonPressMask |
|
||||
ButtonReleaseMask | PointerMotionMask | LeaveWindowMask;
|
||||
}
|
||||
int events = StructureNotifyMask | ExposureMask | PropertyChangeMask |
|
||||
LeaveWindowMask;
|
||||
if (mp_input_mouse_enabled(vo->input_ctx))
|
||||
events |= PointerMotionMask | ButtonPressMask | ButtonReleaseMask;
|
||||
if (mp_input_x11_keyboard_enabled(vo->input_ctx))
|
||||
events |= KeyPressMask | KeyReleaseMask;
|
||||
vo_x11_selectinput_witherr(vo, x11->display, x11->window, events);
|
||||
XMapWindow(x11->display, x11->window);
|
||||
}
|
||||
@ -1667,9 +1664,6 @@ static void vo_x11_selectinput_witherr(struct vo *vo,
|
||||
Window w,
|
||||
long event_mask)
|
||||
{
|
||||
if (!mp_input_mouse_enabled(vo->input_ctx))
|
||||
event_mask &= ~(PointerMotionMask | ButtonPressMask | ButtonReleaseMask);
|
||||
|
||||
XSelectInput(display, w, NoEventMask);
|
||||
|
||||
// NOTE: this can raise BadAccess, which should be ignored by the X error
|
||||
|
Loading…
Reference in New Issue
Block a user