2014-02-10 20:30:55 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "libmpv/client.h"
|
|
|
|
#include "shared.h"
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
if (argc != 2) {
|
|
|
|
printf("pass a single media file as argument\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
mpv_handle *ctx = mpv_create();
|
|
|
|
if (!ctx) {
|
|
|
|
printf("failed creating context\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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"));
|
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.
2014-09-28 18:11:00 +00:00
|
|
|
mpv_set_option_string(ctx, "input-x11-keyboard", "yes");
|
2014-02-24 22:02:50 +00:00
|
|
|
int val = 1;
|
|
|
|
check_error(mpv_set_option(ctx, "osc", MPV_FORMAT_FLAG, &val));
|
2014-02-10 20:30:55 +00:00
|
|
|
|
|
|
|
// Done setting up options.
|
|
|
|
check_error(mpv_initialize(ctx));
|
|
|
|
|
|
|
|
// Play this file.
|
|
|
|
const char *cmd[] = {"loadfile", argv[1], NULL};
|
|
|
|
check_error(mpv_command(ctx, cmd));
|
|
|
|
|
|
|
|
// Let it play, and wait until the user quits.
|
|
|
|
while (1) {
|
|
|
|
mpv_event *event = mpv_wait_event(ctx, 10000);
|
|
|
|
printf("event: %s\n", mpv_event_name(event->event_id));
|
|
|
|
if (event->event_id == MPV_EVENT_SHUTDOWN)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-06-07 18:25:48 +00:00
|
|
|
mpv_terminate_destroy(ctx);
|
2014-02-10 20:30:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|