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

Make PointerTarget/KeyboardTarget/TouchTarget object-safe; use in Anvil #1334

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ids1024
Copy link
Member

@ids1024 ids1024 commented Feb 16, 2024

I've been thinking about how to simplify this code for a while. Implementations of these traits become particularly verbose with a more complicated shell like cosmic-comp: https://github.com/pop-os/cosmic-comp/blob/master/src/shell/focus/target.rs.

It turns out it can be make object-safe, so we can have a &dyn PointerTarget, if PartialEq and Clone requirements are moved out of the trait itself.

I still wonder if it could be better to use enums for input events instead of a million methods. Anyway, something to think about.

Leaving as a draft pending the other changes in input targets in #1326.

@codecov-commenter
Copy link

codecov-commenter commented Feb 16, 2024

Codecov Report

Attention: 23 lines in your changes are missing coverage. Please review.

Comparison is base (832dee8) 21.31% compared to head (44173d9) 21.35%.

Files Patch % Lines
anvil/src/focus.rs 25.80% 23 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1334      +/-   ##
==========================================
+ Coverage   21.31%   21.35%   +0.03%     
==========================================
  Files         156      156              
  Lines       25141    25095      -46     
==========================================
  Hits         5359     5359              
+ Misses      19782    19736      -46     
Flag Coverage Δ
wlcs-buffer 18.43% <0.00%> (+0.03%) ⬆️
wlcs-core 18.11% <0.00%> (+0.03%) ⬆️
wlcs-output 7.76% <0.00%> (+0.01%) ⬆️
wlcs-pointer-input 20.21% <25.80%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cmeissl
Copy link
Collaborator

cmeissl commented Feb 16, 2024

So, the reason for the removal of the PointerTarget/KeyboardTarget implementation of Window /Layer/... in #1326 is that these bypass the Grabs.

For example the default ClickGrab on the PointerHandle should make sure the pointer won't leave the surface that installed the grab. But with something like Window being the PointerTarget and dispatching the focus internally to different surfaces the grab only makes so the same Window is focused, but the actual rule is completely bypassed.

I did look into what cosmic is doing with the targets (turns out quite a lot in case of PointerTarget) for the past few days and procrastinated on how to resolve that without either making it a pain to use in cosmic or sacrifice the grab guarantees.

All I did so far in cosmic is shuffle around a few implementations and try out a few ideas.
My latest idea is based on the fact that the focus on the pointer is actually a stack and we might just should represent it as this. Basically what I have in mind is that we have some sort of focus stack where the top element is the final focus target. So if the pointer is above a surface inside a window inside a cosmic stack it would hold a reference from WlSurface->Window->CosmicStack. The focus stack would implement PointerTarget and its PartialEq implementation would compare equality of the last element of the stack. In addition to this PointerTarget would get a new function that is called when focus moves from one target to another instead of directly calling PointerTarget::leave and PointerTarget::enter. The stack class could also have some function to test if the stack contains some target, which would walk the stack and check if any items equals. The new focus moved function could then walk the old and new stack to find out what exactly left and entered.

This requires to resolve the whole focus stack when the pointer moves in cosmic, should make it possible to keep most of the other focus logic in cosmic as is while still fixing the grab stuff.

Feedback very welcome :)

I've been thinking about how to simplify this code for a while.
Implementations of these traits become particularly verbose with a more
complicated shell like cosmic-comp:
https://github.com/pop-os/cosmic-comp/blob/master/src/shell/focus/target.rs.

It turns out it can be made object-safe, so we can have a `&dyn
PointerTarget`, if `PartialEq` and `Clone` requirements are moved out of
the trait itself.

I still wonder if it could be better to use enums for input events
instead of a million methods. Anyway, something to think about.
@ids1024 ids1024 force-pushed the object-safe-target branch from 44173d9 to 179e750 Compare March 26, 2024 19:26
@ids1024 ids1024 changed the title Make PointerTarget/KeyboardTarget object-safe; use in Anvil Make PointerTarget/KeyboardTarget/TouchTarget object-safe; use in Anvil Mar 26, 2024
@ids1024 ids1024 marked this pull request as ready for review March 26, 2024 19:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants