[vlc-commits] [Git][videolan/vlc][master] 9 commits: qml: eliminate redundant player volume updates

Rémi Denis-Courmont (@Courmisch) gitlab at videolan.org
Sat Apr 30 11:11:56 UTC 2022



Rémi Denis-Courmont pushed to branch master at VideoLAN / VLC


Commits:
f67b2e49 by Fatih Uzunoglu at 2022-04-30T10:40:18+00:00
qml: eliminate redundant player volume updates

- - - - -
14468d0f by Fatih Uzunoglu at 2022-04-30T10:40:18+00:00
qml: implicitly adjust volume on left press in VolumeWidget

- - - - -
99105660 by Fatih Uzunoglu at 2022-04-30T10:40:18+00:00
qml: allow precise scrolling in VolumeWidget

- - - - -
906caeb7 by Fatih Uzunoglu at 2022-04-30T10:40:18+00:00
qt: accept volume up/down steps in player controller

- - - - -
c946d241 by Fatih Uzunoglu at 2022-04-30T10:40:18+00:00
qml: use backend functions for stepwise volume adjustment

- - - - -
76959c5a by Fatih Uzunoglu at 2022-04-30T10:40:18+00:00
qt: add missing equality check in `muted` property setter

- - - - -
cc9d0221 by Fatih Uzunoglu at 2022-04-30T10:40:18+00:00
qml: use visualFocus to show tooltip in volume widget

- - - - -
6d558939 by Fatih Uzunoglu at 2022-04-30T10:40:18+00:00
qml: use player volume in volume widget tooltip

- - - - -
5dc883e7 by Fatih Uzunoglu at 2022-04-30T10:40:18+00:00
qml: respect `qt-max-volume`

- - - - -


5 changed files:

- modules/gui/qt/maininterface/mainctx.cpp
- modules/gui/qt/maininterface/mainctx.hpp
- modules/gui/qt/player/player_controller.cpp
- modules/gui/qt/player/player_controller.hpp
- modules/gui/qt/player/qml/controlbarcontrols/VolumeWidget.qml


Changes:

=====================================
modules/gui/qt/maininterface/mainctx.cpp
=====================================
@@ -293,6 +293,8 @@ void MainCtx::loadPrefs(const bool callSignals)
 #endif
 
     loadFromVLCOption(m_smoothScroll, "qt-smooth-scrolling", &MainCtx::smoothScrollChanged);
+
+    loadFromVLCOption(m_maxVolume, "qt-max-volume", &MainCtx::maxVolumeChanged);
 }
 
 void MainCtx::loadFromSettingsImpl(const bool callSignals)


=====================================
modules/gui/qt/maininterface/mainctx.hpp
=====================================
@@ -174,6 +174,7 @@ class MainCtx : public QObject
     Q_PROPERTY(QWindow* intfMainWindow READ intfMainWindow CONSTANT FINAL)
     Q_PROPERTY(QScreen* screen READ screen NOTIFY screenChanged)
     Q_PROPERTY(bool useGlobalShortcuts READ getUseGlobalShortcuts WRITE setUseGlobalShortcuts NOTIFY useGlobalShortcutsChanged FINAL)
+    Q_PROPERTY(int maxVolume READ maxVolume NOTIFY maxVolumeChanged FINAL)
 
     // This Property only works if hasAcrylicSurface is set
     Q_PROPERTY(bool acrylicActive READ acrylicActive WRITE setAcrylicActive NOTIFY acrylicActiveChanged FINAL)
@@ -255,6 +256,7 @@ public:
     inline QScreen* screen() const { return intfMainWindow()->screen(); }
     inline bool getUseGlobalShortcuts() const { return m_useGlobalShortcuts; }
     void setUseGlobalShortcuts(bool useGlobalShortcuts );
+    inline int maxVolume() const { return m_maxVolume; };
 
     bool hasEmbededVideo() const;
     VideoSurfaceProvider* getVideoSurfaceProvider() const;
@@ -354,6 +356,8 @@ protected:
 
     bool m_preferHotkeys = false;
 
+    int m_maxVolume = 125;
+
 public slots:
     void toggleUpdateSystrayMenu();
     void showUpdateSystrayMenu();
