summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2016-09-09 12:36:44 +0200
committerwm4 <wm4@nowhere>2016-09-09 12:36:44 +0200
commit656341a0f52cc7e7f4404865c63c9339ea05f181 (patch)
treeb0aee3b867dc96888e7849e7f0da3141733c2ad5
parenta7b959cdfed6801d27963808f91eca0abb146b7e (diff)
downloadmpv-examples-656341a0f52cc7e7f4404865c63c9339ea05f181.tar.bz2
mpv-examples-656341a0f52cc7e7f4404865c63c9339ea05f181.tar.xz
qt_opengl: don't stall mpv when window is minimized
Unfortunately not perfect (see code comments). Taken from mpc-qt and relicensed with permission (cmdrkotori/mpc-qt#42).
-rw-r--r--libmpv/qt_opengl/mpvwidget.cpp23
-rw-r--r--libmpv/qt_opengl/mpvwidget.h1
2 files changed, 23 insertions, 1 deletions
diff --git a/libmpv/qt_opengl/mpvwidget.cpp b/libmpv/qt_opengl/mpvwidget.cpp
index 4d2cad6..47abee1 100644
--- a/libmpv/qt_opengl/mpvwidget.cpp
+++ b/libmpv/qt_opengl/mpvwidget.cpp
@@ -123,7 +123,28 @@ void MpvWidget::handle_mpv_event(mpv_event *event)
}
}
+// Make Qt invoke mpv_opengl_cb_draw() to draw a new/updated video frame.
+void MpvWidget::maybeUpdate()
+{
+ // If the Qt window is not visible, Qt's update() will just skip rendering.
+ // This confuses mpv's opengl-cb API, and may lead to small occasional
+ // freezes due to video rendering timing out.
+ // Handle this by manually redrawing.
+ // Note: Qt doesn't seem to provide a way to query whether update() will
+ // be skipped, and the following code still fails when e.g. switching
+ // to a different workspace with a reparenting window manager.
+ if (window()->isMinimized()) {
+ makeCurrent();
+ paintGL();
+ context()->swapBuffers(context()->surface());
+ swapped();
+ doneCurrent();
+ } else {
+ update();
+ }
+}
+
void MpvWidget::on_update(void *ctx)
{
- QMetaObject::invokeMethod((MpvWidget*)ctx, "update");
+ QMetaObject::invokeMethod((MpvWidget*)ctx, "maybeUpdate");
}
diff --git a/libmpv/qt_opengl/mpvwidget.h b/libmpv/qt_opengl/mpvwidget.h
index a219681..e3506d6 100644
--- a/libmpv/qt_opengl/mpvwidget.h
+++ b/libmpv/qt_opengl/mpvwidget.h
@@ -25,6 +25,7 @@ protected:
private Q_SLOTS:
void swapped();
void on_mpv_events();
+ void maybeUpdate();
private:
void handle_mpv_event(mpv_event *event);
static void on_update(void *ctx);