[vlc-commits] [Git][videolan/vlc][master] qml: Safeguard Keys.onReleased events

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Mon Jun 20 08:20:21 UTC 2022



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
d695e4fa by Benjamin Arnaud at 2022-06-20T07:56:31+00:00
qml: Safeguard Keys.onReleased events

fix #25598

- - - - -


9 changed files:

- modules/gui/qt/medialibrary/qml/EmptyLabel.qml
- modules/gui/qt/player/qml/Player.qml
- modules/gui/qt/player/qml/PlayerMenuItem.qml
- modules/gui/qt/player/qml/controlbarcontrols/ArtworkInfoWidget.qml
- modules/gui/qt/player/qml/controlbarcontrols/VolumeWidget.qml
- modules/gui/qt/widgets/qml/KeyNavigableGridView.qml
- modules/gui/qt/widgets/qml/KeyNavigableListView.qml
- modules/gui/qt/widgets/qml/ListItem.qml
- modules/gui/qt/widgets/qml/SearchBox.qml


Changes:

=====================================
modules/gui/qt/medialibrary/qml/EmptyLabel.qml
=====================================
@@ -32,6 +32,8 @@ FocusScope {
     property alias coverWidth: coverContainer.width
     property alias coverHeight: coverContainer.height
 
+    property bool _keyPressed: false
+
     Column {
         anchors.verticalCenter: parent.verticalCenter
         width: root.width
@@ -86,11 +88,23 @@ FocusScope {
     }
 
     Keys.priority: Keys.AfterItem
-    Keys.onPressed: Navigation.defaultKeyAction(event)
+
+    Keys.onPressed: {
+        _keyPressed = true
+
+        Navigation.defaultKeyAction(event)
+    }
+
     Keys.onReleased: {
+        if (_keyPressed === false)
+            return
+
+        _keyPressed = false
+
         if (KeyHelper.matchOk(event)) {
             History.push(["mc", "network"])
         }
+
         Navigation.defaultKeyReleaseAction(event)
     }
 }


=====================================
modules/gui/qt/player/qml/Player.qml
=====================================
@@ -56,6 +56,8 @@ FocusScope {
     readonly property VLCColors colors: (MainCtx.hasEmbededVideo) ? VLCStyle.nightColors
                                                                   : VLCStyle.colors
 
+    property bool _keyPressed: false
+
     // Events
 
     Component.onCompleted: MainCtx.preferHotkeys = true
@@ -65,6 +67,9 @@ FocusScope {
     Keys.onPressed: {
         if (event.accepted)
             return
+
+        _keyPressed = true
+
         rootPlayer.Navigation.defaultKeyAction(event)
 
         //unhandled keys are forwarded as hotkeys
@@ -73,8 +78,11 @@ FocusScope {
     }
 
     Keys.onReleased: {
-        if (event.accepted)
+        if (event.accepted || _keyPressed === false)
             return
+
+        _keyPressed = false
+
         if (event.key === Qt.Key_Menu) {
             toolbarAutoHide.toggleForceVisible()
         } else {


=====================================
modules/gui/qt/player/qml/PlayerMenuItem.qml
=====================================
@@ -31,6 +31,10 @@ import "qrc:///widgets/" as Widgets
 T.MenuItem {
     id: control
 
+    property Item parentMenu: null
+
+    property bool _keyPressed: false
+
     //implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
     //                        implicitContentWidth + leftPadding + rightPadding)
     implicitHeight: contentId.implicitHeight + topPadding + bottomPadding
@@ -46,8 +50,6 @@ T.MenuItem {
 
     leftPadding: VLCStyle.applicationHorizontalMargin
 
-    property Item parentMenu: null
-
     //workaround QTBUG-7018 for Qt < 5.12.2
     activeFocusOnTab: control.enabled
 
@@ -128,9 +130,17 @@ T.MenuItem {
         event.accepted = false
     }
 
+    Keys.onPressed: _keyPressed = true
+
     Keys.onReleased: {
+        if (_keyPressed === false)
+            return
+
+        _keyPressed = false
+
         if (KeyHelper.matchCancel(event)) {
             event.accepted = true
+
             parentMenu.dismiss()
         }
     }


=====================================
modules/gui/qt/player/qml/controlbarcontrols/ArtworkInfoWidget.qml
=====================================
@@ -36,19 +36,30 @@ AbstractButton {
 
     readonly property real minimumWidth: cover.width + (leftPadding + rightPadding)
 
+    property bool _keyPressed: false
+
     padding: VLCStyle.focus_border
 
     Keys.onPressed: {
-        if (KeyHelper.matchOk(event))
+        if (KeyHelper.matchOk(event)) {
             event.accepted = true
 
-        Navigation.defaultKeyAction(event)
+            _keyPressed = true
+        } else {
+            Navigation.defaultKeyAction(event)
+        }
     }
 
     Keys.onReleased: {
+        if (_keyPressed === false)
+            return
+
+        _keyPressed = false
+
         if (KeyHelper.matchOk(event)) {
-            g_mainDisplay.showPlayer()
             event.accepted = true
+
+            g_mainDisplay.showPlayer()
         }
     }
 


=====================================
modules/gui/qt/player/qml/controlbarcontrols/VolumeWidget.qml
=====================================
@@ -93,6 +93,8 @@ T.Pane {
 
             property real _clamp: 0.01
 
+            property bool _keyPressed: false
+
             from: 0
             to: maxvolpos
             opacity: _player.muted ? 0.5 : 1
@@ -102,12 +104,19 @@ T.Pane {
             Keys.onPressed: {
                 if (KeyHelper.matchOk(event)) {
                     event.accepted = true
+
+                    _keyPressed = true
                 } else {
                     Navigation.defaultKeyAction(event)
                 }
             }
 
             Keys.onReleased: {
+                if (_keyPressed === false)
+                    return
+
+                _keyPressed = false
+
                 if (KeyHelper.matchOk(event)) {
                     Player.muted = !Player.muted
                 }


=====================================
modules/gui/qt/widgets/qml/KeyNavigableGridView.qml
=====================================
@@ -62,6 +62,10 @@ FocusScope {
     GridView {
         id: view
 
+        property int _colCount: Math.floor(width / cellWidth)
+
+        property bool _keyPressed: false
+
         anchors.fill: parent
 
         clip: true
@@ -72,8 +76,6 @@ FocusScope {
         //key navigation is reimplemented for item selection
         keyNavigationEnabled: false
 
-        property int _colCount: Math.floor(width / cellWidth)
-
         Util.FlickableScrollHandler { }
 
         Keys.onPressed: {
@@ -101,6 +103,8 @@ FocusScope {
             } else if (KeyHelper.matchOk(event) || event.matches(StandardKey.SelectAll) ) {
                 //these events are matched on release
                 event.accepted = true
+
+                _keyPressed = true
             }
 
             if (newIndex >= 0 && newIndex < modelCount && newIndex != currentIndex) {
@@ -115,6 +119,11 @@ FocusScope {
         }
 
         Keys.onReleased: {
+            if (_keyPressed === false)
+                return
+
+            _keyPressed = false
+
             if (event.matches(StandardKey.SelectAll)) {
                 event.accepted = true
                 selectAll()


=====================================
modules/gui/qt/widgets/qml/KeyNavigableListView.qml
=====================================
@@ -92,6 +92,10 @@ ListView {
         }
     }
 
+    // Private
+
+    property bool _keyPressed: false
+
     // Aliases
 
     //forward view properties
@@ -227,9 +231,11 @@ ListView {
             }
         }
 
-        if (KeyHelper.matchOk(event) || event.matches(StandardKey.SelectAll) ) {
-            //these events are matched on release
+        // these events are matched on release
+        if (event.matches(StandardKey.SelectAll) || KeyHelper.matchOk(event)) {
             event.accepted = true
+
+            _keyPressed = true
         }
 
         var oldIndex = currentIndex
@@ -256,10 +262,15 @@ ListView {
     }
 
     Keys.onReleased: {
+        if (_keyPressed === false)
+            return
+
+        _keyPressed = false
+
         if (event.matches(StandardKey.SelectAll)) {
             event.accepted = true
             selectAll()
-        } else if ( KeyHelper.matchOk(event) ) { //enter/return/space
+        } else if (KeyHelper.matchOk(event)) { //enter/return/space
             event.accepted = true
             actionAtIndex(currentIndex)
         }


=====================================
modules/gui/qt/widgets/qml/ListItem.qml
=====================================
@@ -135,6 +135,9 @@ FocusScope {
                     }
                     FocusScope {
                         id: presentation
+
+                        property bool _keyPressed: false
+
                         Layout.fillHeight: true
                         Layout.fillWidth: true
                         focus: true
@@ -176,7 +179,14 @@ FocusScope {
                             root.Navigation.defaultNavigationLeft()
                         }
 
+                        Keys.onPressed: _keyPressed = true
+
                         Keys.onReleased: {
+                            if (_keyPressed === false)
+                                return
+
+                            _keyPressed = false
+
                             if (KeyHelper.matchOk(event)) {
                                 itemDoubleClicked(event.key, event.modifiers)
                             }


=====================================
modules/gui/qt/widgets/qml/SearchBox.qml
=====================================
@@ -102,6 +102,8 @@ FocusScope {
         TextField {
             id: textField
 
+            property bool _keyPressed: false
+
             anchors.top: parent.top
             anchors.bottom: parent.bottom
 
@@ -140,17 +142,27 @@ FocusScope {
             }
 
             Keys.priority: Keys.AfterItem
+
             Keys.onPressed: {
+                _keyPressed = true
+
                 //we don't want Navigation.cancelAction to match Backspace
                 if (event.matches(StandardKey.Backspace))
                     event.accepted = true
+
                 Navigation.defaultKeyAction(event)
             }
 
             Keys.onReleased: {
+                if (_keyPressed === false)
+                    return
+
+                _keyPressed = false
+
                 //we don't want Navigation.cancelAction to match Backspace
                 if (event.matches(StandardKey.Backspace))
                     event.accepted = true
+
                 Navigation.defaultKeyReleaseAction(event)
             }
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/d695e4facfc2ba13497731eda48e24ef7b7403b1

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/d695e4facfc2ba13497731eda48e24ef7b7403b1
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