@@ -433,6 +437,8 @@ signals:
     void screenChanged();
 
     void useGlobalShortcutsChanged( bool );
+    
+    void maxVolumeChanged();
 
 private:
     void loadPrefs(bool callSignals);


=====================================
modules/gui/qt/player/player_controller.cpp
=====================================
@@ -1556,23 +1556,25 @@ void PlayerController::setVolume(float volume)
     vlc_player_aout_SetVolume( d->m_player, volume );
 }
 
-void PlayerController::setVolumeUp()
+void PlayerController::setVolumeUp(int steps)
 {
     Q_D(PlayerController);
     vlc_player_locker lock{ d->m_player };
-    vlc_player_aout_IncrementVolume( d->m_player, 1, NULL );
+    vlc_player_aout_IncrementVolume( d->m_player, steps, NULL );
 }
 
-void PlayerController::setVolumeDown()
+void PlayerController::setVolumeDown(int steps)
 {
     Q_D(PlayerController);
     vlc_player_locker lock{ d->m_player };
-    vlc_player_aout_DecrementVolume( d->m_player, 1, NULL );
+    vlc_player_aout_DecrementVolume( d->m_player, steps, NULL );
 }
 
 void PlayerController::setMuted(bool muted)
 {
     Q_D(PlayerController);
+    if( d->m_muted == muted )
+        return;
     vlc_player_locker lock{ d->m_player };
     vlc_player_aout_Mute( d->m_player, muted );
 }


=====================================
modules/gui/qt/player/player_controller.hpp
=====================================
@@ -220,8 +220,8 @@ public slots:
     void toggleFullscreen();
 
     //aout properties
-    void setVolumeUp();
-    void setVolumeDown();
+    void setVolumeUp( int steps = 1 );
+    void setVolumeDown( int steps = 1 );
     void toggleMuted();
 
     //misc


