ソースを参照

Initial try at taskbar-local.

Ian Walton 3 年 前
コミット
b72c8084ab

+ 6 - 1
.vscode/settings.json

@@ -15,6 +15,11 @@
         "array": "cpp",
         "tuple": "cpp",
         "utility": "cpp",
-        "variant": "cpp"
+        "variant": "cpp",
+        "istream": "cpp",
+        "ostream": "cpp",
+        "ratio": "cpp",
+        "functional": "cpp",
+        "type_traits": "cpp"
     }
 }

+ 0 - 7
native/mpvAudioPlayer.js

@@ -65,7 +65,6 @@ class mpvAudioPlayer {
                 player.updateDuration.connect(onDuration);
                 player.error.connect(onError);
                 player.paused.connect(onPause);
-                window.api.taskbar.pauseClicked.connect(onPauseClicked);
             }
 
             return setCurrentSrc(options);
@@ -137,7 +136,6 @@ class mpvAudioPlayer {
             player.updateDuration.disconnect(onDuration);
             player.error.disconnect(onError);
             player.paused.disconnect(onPause);
-            window.api.taskbar.pauseClicked.disconnect(onPauseClicked);
         };
 
         function onDuration(duration) {
@@ -153,7 +151,6 @@ class mpvAudioPlayer {
             if (!self._isFadingOut) {
                 self._currentTime = time;
                 self.events.trigger(self, 'timeupdate');
-                window.api.taskbar.setProgress(time * 100 / self._duration);
             }
         }
 
@@ -190,10 +187,6 @@ class mpvAudioPlayer {
                 }
             ]);
         }
-
-        function onPauseClicked() {
-            self.paused() ? self.unpause() : self.pause();
-        }
     }
 
     getSavedVolume() {

+ 0 - 7
native/mpvVideoPlayer.js

@@ -126,7 +126,6 @@
 
                 this._currentTime = time;
                 this.events.trigger(this, 'timeupdate');
-                window.api.taskbar.setProgress(time * 100 / this._duration);
             };
 
             /**
@@ -208,10 +207,6 @@
             this.onDuration = (duration) => {
                 this._duration = duration;
             };
-
-            this.onPauseClicked = () => {
-                this.paused() ? this.unpause() : this.pause();
-            };
         }
 
         currentSrc() {
@@ -402,7 +397,6 @@
             player.updateDuration.disconnect(this.onDuration);
             player.error.disconnect(this.onError);
             player.paused.disconnect(this.onPause);
-            window.api.taskbar.pauseClicked.disconnect(this.onPauseClicked);
 
             const dlg = this._videoDialog;
             if (dlg) {
@@ -455,7 +449,6 @@
                     player.updateDuration.connect(this.onDuration);
                     player.error.connect(this.onError);
                     player.paused.connect(this.onPause);    
-                    window.api.taskbar.pauseClicked.connect(this.onPauseClicked);
                 }
 
                 if (options.fullscreen) {

+ 8 - 0
src/input/InputComponent.cpp

@@ -245,6 +245,14 @@ void InputComponent::executeActions(const QStringList& actions)
     handleAction(action);
 }
 
+/////////////////////////////////////////////////////////////////////////////////////////
+void InputComponent::sendAction(const QString action)
+{
+  QStringList actionsToSend;
+  actionsToSend.append(action);
+  emit hostInput(actionsToSend);
+}
+
 /////////////////////////////////////////////////////////////////////////////////////////
 void InputComponent::registerHostCommand(const QString& command, QObject* receiver, const char* slot)
 {

+ 1 - 0
src/input/InputComponent.h

@@ -106,6 +106,7 @@ public:
   // should be actually dispatched.
   Q_INVOKABLE void executeActions(const QStringList& actions);
   void cancelAutoRepeat();
+  void sendAction(const QString action);
 
 signals:
   // Always emitted when any input arrives

+ 9 - 0
src/player/PlayerComponent.cpp

@@ -949,6 +949,15 @@ qint64 PlayerComponent::getPosition()
   return 0;
 }
 
+/////////////////////////////////////////////////////////////////////////////////////////
+qint64 PlayerComponent::getDuration()
+{
+  QVariant time = mpv::qt::get_property(m_mpv, "duration");
+  if (time.canConvert(QMetaType::Double))
+    return time.toDouble();
+  return 0;
+}
+
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 // This is called with the set of previous audio devices that were detected, and the set of current
 // audio devices. From this we guess whether we should reopen the audio device. If the user-selected

+ 1 - 0
src/player/PlayerComponent.h

@@ -120,6 +120,7 @@ public:
   Q_INVOKABLE void setPlaybackRate(int rate);
 
   Q_INVOKABLE qint64 getPosition();
+  Q_INVOKABLE qint64 getDuration();
 
   QRect videoRectangle() { return m_videoRectangle; }
 

+ 0 - 4
src/taskbar/TaskbarComponent.h

@@ -22,12 +22,8 @@ public:
 
 public Q_SLOTS:
   virtual void setControlsVisible(bool value) {}
-  virtual void setProgress(int value) {}
   virtual void setPaused(bool value) {}
 
-Q_SIGNALS:
-  void pauseClicked();
-
 protected:
   QQuickWindow* m_window;
 };

+ 33 - 3
src/taskbar/TaskbarComponentWin.cpp

@@ -15,10 +15,23 @@ void TaskbarComponentWin::setWindow(QQuickWindow* window)
   m_toolbar = new QWinThumbnailToolBar(m_window);
   m_toolbar->setWindow(m_window);
 
+  m_prev = new QWinThumbnailToolButton(m_toolbar);
+  connect(m_prev, &QWinThumbnailToolButton::clicked, this, &TaskbarComponentWin::onPrevClicked);
+
   m_pause = new QWinThumbnailToolButton(m_toolbar);
   connect(m_pause, &QWinThumbnailToolButton::clicked, this, &TaskbarComponentWin::onPauseClicked);
 
+  m_next = new QWinThumbnailToolButton(m_toolbar);
+  connect(m_next, &QWinThumbnailToolButton::clicked, this, &TaskbarComponentWin::onNextClicked);
+
+  m_prev->setIcon(QApplication::style()->standardIcon(QStyle::SP_MediaSkipBackward));
+  m_next->setIcon(QApplication::style()->standardIcon(QStyle::SP_MediaSkipForward));
+
+  m_toolbar->addButton(m_prev);
   m_toolbar->addButton(m_pause);
+  m_toolbar->addButton(m_next);
+
+  connect(&PlayerComponent::Get(), &PlayerComponent::positionUpdate, this, &TaskbarComponentWin::setProgress);
 
   setControlsVisible(false);
   setPaused(false);
@@ -27,7 +40,19 @@ void TaskbarComponentWin::setWindow(QQuickWindow* window)
 /////////////////////////////////////////////////////////////////////////////////////////
 void TaskbarComponentWin::onPauseClicked()
 {
-  emit pauseClicked();
+  InputComponent::Get().sendAction("play_pause");
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+void TaskbarComponentWin::onNextClicked()
+{
+  InputComponent::Get().sendAction("next");
+}
+
+/////////////////////////////////////////////////////////////////////////////////////////
+void TaskbarComponentWin::onPrevClicked()
+{
+  InputComponent::Get().sendAction("previous");
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////
@@ -42,9 +67,14 @@ void TaskbarComponentWin::setControlsVisible(bool value)
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////
-void TaskbarComponentWin::setProgress(int value)
+void TaskbarComponentWin::setProgress(quint64 value)
 {
-  m_button->progress()->setValue(value);
+  qint64 duration = PlayerComponent::Get().getDuration();
+  int progress = 0;
+  if (duration != 0) {
+    progress = (int) (value * 100 / duration)
+  }
+  m_button->progress()->setValue(progress);
 }
 
 /////////////////////////////////////////////////////////////////////////////////////////

+ 5 - 1
src/taskbar/TaskbarComponentWin.h

@@ -14,17 +14,21 @@ class TaskbarComponentWin : public TaskbarComponent
 public:
   TaskbarComponentWin(): TaskbarComponent(nullptr) {}
   virtual void setControlsVisible(bool value) override;
-  virtual void setProgress(int value) override;
   virtual void setPaused(bool value) override;
 
   virtual void setWindow(QQuickWindow* window) override;
 
 private:
   void onPauseClicked();
+  void onPrevClicked();
+  void onNextClicked();
+  virtual void setProgress(quint64 value) override;
 
   QWinTaskbarButton* m_button;
   QWinThumbnailToolBar* m_toolbar;
   QWinThumbnailToolButton* m_pause;
+  QWinThumbnailToolButton* m_prev;
+  QWinThumbnailToolButton* m_next;
 };
 
 #endif // TASKBARCOMPONENTWIN_H