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

input/seatop_default: properly notify pointer leave #5222

Merged
merged 1 commit into from
May 1, 2020

Conversation

nickdiego
Copy link
Contributor

Currently, clients receive wl_data_device::leave events only when the
pointer enters another surface, which leads to issues, such as #5220.
This happens because wlr_seat_pointer_notify_enter() is called when
handling motion events only for non-NULL surfaces.

Fixes #5220

if (edge & (WLR_EDGE_LEFT | WLR_EDGE_RIGHT)) {
cursor_set_image(cursor, "col-resize", NULL);
} else {
if (node && node->type == N_CONTAINER) {
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for you PR!

Why is this block changed? It would make git-bisect's life easier if only one line was modified to add a call to wlr_seat_pointer_notify_enter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess you mean git-blame here, right?

My motivation for this was readability, but TBH cursor_do_rebase() doesn't seem to be the correct place to notify enter/leave events. So, as an improvement I'd propose to either (1) move event notification out of this function to where it's called from, or (2) rename this function to better reflect what it actually does. wdyt?
Anyways, if you still prefer just to add the missing call, I'll proceed and do it :)

Thanks

Copy link
Member

Choose a reason for hiding this comment

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

I guess you mean git-blame here, right?

Yeah, git-blame too. When searching for the cause of a bug, it'll be harder if a commit contains unrelated refactoring.

move event notification out of this function to where it's called from

Interestingly, @Xyene suggested the same thing.

"Rebasing" here means that "update the pointer to be consistent with whatever is under it". It's used when changing the layout for instance, or after a TTY switch. If we remove enter/leave events from this function, we could rename it to something like cursor_update_image and re-use it from the tablet code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, git-blame too. When searching for the cause of a bug, it'll be harder if a commit contains unrelated refactoring.

Ack and done.

If we remove enter/leave events from this function, we could rename it to something like cursor_update_image and re-use it from the tablet code.

Sounds like something worth doing. Will send it in a followup patch soon.
Thanks

Copy link
Member

@Xyene Xyene Apr 23, 2020

Choose a reason for hiding this comment

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

👍

To summarize a discussion from IRC yesterday (since I imagine you might find it interesting):

  • the cursor/seat code predates tablet and touch specs, so is tightly coupled with pointers
  • this is "surprising", e.g. you'd expect functions like cursor_motion or cursor_do_rebase to not send pointer events, but they do
    • this means they're not used for tablet/touch support, instead both tablet and touch re-implement ad-hoc parts of that functionality
    • since fewer people use those input methods, it's easier for the code to fall behind without anyone noticing (or reporting)
  • tablet support, at least, currently has some issues1 that would likely best be fixed by decoupling the *cursor* functions from sending pointer events, and moving those events to the call sites

The plan proposed looks something like this:

  1. move the pointer events out of the cursor functions
  2. reuse them for tablet support — this'd fix a bunch of tablet issues
  3. for future maintainability, add handlers for tablet and touch into seatop, so that the logic for those devices can be migrated from cursor.c
  4. once everything's in one place rather than two and confirmed "not broken by refactoring", it'll be easier to see what abstractions make sense

1 There are more if you just search for "tablet", but these are the ones I know the cause of so far 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @Xyene, thanks for the info. It sounds like a good plan for me.

Copy link
Member

@emersion emersion left a comment

Choose a reason for hiding this comment

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

This one-liner already fixes a bug. Can you rebase and squash the commits?

Currently, clients receive wl_data_device::leave events only when the
pointer enters another surface, which leads to issues, such as swaywm#5220.
This happens because wlr_seat_pointer_notify_enter() is called when
handling motion events only for non-NULL surfaces.

Fixes swaywm#5220
@nickdiego
Copy link
Contributor Author

This one-liner already fixes a bug. Can you rebase and squash the commits?

Done. Thanks

@emersion
Copy link
Member

emersion commented May 1, 2020

Thanks for the fix!

@tchebb
Copy link
Contributor

tchebb commented May 7, 2020

This change caused wlroots to segfault on pointer leave when an xdg_shell popup is active. I've written up an analysis at swaywm/wlroots#2162, but the tl;dr is I think we should revert this until we fix the underlying issue.

@emersion
Copy link
Member

emersion commented May 7, 2020

Let's wait a little bit, I'll revert if we don't come up with a fix in a few days.

@travankor
Copy link

revert?

tchebb added a commit to tchebb/sway that referenced this pull request May 21, 2020
We are not allowed to do what we did in swaywm#5222 and pass a `NULL` surface
wlr_seat_pointer_notify_enter(), and it's causing crashes when an
xdg-shell popup is active (see swaywm#5294 and swaywm/wlroots#2161).

Instead, solve swaywm#5220 using the new wlroots API introduced in
swaywm/wlroots#2217.
emersion pushed a commit to swaywm/wlroots that referenced this pull request Jun 5, 2020
This is necessary for some grabs, which currently have no way of knowing
when the pointer/keyboard focus has left a surface. For example, without
this, a drag-and-drop grab can erroneously drop into a window that the
cursor is no longer over.

This is the plumbing needed to properly fix swaywm/sway#5220. The
existing fix, swaywm/sway#5222, relies on every grab's `enter()` hook
allowing a `NULL` surface. This is not guaranteed by the API and, in
fact, is not the case for the xdg-shell popup grab and results in a
crash when the cursor leaves a surface and does not immediately enter
another one while a popup is open (#2161).

This fix also adds an assertion to wlr_seat_pointer_notify_enter() that
ensures it's never called with a `NULL` surface. This will make Sway
crash much more until it fixes its usage of the API, so we should land
this at the same time as a fix in Sway (which I haven't posted yet).
emersion pushed a commit that referenced this pull request Jun 5, 2020
We are not allowed to do what we did in #5222 and pass a `NULL` surface
wlr_seat_pointer_notify_enter(), and it's causing crashes when an
xdg-shell popup is active (see #5294 and swaywm/wlroots#2161).

Instead, solve #5220 using the new wlroots API introduced in
swaywm/wlroots#2217.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

wl_data_device.leave events are not sent
5 participants