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

touch re-factor #1326

Merged
merged 4 commits into from
Feb 23, 2024
Merged

touch re-factor #1326

merged 4 commits into from
Feb 23, 2024

Conversation

cmeissl
Copy link
Collaborator

@cmeissl cmeissl commented Feb 11, 2024

The current implementation has a few limitations and does not provide an abstraction on the same level as pointer or keyboard. For proper support including DnD we also need to support grabs.

This also removes the implementation of PointerTarget and KeyboardTarget on the desktop abstractions. I described the motivation behind this here
The last commit also implements the base for the idea mentioned in the above comment.

@Drakulix
Copy link
Member

As noted in matrix previously, I am not yet convinced, that dropping the KeyboardHandler/PointerHandler traits is the right move for more complex cases of in-compositor UI elements.

But I guess the only way to figure this out, is to implement it. And apart from that I do agree with the general structure.

@cmeissl cmeissl force-pushed the feature/touch branch 3 times, most recently from ad75176 to 846b662 Compare February 13, 2024 19:41
@codecov-commenter
Copy link

codecov-commenter commented Feb 13, 2024

Codecov Report

Attention: Patch coverage is 2.85714% with 1496 lines in your changes are missing coverage. Please review.

Project coverage is 20.38%. Comparing base (288ba1a) to head (e29f8be).

Files Patch % Lines
src/input/touch/mod.rs 0.00% 279 Missing ⚠️
anvil/src/shell/grabs.rs 0.00% 219 Missing ⚠️
anvil/src/focus.rs 2.53% 154 Missing ⚠️
src/wayland/selection/data_device/dnd_grab.rs 0.00% 149 Missing ⚠️
...c/wayland/selection/data_device/server_dnd_grab.rs 0.00% 141 Missing ⚠️
src/input/touch/grab.rs 0.00% 107 Missing ⚠️
anvil/src/shell/xdg.rs 0.00% 101 Missing ⚠️
anvil/src/shell/element.rs 10.28% 96 Missing ⚠️
src/wayland/seat/touch.rs 0.00% 68 Missing ⚠️
anvil/src/shell/ssd.rs 0.00% 61 Missing ⚠️
... and 6 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1326      +/-   ##
==========================================
- Coverage   21.23%   20.38%   -0.86%     
==========================================
  Files         156      158       +2     
  Lines       25023    25818     +795     
==========================================
- Hits         5313     5262      -51     
- Misses      19710    20556     +846     
Flag Coverage Δ
wlcs-buffer 17.79% <0.06%> (-0.58%) ⬇️
wlcs-core 17.46% <0.06%> (-0.57%) ⬇️
wlcs-output 7.54% <0.06%> (-0.25%) ⬇️
wlcs-pointer-input 19.23% <2.85%> (-0.82%) ⬇️

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.

FocusTarget::Popup(p) => PointerTarget::enter(p.wl_surface(), seat, data, event),
PointerFocusTarget::WlSurface(w) => PointerTarget::enter(w, seat, data, event),
#[cfg(feature = "xwayland")]
PointerFocusTarget::X11Surface(w) => PointerTarget::enter(w, seat, data, event),
Copy link
Member

Choose a reason for hiding this comment

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

If Window/LayerSurface/Popup can be combined as just WlSurface, shouldn't that also cover X11Surface?

It seems PointerTarget<D> for X11Surface just calls PointerTarget methods on the underlying WlSurface, if it exists.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that would be possible, but it felt strange to leave the KeyboardTarget impl there (which does a few x related stuff) and only remove the PointerTarget impl.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, fair point.

ids1024 added a commit to ids1024/smithay that referenced this pull request 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
Smithay#1326.
ids1024 added a commit to ids1024/smithay that referenced this pull request 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
Smithay#1326.
@cmeissl
Copy link
Collaborator Author

cmeissl commented Feb 16, 2024

Linking to #1334 (comment) as it contains some background info about my motivation behind removing the PointerTarget`KeyboardTargetimpls onWindow` and so on.
(Also includes some proposal on how to solve the focus issue, feedback welcome)

@cmeissl cmeissl force-pushed the feature/touch branch 2 times, most recently from 679b4b7 to 5151f2f Compare February 18, 2024 18:38
@cmeissl cmeissl marked this pull request as ready for review February 18, 2024 18:45
Copy link
Member

@Drakulix Drakulix left a comment

Choose a reason for hiding this comment

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

Liking this a lot, I am quite confident, that this state of the api will work with cosmic-comp.

@ids1024
Copy link
Member

ids1024 commented Feb 20, 2024

So the idea is that a compositor (like cosmic-comp) would have some concept of a focus stack, without such a thing existing explicitly in smithay itself? Makes sense for that to be represented as a stack, though I don't know exactly how that will end up looking.

It's good to have touch brought up to parity with keyboard/pointer.

@cmeissl
Copy link
Collaborator Author

cmeissl commented Feb 21, 2024

So the idea is that a compositor (like cosmic-comp) would have some concept of a focus stack, without such a thing existing explicitly in smithay itself?

For the moment, yes. Though cnce we figure out a generic way to represent it we probably should add an abstraction to smithay.

especially the pointer target is problematic as
it dispatches the pointer target to surfaces based
on the location of the pointer. this can break
guarantees a grab tries to enforce.
this brings touch handling to the same level as we
already provide for pointer and keyboard.
the default touch grab will invoke the touch
down grab which will keep the focus on a single
surface. while this is a sane default downstream
might want to override this behavior.
this adds a new function to PointerTarget that
is called when the focus is replaced. this allows
implementing a nested stack of focus targets
without sacrificing grab guarantees.

the default impl will do the same like the old
behavior, so call leave on the previous target
and enter on the new one.
Copy link
Member

@Drakulix Drakulix left a comment

Choose a reason for hiding this comment

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

Lacking a touch-device to properly test this, but code wise LGTM!

@Drakulix Drakulix merged commit 8230d5d into Smithay:master Feb 23, 2024
13 checks passed
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.

4 participants