X11: Report CursorMoved when touch event occurs#1297
X11: Report CursorMoved when touch event occurs#1297murarth merged 6 commits intorust-windowing:masterfrom
CursorMoved when touch event occurs#1297Conversation
|
@dhardy Can you confirm that this PR resolves the issue? |
|
Ah, sorry. Yes, it does, but it causes another more subtle bug because now all touch events fire The solution would be to only fire |
|
@dhardy I've implemented the fix you described. Does everything seem to be working as expected now? |
|
I didn't think to test a third touch event started after the first ends (but while the second is still active). Both commits fail in this case. Instead, a touch should only be able to become a "first touch" if there are no other active touch events when it starts. |
|
@dhardy Oh, what a silly mistake on my part. I'm glad you caught it. I've pushed another fix. |
|
Just tested, and it passes my obscure test, but not the much simpler test of touch and drag across buttons: the first button remains highlighted. I will investigate tomorrow. (Also, touch-cancel events seem to be causing issues but this may be my UI). |
dhardy
left a comment
There was a problem hiding this comment.
Corrected version here (tested): https://github.com/dhardy/winit/commits/x11-touch-cursor-moved
I also took the liberty of removing that complicated data structure we don't actually need. Counting is enough in this case.
| } | ||
|
|
||
| fn is_first_touch(m: &mut HashSet<u64>, id: u64, phase: TouchPhase) -> bool { | ||
| let is_first = m.is_empty(); |
There was a problem hiding this comment.
This logic is incorrect except on TouchPhase::Started.
There was a problem hiding this comment.
Fixed again. Hopefully.
There was a problem hiding this comment.
Also, I changed the code from using a HashSet to a simple count of concurrent running touch events. As long as winit doesn't receive a duplicate Ended event, it should work as well as the HashSet.
|
Is there any reason you keep re-writing my patches? I already tested mine, now I have to test this one too. |
|
@dhardy I didn't realize you were writing any patches. It seems we each arrived at the same solution independently. |
|
The first I created a pull-request against your fork, and the second I linked above. |
|
Well, I'm sorry, but I didn't see either of those. I just saw the one comment on my code, so I wrote my own fix, which appears to have essentially the same logic. If you've tested your version and can confirm that it resolves the issue, I think this PR is ready to be reviewed and merged. |
There was a problem hiding this comment.
Anyway, the above below optimisation is irrelevant. I tested this code and it appears to work correctly, so this gets a 👍 and thanks for the effort!
(For what it's worth, the reason I didn't open a PR myself is that I was unsure if adding an X11-specific workaround was the correct thing to do.)
| } | ||
| TouchPhase::Cancelled | TouchPhase::Ended => { | ||
| if *first == Some(id) { | ||
| *first = None; |
There was a problem hiding this comment.
My understanding is that this is correct, but unnecessary: if num == 0 then first == Some(id) is never evaluated (except on TouchPhase::Ended for the last event, when the above ids are still valid). As soon as the next event starts, first is re-assigned. Thus in my version I didn't bother using an Option here.
|
@goddessfreya I believe this PR is now ready for review. |
goddessfreya
left a comment
There was a problem hiding this comment.
lgtm if it works for @dhardy
Closes #1261
cargo fmthas been run on this branchcargo docbuilds successfullyCHANGELOG.mdif knowledge of this change could be valuable to users