From 2b05c3184d62638002b3105fd4bc0a9891d76242 Mon Sep 17 00:00:00 2001 From: NamedKitten Date: Sat, 1 Dec 2018 12:10:52 +0000 Subject: [PATCH] [UI+Backend] Hopefuly make disabling screensaver better and added per theme colours. --- src/DirectMpvPlayerBackend.cpp | 9 ++- src/MpvPlayerBackend.cpp | 8 +-- src/qml/ControlsBar.qml | 6 +- src/qml/CustomMenu.qml | 3 +- src/qml/Items/ChapterMarkerItem.qml | 3 +- src/qml/MainMenu.qml | 3 +- src/qml/NiconicoButtonLayout.qml | 5 -- src/qml/UIComponents/BackwardButton.qml | 2 +- src/qml/UIComponents/ForwardButton.qml | 2 +- src/qml/UIComponents/FullscreenButton.qml | 3 +- src/qml/UIComponents/PlayPauseButton.qml | 2 +- src/qml/UIComponents/PlaylistNextButton.qml | 2 +- src/qml/UIComponents/PlaylistPrevButton.qml | 2 +- src/qml/UIComponents/SettingsButton.qml | 2 +- src/qml/UIComponents/VideoProgress.qml | 16 +++-- src/qml/UIComponents/VolumeButton.qml | 2 +- src/qml/UIComponents/VolumeSlider.qml | 6 +- src/qml/YouTubeButtonLayout.qml | 1 - src/qml/main.qml | 77 ++++++++++++++------- src/utils.cpp | 67 +++++++++--------- src/utils.hpp | 5 +- 21 files changed, 126 insertions(+), 100 deletions(-) diff --git a/src/DirectMpvPlayerBackend.cpp b/src/DirectMpvPlayerBackend.cpp index 5b122b6..522aea5 100644 --- a/src/DirectMpvPlayerBackend.cpp +++ b/src/DirectMpvPlayerBackend.cpp @@ -109,7 +109,7 @@ DirectMpvPlayerBackend::DirectMpvPlayerBackend(QQuickItem* parent) mpv_observe_property(mpv, 0, "sub-text", MPV_FORMAT_STRING); mpv_observe_property(mpv, 0, "time-pos", MPV_FORMAT_DOUBLE); mpv_observe_property(mpv, 0, "demuxer-cache-duration", MPV_FORMAT_DOUBLE); - mpv_observe_property(mpv, 0, "pause", MPV_FORMAT_NONE); + mpv_observe_property(mpv, 0, "pause", MPV_FORMAT_NODE); mpv_observe_property(mpv, 0, "playlist", MPV_FORMAT_NODE); mpv_set_wakeup_callback(mpv, wakeup, this); @@ -541,7 +541,6 @@ DirectMpvPlayerBackend::handle_mpv_event(mpv_event* event) if (prop->format == MPV_FORMAT_DOUBLE) { double time = *(double*)prop->data; emit durationChanged(time); - Utils::ResetScreensaver(); } } else if (strcmp(prop->name, "mute") == 0 || strcmp(prop->name, "volume") == 0) { @@ -578,10 +577,14 @@ DirectMpvPlayerBackend::handle_mpv_event(mpv_event* event) emit playlistPositionChanged(pos); } } else if (strcmp(prop->name, "pause") == 0) { - if (getProperty("pause").toBool()) { + mpv_node* nod = (mpv_node*)prop->data; + if (mpv::qt::node_to_variant(nod).toBool()) { emit playStatusChanged(Enums::PlayStatus::Paused); + Utils::SetScreensaver(window()->winId(), true); + } else { emit playStatusChanged(Enums::PlayStatus::Playing); + Utils::SetScreensaver(window()->winId(), true); } } else if (strcmp(prop->name, "track-list") == 0) { mpv_node* nod = (mpv_node*)prop->data; diff --git a/src/MpvPlayerBackend.cpp b/src/MpvPlayerBackend.cpp index 52f7403..bcb2b91 100644 --- a/src/MpvPlayerBackend.cpp +++ b/src/MpvPlayerBackend.cpp @@ -159,7 +159,7 @@ MpvPlayerBackend::MpvPlayerBackend(QQuickItem* parent) mpv_observe_property(mpv, 0, "sub-text", MPV_FORMAT_STRING); mpv_observe_property(mpv, 0, "time-pos", MPV_FORMAT_DOUBLE); mpv_observe_property(mpv, 0, "demuxer-cache-duration", MPV_FORMAT_DOUBLE); - mpv_observe_property(mpv, 0, "pause", MPV_FORMAT_DOUBLE); + mpv_observe_property(mpv, 0, "pause", MPV_FORMAT_NODE); mpv_observe_property(mpv, 0, "playlist", MPV_FORMAT_NODE); mpv_set_wakeup_callback(mpv, wakeup, this); @@ -519,7 +519,6 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event) if (prop->format == MPV_FORMAT_DOUBLE) { double time = *(double*)prop->data; emit durationChanged(time); - Utils::ResetScreensaver(); } } else if (strcmp(prop->name, "mute") == 0 || strcmp(prop->name, "volume") == 0) { @@ -558,11 +557,12 @@ MpvPlayerBackend::handle_mpv_event(mpv_event* event) } } else if (strcmp(prop->name, "pause") == 0) { mpv_node* nod = (mpv_node*)prop->data; - qDebug() << mpv::qt::node_to_variant(nod); - if (getProperty("pause").toBool()) { + if (mpv::qt::node_to_variant(nod).toBool()) { emit playStatusChanged(Enums::PlayStatus::Paused); + Utils::SetScreensaver(window()->winId(), true); } else { emit playStatusChanged(Enums::PlayStatus::Playing); + Utils::SetScreensaver(window()->winId(), false); } } else if (strcmp(prop->name, "track-list") == 0) { mpv_node* nod = (mpv_node*)prop->data; diff --git a/src/qml/ControlsBar.qml b/src/qml/ControlsBar.qml index 723e1e0..8af4df6 100644 --- a/src/qml/ControlsBar.qml +++ b/src/qml/ControlsBar.qml @@ -81,7 +81,8 @@ Item { opacity: 1 background: Rectangle { id: subsBackground - color: appearance.mainBackground + color: getAppearanceValueForTheme(appearance.themeName, + "mainBackground") width: subsContainer.childrenRect.width height: subsContainer.childrenRect.height } @@ -106,7 +107,8 @@ Item { anchors.right: parent.right Layout.fillWidth: true Layout.fillHeight: true - color: appearance.mainBackground + color: getAppearanceValueForTheme(appearance.themeName, + "mainBackground") visible: controlsOverlay.controlsShowing } diff --git a/src/qml/CustomMenu.qml b/src/qml/CustomMenu.qml index 9da3a6d..a0b671b 100644 --- a/src/qml/CustomMenu.qml +++ b/src/qml/CustomMenu.qml @@ -6,7 +6,8 @@ Menu { background: Rectangle { implicitWidth: parent.width implicitHeight: 10 - color: appearance.mainBackground + color: getAppearanceValueForTheme(appearance.themeName, + "mainBackground") } delegate: CustomMenuItem { } diff --git a/src/qml/Items/ChapterMarkerItem.qml b/src/qml/Items/ChapterMarkerItem.qml index 4bd7761..ea12551 100644 --- a/src/qml/Items/ChapterMarkerItem.qml +++ b/src/qml/Items/ChapterMarkerItem.qml @@ -6,7 +6,8 @@ import player 1.0 Rectangle { id: chapterMarker property int time: 0 - color: appearance.chapterMarkerColor + color: getAppearanceValueForTheme(appearance.themeName, + "chapterMarkerColor") Connections { target: player enabled: true diff --git a/src/qml/MainMenu.qml b/src/qml/MainMenu.qml index f1fb8d7..5227c94 100644 --- a/src/qml/MainMenu.qml +++ b/src/qml/MainMenu.qml @@ -166,7 +166,8 @@ MenuBar { background: Rectangle { width: parent.width implicitHeight: 10 - color: appearance.mainBackground + color: getAppearanceValueForTheme(appearance.themeName, + "mainBackground") } CustomMenu { diff --git a/src/qml/NiconicoButtonLayout.qml b/src/qml/NiconicoButtonLayout.qml index de5bca3..3aeba28 100644 --- a/src/qml/NiconicoButtonLayout.qml +++ b/src/qml/NiconicoButtonLayout.qml @@ -40,7 +40,6 @@ Item { anchors.bottom: parent.bottom icon.height: parent.height / 2 icon.width: parent.height / 2 - } BackwardButton { id: backwardButton @@ -63,7 +62,6 @@ Item { anchors.bottom: parent.bottom icon.height: parent.height / 2 icon.width: parent.height / 2 - } PlaylistNextButton { id: playlistNextButton @@ -72,7 +70,6 @@ Item { anchors.bottom: parent.bottom icon.height: parent.height / 2 icon.width: parent.height / 2 - } FullscreenButton { @@ -82,7 +79,6 @@ Item { anchors.bottom: parent.bottom icon.height: parent.height / 2 icon.width: parent.height / 2 - } SettingsButton { id: settingsButton @@ -91,6 +87,5 @@ Item { anchors.bottom: parent.bottom icon.height: parent.height / 2 icon.width: parent.height / 2 - } } diff --git a/src/qml/UIComponents/BackwardButton.qml b/src/qml/UIComponents/BackwardButton.qml index 999094d..d37638b 100644 --- a/src/qml/UIComponents/BackwardButton.qml +++ b/src/qml/UIComponents/BackwardButton.qml @@ -10,7 +10,7 @@ import player 1.0 Button { id: backwardButton icon.source: "icons/" + appearance.themeName + "/backward.svg" - icon.color: appearance.buttonColor + icon.color: getAppearanceValueForTheme(appearance.themeName, "buttonColor") display: AbstractButton.IconOnly onClicked: { player.playerCommand(Enums.Commands.Seek, "-10") diff --git a/src/qml/UIComponents/ForwardButton.qml b/src/qml/UIComponents/ForwardButton.qml index d115e7f..f3e3071 100644 --- a/src/qml/UIComponents/ForwardButton.qml +++ b/src/qml/UIComponents/ForwardButton.qml @@ -10,7 +10,7 @@ import player 1.0 Button { id: forwardButton icon.source: "icons/" + appearance.themeName + "/forward.svg" - icon.color: appearance.buttonColor + icon.color: getAppearanceValueForTheme(appearance.themeName, "buttonColor") display: AbstractButton.IconOnly onClicked: { player.playerCommand(Enums.Commands.Seek, "10") diff --git a/src/qml/UIComponents/FullscreenButton.qml b/src/qml/UIComponents/FullscreenButton.qml index 69a8322..7f25dac 100644 --- a/src/qml/UIComponents/FullscreenButton.qml +++ b/src/qml/UIComponents/FullscreenButton.qml @@ -9,9 +9,8 @@ import player 1.0 Button { id: fullscreenButton - //icon.name: "fullscreen" icon.source: "icons/" + appearance.themeName + "/fullscreen.svg" - icon.color: appearance.buttonColor + icon.color: getAppearanceValueForTheme(appearance.themeName, "buttonColor") Layout.alignment: Qt.AlignVCenter | Qt.AlignRight display: AbstractButton.IconOnly diff --git a/src/qml/UIComponents/PlayPauseButton.qml b/src/qml/UIComponents/PlayPauseButton.qml index 4595e04..2c06378 100644 --- a/src/qml/UIComponents/PlayPauseButton.qml +++ b/src/qml/UIComponents/PlayPauseButton.qml @@ -10,7 +10,7 @@ import player 1.0 Button { id: playPauseButton icon.source: "icons/" + appearance.themeName + "/pause.svg" - icon.color: appearance.buttonColor + icon.color: getAppearanceValueForTheme(appearance.themeName, "buttonColor") display: AbstractButton.IconOnly onClicked: { player.playerCommand(Enums.Commands.TogglePlayPause) diff --git a/src/qml/UIComponents/PlaylistNextButton.qml b/src/qml/UIComponents/PlaylistNextButton.qml index be86612..860b252 100644 --- a/src/qml/UIComponents/PlaylistNextButton.qml +++ b/src/qml/UIComponents/PlaylistNextButton.qml @@ -11,7 +11,7 @@ Button { id: playlistNextButton //icon.name: "next" icon.source: "icons/" + appearance.themeName + "/next.svg" - icon.color: appearance.buttonColor + icon.color: getAppearanceValueForTheme(appearance.themeName, "buttonColor") display: AbstractButton.IconOnly onClicked: { player.playerCommand(Enums.Commands.NextPlaylistItem) diff --git a/src/qml/UIComponents/PlaylistPrevButton.qml b/src/qml/UIComponents/PlaylistPrevButton.qml index d547e5c..820284e 100644 --- a/src/qml/UIComponents/PlaylistPrevButton.qml +++ b/src/qml/UIComponents/PlaylistPrevButton.qml @@ -11,7 +11,7 @@ Button { id: playlistPrevButton objectName: "playlistPrevButton" icon.source: "icons/" + appearance.themeName + "/prev.svg" - icon.color: appearance.buttonColor + icon.color: getAppearanceValueForTheme(appearance.themeName, "buttonColor") display: AbstractButton.IconOnly visible: appearance.themeName == "Youtube" ? false : true onClicked: { diff --git a/src/qml/UIComponents/SettingsButton.qml b/src/qml/UIComponents/SettingsButton.qml index d0e23c2..6e0664b 100644 --- a/src/qml/UIComponents/SettingsButton.qml +++ b/src/qml/UIComponents/SettingsButton.qml @@ -11,7 +11,7 @@ Button { id: settingsButton //icon.name: "settings" icon.source: "icons/" + appearance.themeName + "/settings.svg" - icon.color: appearance.buttonColor + icon.color: getAppearanceValueForTheme(appearance.themeName, "buttonColor") Layout.alignment: Qt.AlignVCenter | Qt.AlignRight display: AbstractButton.IconOnly onClicked: { diff --git a/src/qml/UIComponents/VideoProgress.qml b/src/qml/UIComponents/VideoProgress.qml index cec364c..5d43d26 100644 --- a/src/qml/UIComponents/VideoProgress.qml +++ b/src/qml/UIComponents/VideoProgress.qml @@ -75,13 +75,15 @@ Slider { width: progressBar.availableWidth height: progressBar.getProgressBarHeight( fun.nyanCat, mouseAreaProgressBar.containsMouse) - color: appearance.progressBackgroundColor + color: getAppearanceValueForTheme(appearance.themeName, + "progressBackgroundColor") Rectangle { x: (mouseAreaProgressBar.mouseX - hoverProgressLabel.width / 2) y: progressBackground.y - 20 - hoverProgressLabel.height visible: mouseAreaProgressBar.containsMouse - color: appearance.mainBackground + color: getAppearanceValueForTheme(appearance.themeName, + "mainBackground") height: hoverProgressLabel.height width: hoverProgressLabel.width z: 80 @@ -105,7 +107,8 @@ Slider { Rectangle { width: cachedLength.visualPosition * parent.width height: parent.height - color: appearance.progressCachedColor + color: getAppearanceValueForTheme(appearance.themeName, + "progressCachedColor") } } z: 40 @@ -124,7 +127,6 @@ Slider { onChaptersChanged: function (chapters) { for (var i = 0, len = chapters.length; i < len; i++) { var component = Qt.createComponent("ChapterMarker.qml") - var marker = component.createObject(chapterMarkers, { time: chapters[i]["time"] }) @@ -139,7 +141,8 @@ Slider { anchors.left: progressBackground.left width: progressBar.visualPosition * parent.width height: parent.height - color: appearance.progressSliderColor + color: getAppearanceValueForTheme(appearance.themeName, + "progressSliderColor") Image { visible: fun.nyanCat id: rainbow @@ -161,7 +164,8 @@ Slider { implicitHeight: radius implicitWidth: radius radius: 12 + (progressBackground.height / 2) - color: fun.nyanCat ? "transparent" : appearance.progressSliderColor + color: fun.nyanCat ? "transparent" : getAppearanceValueForTheme( + appearance.themeName, "progressSliderColor") visible: getHandleVisibility(appearance.themeName, mouseAreaProgressBar.containsMouse) AnimatedImage { diff --git a/src/qml/UIComponents/VolumeButton.qml b/src/qml/UIComponents/VolumeButton.qml index 85a7688..69fa485 100644 --- a/src/qml/UIComponents/VolumeButton.qml +++ b/src/qml/UIComponents/VolumeButton.qml @@ -11,7 +11,7 @@ Button { id: volumeButton objectName: "volumeButton" icon.source: "icons/" + appearance.themeName + "/volume-up.svg" - icon.color: appearance.buttonColor + icon.color: getAppearanceValueForTheme(appearance.themeName, "buttonColor") display: AbstractButton.IconOnly onClicked: { player.playerCommand(Enums.Commands.ToggleMute) diff --git a/src/qml/UIComponents/VolumeSlider.qml b/src/qml/UIComponents/VolumeSlider.qml index 41eee3a..0f1bdfb 100644 --- a/src/qml/UIComponents/VolumeSlider.qml +++ b/src/qml/UIComponents/VolumeSlider.qml @@ -48,11 +48,13 @@ Slider { implicitHeight: appearance.themeName == "Niconico" ? layout.height / 8 : layout.height / 10 width: volumeBar.availableWidth height: implicitHeight - color: appearance.progressBackgroundColor + color: getAppearanceValueForTheme(appearance.themeName, + "progressBackgroundColor") Rectangle { width: volumeBar.visualPosition * parent.width height: parent.height - color: appearance.volumeSliderBackground + color: getAppearanceValueForTheme(appearance.themeName, + "volumeSliderBackground") } } } diff --git a/src/qml/YouTubeButtonLayout.qml b/src/qml/YouTubeButtonLayout.qml index 06e1bc7..4fd9f10 100644 --- a/src/qml/YouTubeButtonLayout.qml +++ b/src/qml/YouTubeButtonLayout.qml @@ -29,7 +29,6 @@ Item { anchors.bottom: parent.bottom icon.height: parent.height / 2 icon.width: parent.height / 2 - } PlaylistNextButton { id: playlistNextButton diff --git a/src/qml/main.qml b/src/qml/main.qml index 5042e67..5b7f6a7 100644 --- a/src/qml/main.qml +++ b/src/qml/main.qml @@ -20,6 +20,14 @@ Window { property bool onTop: false + function getAppearanceValueForTheme(themeName, name) { + if (themeName == "YouTube") { + return youTubeAppearance[name] + } else if (themeName == "Niconico") { + return nicoNicoAppearance[name] + } + } + Translator { id: translate } @@ -38,6 +46,12 @@ Window { property bool useMpvSubs: false property string themeName: "YouTube" property string fontName: "Roboto" + property double scaleFactor: 1.0 + } + + Settings { + id: youTubeAppearance + category: "Appearance" property string mainBackground: "#9C000000" property string progressBackgroundColor: "#3CFFFFFF" property string progressCachedColor: "white" @@ -45,7 +59,18 @@ Window { property string progressSliderColor: "red" property string chapterMarkerColor: "#fc0" property string volumeSliderBackground: "white" - property double scaleFactor: 1.0 + } + + Settings { + id: nicoNicoAppearance + category: "Appearance" + property string mainBackground: "#9C000000" + property string progressBackgroundColor: "#444" + property string progressCachedColor: "white" + property string buttonColor: "white" + property string progressSliderColor: "#007cff" + property string chapterMarkerColor: "#fc0" + property string volumeSliderBackground: "#0077cff" } Settings { @@ -93,6 +118,7 @@ Window { property string decreaseVolume: "/" property string mute: "m" property string increaseScale: "Ctrl+Shift+=" + property string resetScale: "Ctrl+Shift+0" property string decreaseScale: "Ctrl+Shift+-" property string customKeybind0: "" property string customKeybind0Command: "" @@ -137,6 +163,26 @@ Window { width: parent.width height: parent.height z: 1 + + Action { + onTriggered: { + appearance.scaleFactor += 0.1 + } + shortcut: keybinds.increaseScale + } + Action { + onTriggered: { + appearance.scaleFactor = 1 + } + shortcut: keybinds.resetScale + } + Action { + onTriggered: { + appearance.scaleFactor -= 0.1 + } + shortcut: keybinds.decreaseScale + } + function startPlayer() { var args = Qt.application.arguments var len = Qt.application.arguments.length @@ -239,19 +285,6 @@ Window { mouseAreaPlayerTimer.stop() } } - - Action { - onTriggered: { - appearance.scaleFactor += 0.1 - } - shortcut: appearance.increaseScale - } - Action { - onTriggered: { - appearance.scaleFactor -= 0.1 - } - shortcut: appearance.decreaseScale - } MouseArea { id: mouseAreaPlayer @@ -268,7 +301,7 @@ Window { anchors.topMargin: 0 hoverEnabled: true onDoubleClicked: { - playTimer.stop() + player.playerCommand(Enums.Commands.TogglePlayPause) toggleFullscreen() } Action { @@ -279,18 +312,9 @@ Window { } shortcut: "Esc" } - Timer { - id: playTimer - interval: 200 - running: false - repeat: false - onTriggered: { - player.playerCommand(Enums.Commands.TogglePlayPause) - } - } onClicked: { if (appearance.clickToPause) { - playTimer.start() + player.playerCommand(Enums.Commands.TogglePlayPause) } } Timer { @@ -321,7 +345,8 @@ Window { anchors.top: parent.top visible: controlsOverlay.controlsShowing - color: appearance.mainBackground + color: getAppearanceValueForTheme(appearance.themeName, + "mainBackground") Text { id: titleLabel diff --git a/src/utils.cpp b/src/utils.cpp index e7a8d5b..2a231b0 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -14,9 +14,6 @@ #include #include #include -#include -#include -#include #endif #endif @@ -65,36 +62,53 @@ createTimestamp(int seconds) } } -#ifdef __linux__ +void +SetScreensaver(WId wid, bool on) +{ + QProcess xdgScreensaver; + xdgScreensaver.setProcessChannelMode(QProcess::ForwardedChannels); + if (on) { + xdgScreensaver.start("xdg-screensaver", + QStringList() << "resume" << QString::number(wid)); + } else { + xdgScreensaver.start("xdg-screensaver", + QStringList() << "suspend" << QString::number(wid)); + } + xdgScreensaver.waitForFinished(); +} + void SetDPMS(bool on) { +#ifdef __linux__ if (getPlatformName() != "xcb") { return; } -#ifdef ENABLE_X11 - Display* dpy = QX11Info::display(); + QProcess xsetProcess; + xsetProcess.setProcessChannelMode(QProcess::ForwardedChannels); if (on) { - DPMSEnable(dpy); qDebug() << "Enabled DPMS."; + xsetProcess.start("xset", + QStringList() << "s" + << "on" + << "+dpms"); } else { - DPMSDisable(dpy); qDebug() << "Disabled DPMS."; + xsetProcess.start("xset", + QStringList() << "s" + << "off" + << "-dpms"); } -#endif -} -void -ResetScreensaver() -{ -#ifdef ENABLE_X11 - Display* display = QX11Info::display(); - XResetScreenSaver(display); + xsetProcess.waitForFinished(); +#else + qDebug() << "Can't set DPMS for platform: " << getPlatformName(); #endif } void AlwaysOnTop(WId wid, bool on) { +#ifdef __linux__ #ifdef ENABLE_X11 Display* display = QX11Info::display(); XEvent event; @@ -118,27 +132,8 @@ AlwaysOnTop(WId wid, bool on) SubstructureRedirectMask | SubstructureNotifyMask, &event); #endif -} - #else - -void -AlwaysOnTop(WId wid, bool on) -{ qDebug() << "Can't set on top for platform: " << getPlatformName(); -} - -void -SetDPMS(bool on) -{ - qDebug() << "Can't set DPMS for platform: " << getPlatformName(); -} - -void -ResetScreensaver() -{ - qDebug() << "Can't reset screensaver for: " << getPlatformName(); -} - #endif } +} diff --git a/src/utils.hpp b/src/utils.hpp index 3dd59a0..dd3385e 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -10,13 +10,13 @@ Q_NAMESPACE void SetDPMS(bool on); void +SetScreensaver(WId wid, bool on); +void AlwaysOnTop(WId wid, bool on); void updateAppImage(); QString createTimestamp(int seconds); -void -ResetScreensaver(); } class UtilsClass : public QObject @@ -30,7 +30,6 @@ public slots: { return Utils::createTimestamp(seconds); }; - void ResetScreensaver() { Utils::ResetScreensaver(); }; }; #endif