File: upstream_ed525755_lib-simplify-mouse-hover-handling.patch

package info (click to toggle)
milou 4%3A6.3.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 856 kB
  • sloc: cpp: 133; javascript: 3; makefile: 3; sh: 2
file content (131 lines) | stat: -rw-r--r-- 4,514 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
From ed5257558eeb994071be14a9c799d4a34e11e169 Mon Sep 17 00:00:00 2001
From: Christoph Wolk <cwo.kde@posteo.net>
Date: Wed, 12 Mar 2025 19:28:47 +0100
Subject: [PATCH] lib: simplify mouse hover handling

ResultsView/ResultDelegate do some complicated mouse interaction
handling: the delegate listens to a HoverHandler's pointChanged signal.
which updates in a lot of circumstances, and then filters based on
keeping track whether the mouse moved to not activate with keyboard-only
use. This doesn't work well if there is mixed keyboard/mouse use, where
arrow key navigation becomes useless almost as soon as the mouse is
involved. And it isn't really necessary in the first place, as the real
problem is connecting to such a busy signal.

Instead, we drop the whole state-tracking jazz and even the
HoverHandler, and just listen to the delegate's own hovered property.
hovered only updates after the mouse moves, so we get essentially
the same thing for free but without the edge case bugs.

BUG: 501350
FIXED-IN: 6.4.0
---
 lib/mousehelper.cpp        |  7 +------
 lib/mousehelper.h          |  2 --
 lib/qml/ResultDelegate.qml | 19 ++++++-------------
 lib/qml/ResultsView.qml    |  9 ---------
 4 files changed, 7 insertions(+), 30 deletions(-)

diff --git a/lib/mousehelper.cpp b/lib/mousehelper.cpp
index 33f49cf5..27e9b33b 100644
--- a/lib/mousehelper.cpp
+++ b/lib/mousehelper.cpp
@@ -22,11 +22,6 @@ MouseHelper::~MouseHelper()
 {
 }
 
-QPointF MouseHelper::globalMousePosition() const
-{
-    return QCursor::pos();
-}
-
 QVariantMap MouseHelper::generateMimeDataMap(QMimeData *data) const
 {
     QVariantMap dataMap;
@@ -63,4 +58,4 @@ QVariantMap MouseHelper::generateMimeDataMap(QMimeData *data) const
     }
 
     return dataMap;
-}
\ No newline at end of file
+}
diff --git a/lib/mousehelper.h b/lib/mousehelper.h
index 717e54eb..983ebedd 100644
--- a/lib/mousehelper.h
+++ b/lib/mousehelper.h
@@ -24,8 +24,6 @@ public:
     explicit MouseHelper(QObject *parent = nullptr);
     ~MouseHelper() override;
 
-    Q_INVOKABLE QPointF globalMousePosition() const;
-
     /*
      * Converts QMimeData to QVariantMap
      * @internal will be removed after https://codereview.qt-project.org/c/qt/qtdeclarative/+/491548
diff --git a/lib/qml/ResultDelegate.qml b/lib/qml/ResultDelegate.qml
index f5d8532f..86f45b57 100644
--- a/lib/qml/ResultDelegate.qml
+++ b/lib/qml/ResultDelegate.qml
@@ -81,6 +81,12 @@ PlasmaComponents3.ItemDelegate {
         resultDelegate.ListView.view.runCurrentIndex()
     }
 
+    onHoveredChanged: {
+        if (hovered) {
+            resultDelegate.ListView.view.currentIndex = index
+        }
+    }
+
     DragHandler {
         id: dragHandler
         parent: labelWrapper
@@ -115,19 +121,6 @@ PlasmaComponents3.ItemDelegate {
             }
         }
 
-        HoverHandler {
-            enabled: !resultDelegate.isCurrent
-            onPointChanged: {
-                // In case we display the history we have a QML ListView which does not have the moved property
-                if (!resultDelegate.ListView.view.hasOwnProperty("moved") || resultDelegate.ListView.view.moved) {
-                    resultDelegate.ListView.view.currentIndex = index
-                } else if (resultDelegate.ListView.view.mouseMovedGlobally()) {
-                    resultDelegate.ListView.view.moved = true
-                    resultDelegate.ListView.view.currentIndex = index
-                }
-            }
-        }
-
         // QTBUG-63395: DragHandler blocks ItemDelegate's clicked signal
         TapHandler {
             id: tapHandler
diff --git a/lib/qml/ResultsView.qml b/lib/qml/ResultsView.qml
index 85886dee..f933d6de 100644
--- a/lib/qml/ResultsView.qml
+++ b/lib/qml/ResultsView.qml
@@ -46,13 +46,6 @@ ListView {
     // be run when the model is populated
     property bool runAutomatically
 
-    // This is used to disable mouse selection if the user interacts only with keyboard
-    property bool moved: false
-    property point savedMousePosition: Milou.MouseHelper.globalMousePosition()
-    function mouseMovedGlobally() {
-        return savedMousePosition != Milou.MouseHelper.globalMousePosition();
-    }
-
     model: Milou.ResultsModel {
         id: resultModel
         limit: 15
@@ -91,8 +84,6 @@ ListView {
 
         function resetView() {
             listView.currentIndex = 0;
-            listView.moved = false;
-            listView.savedMousePosition = Milou.MouseHelper.globalMousePosition();
         }
     }
 
-- 
GitLab