Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

X11: Report CursorMoved when touch event occurs #1297

Merged
merged 6 commits into from
Dec 12, 2019

Conversation

murarth
Copy link
Contributor

@murarth murarth commented Nov 30, 2019

Closes #1261

  • Tested on all platforms changed
  • Compilation warnings were addressed
  • cargo fmt has been run on this branch
  • cargo doc builds successfully
  • Added an entry to CHANGELOG.md if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality
  • Updated feature matrix, if new features were added or implemented

@murarth
Copy link
Contributor Author

murarth commented Dec 6, 2019

@dhardy Can you confirm that this PR resolves the issue?

@dhardy
Copy link
Contributor

dhardy commented Dec 7, 2019

Ah, sorry. Yes, it does, but it causes another more subtle bug because now all touch events fire CursorMoved events (potentially leaving my UI highlighting the wrong button after multiple touch events end).

The solution would be to only fire CursorMoved events for the "first" touch event (i.e. where no other touch id was active at the touch start time).

@murarth
Copy link
Contributor Author

murarth commented Dec 7, 2019

@dhardy I've implemented the fix you described. Does everything seem to be working as expected now?

@dhardy
Copy link
Contributor

dhardy commented Dec 7, 2019

I tested the commit I made and it worked perfectly, but I just tested this version and it doesn't. The issue is that first_touch will set a new id as soon as the previous "first touch" ends; to match X11 behaviour only a new touch (i.e. Phase::Begin) should be able to become a "first touch".

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.

@murarth
Copy link
Contributor Author

murarth commented Dec 7, 2019

@dhardy Oh, what a silly mistake on my part. I'm glad you caught it. I've pushed another fix.

@dhardy
Copy link
Contributor

dhardy commented Dec 7, 2019

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).

Copy link
Contributor

@dhardy dhardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@@ -1216,3 +1241,19 @@ impl<T: 'static> EventProcessor<T> {
}
}
}

fn is_first_touch(m: &mut HashSet<u64>, id: u64, phase: TouchPhase) -> bool {
let is_first = m.is_empty();
Copy link
Contributor

@dhardy dhardy Dec 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is incorrect except on TouchPhase::Started.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed again. Hopefully.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@goddessfreya goddessfreya self-requested a review December 8, 2019 17:16
@dhardy
Copy link
Contributor

dhardy commented Dec 9, 2019

Is there any reason you keep re-writing my patches? I already tested mine, now I have to test this one too.

@murarth
Copy link
Contributor Author

murarth commented Dec 9, 2019

@dhardy I didn't realize you were writing any patches. It seems we each arrived at the same solution independently.

@dhardy
Copy link
Contributor

dhardy commented Dec 9, 2019

The first I created a pull-request against your fork, and the second I linked above.

@murarth
Copy link
Contributor Author

murarth commented Dec 9, 2019

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.

Copy link
Contributor

@dhardy dhardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@murarth
Copy link
Contributor Author

murarth commented Dec 10, 2019

@goddessfreya I believe this PR is now ready for review.

Copy link
Contributor

@goddessfreya goddessfreya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm if it works for @dhardy

@murarth murarth merged commit 1f81e5c into rust-windowing:master Dec 12, 2019
@murarth murarth deleted the x11-touch-cursor-moved branch December 12, 2019 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C - waiting on maintainer A maintainer must review this code DS - x11
Development

Successfully merging this pull request may close these issues.

On X11, touch events can move the cursor without CursorMoved event
3 participants