Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upHit testing is offset in GL aquarium #21168
Comments
|
I think hit testing is broken in general, I see this behavior on every site. I think it may be related to hidpi screens; servo thinks the mouse is in the center of the window when its actually on the far right. |
|
I can also reproduce this on Linux - I'll investigate today. |
|
It looks like something has changed to do with how / where DPI scaling is applied, either in Servo or in Glutin / Winit. Specifically, in the hit test method in As a quick hack, I applied the following patch:
This appears to fix hit testing on my Linux machine in the tests I've tried thus far. @jdm or @cbrewster Would you be able to check if this also fixes it on a Mac? If it does, the proper fix will involve working out what changed and either restoring the previous behavior (so we are getting a true DevicePoint in this method) or modifying the method and signatures to reflect that it is no longer a DevicePoint. We'll still need to handle other scale factors, such as page zoom, which I've ignored in the patch above for now. |
|
@gw3583 Yes, that patch fixes the issue for me as well. |
|
This might be due to the winit/glutin update in #21087. There were some HiDPI changes there: https://github.com/tomaka/winit/blob/master/CHANGELOG.md |
|
@jdm OK, I confirmed the issue is from #21087. It looks like winit now returns events in logical units, rather than device units. That patch will need to be re-worked in order to handle this - it looks like it gets logical / device units confused in a few places, by constructing those types directly from the scalar values, I think. |
|
Thanks for investigating! |
diff --git a/ports/servo/glutin_app/window.rs b/ports/servo/glutin_app/window.rs
index 514b1f8c07..75c5ac29d0 100644
--- a/ports/servo/glutin_app/window.rs
+++ b/ports/servo/glutin_app/window.rs
@@ -493,12 +493,14 @@ impl Window {
},
Event::WindowEvent {
event: winit::WindowEvent::CursorMoved {
- position: LogicalPosition { x, y },
+ position,
..
},
..
} => {
- self.mouse_pos.set(TypedPoint2D::new(x as i32, y as i32));
+ let pos = position.to_physical(self.hidpi_factor().get() as f64);
+ let (x, y): (i32, i32) = pos.into();
+ self.mouse_pos.set(TypedPoint2D::new(x, y));
self.event_queue.borrow_mut().push(
WindowEvent::MouseWindowMoveEventClass(TypedPoint2D::new(x as f32, y as f32)));This change fixed the hit testing for me. |
Fix hittesting on HiDPI screens This fixes some regressions introduced in #21087 due to treating logical coordinates as physical ones without converting between them correctly. --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #21168 - [x] These changes do not require tests because we do not have the ability to test embedding input yet. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21190) <!-- Reviewable:end -->
Fix hittesting on HiDPI screens This fixes some regressions introduced in #21087 due to treating logical coordinates as physical ones without converting between them correctly. --- - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [x] These changes fix #21168 - [x] These changes do not require tests because we do not have the ability to test embedding input yet. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/21190) <!-- Reviewable:end -->
https://webglsamples.org/aquarium/aquarium.html
When I try to click the numbers, there is a clear vertical offset (like 100px or more) that I need to compensate for to click the numbers I intend.