diff --git a/src/DirectMpvPlayerBackend.h b/src/DirectMpvPlayerBackend.h index 3f147b4..c4f8b99 100644 --- a/src/DirectMpvPlayerBackend.h +++ b/src/DirectMpvPlayerBackend.h @@ -1,4 +1,4 @@ -#ifndef DirectMpvPlayerBackend_Hc +#ifndef DirectMpvPlayerBackend_H #define DirectMpvPlayerBackend_H #include diff --git a/src/MpvPlayerBackend.cpp b/src/MpvPlayerBackend.cpp index d408302..1e659fe 100644 --- a/src/MpvPlayerBackend.cpp +++ b/src/MpvPlayerBackend.cpp @@ -4,6 +4,8 @@ #include "MpvPlayerBackend.h" +#ifndef DISABLE_MpvPlayerBackend + #include "utils.hpp" #include #include @@ -183,6 +185,7 @@ MpvPlayerBackend::~MpvPlayerBackend() { printf("Shutting down...\n"); Utils::SetDPMS(true); + command("quit-watch-later"); mpv_render_context_free(mpv_gl); mpv_terminate_destroy(mpv); printf("MPV terminated.\n"); @@ -580,3 +583,5 @@ MpvPlayerBackend::createRenderer() const window()->setPersistentSceneGraph(true); return new MpvRenderer(const_cast(this)); } + +#endif diff --git a/src/MpvPlayerBackend.h b/src/MpvPlayerBackend.h index 313cdb5..8582934 100644 --- a/src/MpvPlayerBackend.h +++ b/src/MpvPlayerBackend.h @@ -1,8 +1,15 @@ -#ifndef MpvPlayerBackend_Hc +#ifndef MpvPlayerBackend_H #define MpvPlayerBackend_H #include #include + +#if MPV_CLIENT_API_VERSION <= MPV_MAKE_VERSION(1, 28) +#define DISABLE_MpvPlayerBackend +#endif + +#ifndef DISABLE_MpvPlayerBackend + #include #include @@ -11,6 +18,7 @@ #include "backendinterface.hpp" #include "enums.hpp" +#include "utils.hpp" class MpvRenderer; @@ -85,3 +93,4 @@ private: }; #endif +#endif diff --git a/src/main.cpp b/src/main.cpp index 7f1e202..609f5b7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,8 +54,11 @@ catchUnixSignals(std::initializer_list quitSignals) int main(int argc, char* argv[]) { - +#ifdef DISABLE_MpvPlayerBackend + Enums::Backends backend = Enums::Backends::DirectMpvBackend; +#else Enums::Backends backend = Enums::Backends::MpvBackend; +#endif setenv("QT_QUICK_CONTROLS_STYLE", "Desktop", 1); QApplication app(argc, argv); #ifdef __linux__ @@ -99,23 +102,24 @@ main(int argc, char* argv[]) app.setApplicationName("KittehPlayer"); QSettings settings; - QString backendSetting = settings.value("Backend/backend", "mpv").toString(); - if (backendSetting == "mpv") { - qDebug() << "Using MPV backend."; - backend = Enums::Backends::MpvBackend; - } else if (backendSetting == "direct-mpv") { - qDebug() << "Using Direct MPV backend."; - backend = Enums::Backends::DirectMpvBackend; + QString backendSetting = settings.value("Backend/backend", "").toString(); + if (backendSetting.length() == 0) { +#ifndef DISABLE_MpvPlayerBackend + settings.setValue("Backend/backend", "mpv"); +#else + settings.setValue("Backend/backend", "direct-mpv"); +#endif } + qDebug() << backendSetting; + for (int i = 1; i < argc; ++i) { if (!qstrcmp(argv[i], "--update")) { Utils::updateAppImage(); - } else if (!qstrcmp(argv[i], "--backend=mpv")) { - qDebug() << "Using MPV backend."; + } else if (!qstrcmp(argv[i], "--backend=mpv") || backendSetting == "mpv") { backend = Enums::Backends::MpvBackend; - } else if (!qstrcmp(argv[i], "--backend=direct-mpv")) { - qDebug() << "Using Direct MPV backend."; + } else if (!qstrcmp(argv[i], "--backend=direct-mpv") || + backendSetting == "direct-mpv") { backend = Enums::Backends::DirectMpvBackend; } } @@ -128,23 +132,25 @@ main(int argc, char* argv[]) setenv("PATH", newpath.toUtf8().constData(), 1); qmlRegisterUncreatableMetaObject( - Enums::staticMetaObject, // static meta object - "player", // import statement (can be any string) - 1, - 0, // major and minor version of the import - "Enums", // name in QML (does not have to match C++ name) - "Error: only enums" // error in case someone tries to create a MyNamespace - // object - ); + Enums::staticMetaObject, "player", 1, 0, "Enums", "Error: only enums"); qRegisterMetaType("Enums.PlayStatus"); qRegisterMetaType("Enums.VolumeStatus"); qRegisterMetaType("Enums.Backends"); qRegisterMetaType("Enums.Commands"); + qmlRegisterType("player", 1, 0, "Utils"); + switch (backend) { case Enums::Backends::MpvBackend: { +#ifndef DISABLE_MpvPlayerBackend qmlRegisterType("player", 1, 0, "PlayerBackend"); +#else + qDebug() << "Normal MPV backend not available, resetting backend option " + "to blank."; + settings.setValue("Backend/backend", "direct-mpv"); + app.exit(); +#endif break; } case Enums::Backends::DirectMpvBackend: { diff --git a/src/qml/ControlsBar.qml b/src/qml/ControlsBar.qml index 039a2a8..b5c5725 100644 --- a/src/qml/ControlsBar.qml +++ b/src/qml/ControlsBar.qml @@ -133,16 +133,21 @@ Item { var x = Math.max(Screen.height / 256, fun.nyanCat ? 12 : 2) return isMouse & !fun.nyanCat ? x * 2 : x } - MouseArea { id: mouseAreaProgressBar - y: parent.height width: parent.width height: parent.height anchors.fill: parent + y: parent.y + x: parent.x hoverEnabled: true - propagateComposedEvents: true + propagateComposedEvents: false acceptedButtons: Qt.NoButton + z: 1 + onPositionChanged: { + var a = (mouseAreaProgressBar.mouseX * (progressBar.to / (progressBackground.width))); + hoverProgressLabel.text = utils.createTimestamp(a) + } } background: Rectangle { @@ -153,6 +158,28 @@ Item { height: progressBar.getProgressBarHeight( fun.nyanCat, mouseAreaProgressBar.containsMouse) color: appearance.progressBackgroundColor + + + Rectangle { + x: (mouseAreaProgressBar.mouseX - width / 2) + progressBar.leftPadding + y: progressBackground.y - 20 - height + visible: mouseAreaProgressBar.containsMouse + color: appearance.mainBackground + height: 20 + width: 50 + z: 80 + Text { + id: hoverProgressLabel + text: "0:00" + color: "white" + padding: 2 + font.family: appearance.fontName + font.pixelSize: 14 + verticalAlignment: Text.AlignVCenter + renderType: Text.NativeRendering + } + } + ProgressBar { id: cachedLength background: Item { @@ -178,7 +205,6 @@ Item { player.chaptersChanged.connect(chaptersChanged) } function chaptersChanged(chapters) { - console.log(JSON.stringify(chapters)) for (var i = 0, len = chapters.length; i < len; i++) { var chapter = chapters[i] var component = Qt.createComponent( @@ -197,7 +223,6 @@ Item { z: 50 anchors.left: progressBackground.left width: progressBar.visualPosition * parent.width - + (progressBar.handle.width / 2) height: parent.height color: appearance.progressSliderColor Image { diff --git a/src/qml/main.qml b/src/qml/main.qml index 56c39df..39d4806 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -16,6 +16,8 @@ Window { width: 720 height: 480 + property bool onTop: false + Translator { id: translate } @@ -116,31 +118,26 @@ Window { mainWindow.visibility = lastScreenVisibility } } - + + Utils { + id: utils + } + PlayerBackend { id: player anchors.fill: parent width: parent.width height: parent.height z: 1 - property bool controlsShowing: true - function startPlayer() { - console.log(player) - console.log(typeof (player)) var args = Qt.application.arguments var len = Qt.application.arguments.length var argNo = 0 if (!appearance.useMpvSubs) { - player.setOption("sub-font", "Noto Sans") - player.setOption("sub-font-size", "24") player.setOption("sub-ass-override", "force") player.setOption("sub-ass", "off") player.setOption("sub-border-size", "0") - player.setOption("sub-bold", "off") - player.setOption("sub-scale-by-window", "on") - player.setOption("sub-scale-with-window", "on") player.setOption("sub-color", "0.0/0.0/0.0/0.0") player.setOption("sub-border-color", "0.0/0.0/0.0/0.0") player.setOption("sub-back-color", "0.0/0.0/0.0/0.0") @@ -198,6 +195,15 @@ Window { } } } + } + + Item { + id: controlsOverlay + anchors.centerIn: player + height: player.height + width: player.width + property bool controlsShowing: true + z: 2 function hideControls(force) { if (!menuBar.anythingOpen() || force) { @@ -212,13 +218,7 @@ Window { mouseAreaPlayer.cursorShape = Qt.ArrowCursor } } - } - Item { - anchors.centerIn: player - height: player.height - width: player.width - z: 2 - + MouseArea { id: mouseAreaBar @@ -278,18 +278,18 @@ Window { running: true repeat: false onTriggered: { - player.hideControls() + controlsOverlay.hideControls() } } onPositionChanged: { - player.showControls() + controlsOverlay.showControls() mouseAreaPlayerTimer.restart() } } MainMenu { id: menuBar - visible: player.controlsShowing + visible: controlsOverlay.controlsShowing } Rectangle { @@ -298,7 +298,7 @@ Window { anchors.right: parent.right anchors.left: menuBar.right anchors.top: parent.top - visible: player.controlsShowing + visible: controlsOverlay.controlsShowing color: appearance.mainBackground @@ -319,7 +319,7 @@ Window { font.pixelSize: 14 font.bold: true opacity: 1 - visible: player.controlsShowing + visible: controlsOverlay.controlsShowing && ((!appearance.titleOnlyOnFullscreen) || (mainWindow.visibility == Window.FullScreen)) Component.onCompleted: { @@ -332,7 +332,7 @@ Window { ControlsBar { id: controlsBar - visible: player.controlsShowing + visible: controlsOverlay.controlsShowing } } } diff --git a/src/utils.hpp b/src/utils.hpp index 29a42b7..3dd59a0 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -1,9 +1,12 @@ #ifndef UTILS_H #define UTILS_H +#include #include +#include #include namespace Utils { +Q_NAMESPACE void SetDPMS(bool on); void @@ -15,4 +18,19 @@ createTimestamp(int seconds); void ResetScreensaver(); } + +class UtilsClass : public QObject +{ + Q_OBJECT +public slots: + void SetDPMS(bool on) { Utils::SetDPMS(on); }; + void AlwaysOnTop(WId wid, bool on) { Utils::AlwaysOnTop(wid, on); }; + void updateAppImage() { Utils::updateAppImage(); }; + QString createTimestamp(int seconds) + { + return Utils::createTimestamp(seconds); + }; + void ResetScreensaver() { Utils::ResetScreensaver(); }; +}; + #endif