From 999344c9dfaadffa070282c31486e509b61692fa Mon Sep 17 00:00:00 2001 From: NamedKitten Date: Sat, 1 Dec 2018 13:03:22 +0000 Subject: [PATCH] [UI+Backend] Added wayland support and fixed config names. --- CMakeLists.txt | 2 +- src/MpvPlayerBackend.cpp | 31 +++++++++++++++++++------------ src/qml/main.qml | 4 ++-- src/utils.cpp | 2 ++ 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cf70fb1..b50c002 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,7 +97,7 @@ add_executable(KittehPlayer ${SOURCES} ${qml_QRC}) # Use the Qml/Quick modules from Qt 5. target_link_libraries(KittehPlayer ${MPV_LIBRARIES} ${X11_LIBRARIES} ${Xext_LIBRARIES} Qt5::X11Extras) - +include_directories(${Qt5Gui_PRIVATE_INCLUDE_DIRS}) qt5_use_modules(KittehPlayer Qml Quick Core Gui Widgets X11Extras) install (TARGETS ${PROJECT_NAME} DESTINATION bin) diff --git a/src/MpvPlayerBackend.cpp b/src/MpvPlayerBackend.cpp index bcb2b91..d6e6241 100644 --- a/src/MpvPlayerBackend.cpp +++ b/src/MpvPlayerBackend.cpp @@ -1,7 +1,6 @@ #include #include #include - #include "MpvPlayerBackend.h" #include "utils.hpp" @@ -20,6 +19,8 @@ #include #include #include +#include +#include #endif namespace { @@ -33,7 +34,7 @@ wakeup(void* ctx) void on_mpv_redraw(void* ctx) { - MpvPlayerBackend::on_update(ctx); + QMetaObject::invokeMethod(reinterpret_cast(ctx), "update"); } static void* @@ -74,8 +75,22 @@ public: { MPV_RENDER_PARAM_API_TYPE, const_cast(MPV_RENDER_API_TYPE_OPENGL) }, { MPV_RENDER_PARAM_OPENGL_INIT_PARAMS, &gl_init_params }, + { MPV_RENDER_PARAM_INVALID, nullptr }, { MPV_RENDER_PARAM_INVALID, nullptr } }; +#if __linux__ + if (QGuiApplication::platformName().contains("xcb")) { + params[2].type = MPV_RENDER_PARAM_X11_DISPLAY; + params[2].data = QX11Info::display(); + qDebug() << "On Xorg."; + } else if (QGuiApplication::platformName().contains("wayland")) { + QPlatformNativeInterface *native = QGuiApplication::platformNativeInterface(); + params[2].type = MPV_RENDER_PARAM_WL_DISPLAY; + params[2].data = native->nativeResourceForWindow("display", nullptr); + qDebug() << "On wayland."; + } +#endif + if (mpv_render_context_create(&obj->mpv_gl, obj->mpv, params) < 0) throw std::runtime_error("failed to initialize mpv GL context"); mpv_render_context_set_update_callback(obj->mpv_gl, on_mpv_redraw, obj); @@ -95,23 +110,15 @@ public: .h = fbo->height(), .internal_format = 0 }; int flip_y{ 0 }; -#ifdef __linux__ - Display* dpy = QX11Info::display(); -#endif mpv_render_param params[] = { - // Specify the default framebuffer (0) as target. This will - // render onto the entire screen. If you want to show the video - // in a smaller rectangle or apply fancy transformations, you'll - // need to render into a separate FBO and draw it manually. { MPV_RENDER_PARAM_OPENGL_FBO, &mpfbo }, -#ifdef __linux__ - { MPV_RENDER_PARAM_X11_DISPLAY, dpy }, -#endif // Flip rendering (needed due to flipped GL coordinate system). { MPV_RENDER_PARAM_FLIP_Y, &flip_y }, { MPV_RENDER_PARAM_INVALID, nullptr } }; + + // See render_gl.h on what OpenGL environment mpv expects, and // other API details. mpv_render_context_render(obj->mpv_gl, params); diff --git a/src/qml/main.qml b/src/qml/main.qml index 2ba3df8..aaaf056 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -51,7 +51,7 @@ Window { Settings { id: youTubeAppearance - category: "Appearance" + category: "YouTubeAppearance" property string mainBackground: "#9C000000" property string progressBackgroundColor: "#3CFFFFFF" property string progressCachedColor: "white" @@ -63,7 +63,7 @@ Window { Settings { id: nicoNicoAppearance - category: "Appearance" + category: "NicoNicoAppearance" property string mainBackground: "#9C000000" property string progressBackgroundColor: "#444" property string progressCachedColor: "white" diff --git a/src/utils.cpp b/src/utils.cpp index 2a231b0..82b4695 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -68,9 +68,11 @@ SetScreensaver(WId wid, bool on) QProcess xdgScreensaver; xdgScreensaver.setProcessChannelMode(QProcess::ForwardedChannels); if (on) { + qDebug() << "Enabling screensaver."; xdgScreensaver.start("xdg-screensaver", QStringList() << "resume" << QString::number(wid)); } else { + qDebug() << "Disabling screensaver."; xdgScreensaver.start("xdg-screensaver", QStringList() << "suspend" << QString::number(wid)); }