=====================================
modules/gui/qt/player/qml/controlbarcontrols/VolumeWidget.qml
=====================================
@@ -89,7 +89,6 @@ T.Pane {
 
             from: 0
             to: maxvolpos
-            stepSize: 0.05
             opacity: _player.muted ? 0.5 : 1
 
             Accessible.name: I18n.qtr("Volume")
@@ -114,6 +113,11 @@ T.Pane {
                 volControl._inhibitPlayerVolumeUpdate = false
             }
 
+            function _adjustPlayerVolume() {
+                Player.muted = false
+                Player.volume = volControl.value
+            }
+
             Component.onCompleted: {
                 root.paintOnlyChanged.connect(_syncVolumeWithPlayer)
                 volControl._syncVolumeWithPlayer()
@@ -126,31 +130,23 @@ T.Pane {
                 onVolumeChanged: volControl._syncVolumeWithPlayer()
             }
 
-            Timer {
-                // useful for keyboard volume alteration
-                id: tooltipShower
-                running: false
-                repeat: false
-                interval: 1000
-            }
-
             Navigation.leftItem: volumeBtn
             Navigation.parentItem: root
 
             Keys.onUpPressed: {
-                volControl.increase()
-                tooltipShower.restart()
+                Player.muted = false
+                Player.setVolumeUp()
             }
 
             Keys.onDownPressed: {
-                volControl.decrease()
-                tooltipShower.restart()
+                Player.muted = false
+                Player.setVolumeDown()
             }
 
             Keys.priority: Keys.BeforeItem
 
             readonly property color sliderColor: (volControl.position > fullvolpos) ? colors.volmax : root.color
-            readonly property int maxvol: 125
+            readonly property int maxvol: MainCtx.maxVolume
             readonly property real fullvolpos: 100 / maxvol
             readonly property real maxvolpos: maxvol / 100
 
@@ -159,10 +155,7 @@ T.Pane {
                     return
 
                 if (!volControl._inhibitPlayerVolumeUpdate) {
-                    if (Player.muted)
-                        Player.muted = false
-
-                    Player.volume = volControl.value
+                    Qt.callLater(volControl._adjustPlayerVolume)
                 }
             }
 
@@ -171,9 +164,9 @@ T.Pane {
                 active: !paintOnly
 
                 sourceComponent: Widgets.PointingTooltip {
-                    visible: tooltipShower.running || sliderMouseArea.pressed || sliderMouseArea.containsMouse
+                    visible: sliderMouseArea.pressed || volControl.pressed || volControl.hovered || volControl.visualFocus
 
-                    text: Math.round(volControl.value * 100) + "%"
+                    text: Math.round(Player.volume * 100) + "%"
 
                     pos: Qt.point(handle.x + handle.width / 2, handle.y)
 
@@ -225,8 +218,7 @@ T.Pane {
                 id: sliderMouseArea
                 anchors.fill: parent
 
-                hoverEnabled: true
-                acceptedButtons: Qt.LeftButton | Qt.RightButton
+                acceptedButtons: Qt.RightButton
 
                 Component.onCompleted: {
                     positionChanged.connect(adjustVolume)
@@ -234,48 +226,57 @@ T.Pane {
                 }
 
                 function adjustVolume(mouse) {
-                    if (pressedButtons === Qt.LeftButton) {
-                        // The slider itself can handle this,
-                        // but then the top&bottom margins need to be
-                        // set there instead of here. Also, if handled
-                        // there stepSize will be respected.
-                        volControl.value = volControl.maxvolpos * (mouse.x - handle.width)
-                                                                / (sliderBg.width - handle.width)
-
-                        mouse.accepted = true
-                    } else if (pressedButtons === Qt.RightButton) {
-                        var pos = mouse.x * volControl.maxvolpos / width
-                        if (pos < 0.25)
-                            volControl.value = 0
-                        else if (pos < 0.75)
-                            volControl.value = 0.5
-                        else if (pos < 1.125)
-                            volControl.value = 1
-                        else
-                            volControl.value = 1.25
+                    var pos = mouse.x * volControl.maxvolpos / width
+                    if (pos < 0.25)
+                        volControl.value = 0
+                    else if (pos < 0.75)
+                        volControl.value = 0.5
+                    else if (pos < 1.125)
+                        volControl.value = 1
+                    else
+                        volControl.value = 1.25
+
+                    mouse.accepted = true
+                }
 
-                        mouse.accepted = true
+                onWheel: {
+                    var delta = 0, fineControl = false
+
+                    if ((Math.abs(wheel.pixelDelta.x) % 120 > 0) || (Math.abs(wheel.pixelDelta.y) % 120 > 0)) {
+                        if (Math.abs(wheel.pixelDelta.x) > Math.abs(wheel.pixelDelta.y))
+                            delta = wheel.pixelDelta.x
+                        else
+                            delta = wheel.pixelDelta.y
+                        fineControl = true
                     }
-                }
+                    else if (wheel.angleDelta.x)
+                        delta = wheel.angleDelta.x
+                    else if (wheel.angleDelta.y)
+                        delta = wheel.angleDelta.y
 
-                onPressed: {
-                    if (!volControl.activeFocus)
-                        volControl.forceActiveFocus(Qt.MouseFocusReason)
-                }
+                    if (delta === 0)
+                        return
 
-                onWheel: {
-                    var x = wheel.angleDelta.x
-                    var y = wheel.angleDelta.y
-
-                    if (x > 0 || y > 0) {
-                        volControl.increase()
-                        wheel.accepted = true
-                    } else if (x < 0 || y < 0) {
-                        volControl.decrease()
-                        wheel.accepted = true
-                    } else {
-                        wheel.accepted = false
+                    if (wheel.inverted)
+                        delta = -delta
+
+                    if (fineControl)
+                        volControl.value += 0.001 * delta
+                    else {
+                        // Degrees to steps for standard mouse
+                        delta = delta / 8 / 15
+
+                        var steps = Math.ceil(Math.abs(delta))
+
+                        Player.muted = false
+
+                        if (delta > 0)
+                            Player.setVolumeUp(steps)
+                        else
+                            Player.setVolumeDown(steps)
                     }
+
+                    wheel.accepted = true
                 }
             }
         }



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/346b2fb9b68ef9cb7da0e4daf757f6334c74c57d...5dc883e7461c6d90c35f741e4eaaf8447cc51609

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/346b2fb9b68ef9cb7da0e4daf757f6334c74c57d...5dc883e7461c6d90c35f741e4eaaf8447cc51609
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list