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 focus request handling predictable. #948

Merged
merged 4 commits into from
May 21, 2020

Conversation

xStrom
Copy link
Member

@xStrom xStrom commented May 16, 2020

Focus request handling in master is somewhat unpredictable:

  • If a parent requests focus to start with, that wins regardless of further focus requests by children.
  • If a paren't doesn't request focus immediately, then the first child to request focus wins - maybe.
  • If a parent requests focus after passing events to children, then the parent wins.

This PR makes it a lot simpler to understand:

  • Whoever calls request_focus last will win.

This change makes it easier to build widget groups where both the parent and children are interested in focus. It will allow the parent to request focus before passing down the event if it's ok with not winning. With master the parent would have to track the children's interest in focus by its own means to not override it.

@xStrom xStrom added the S-needs-review waits for review label May 16, 2020
@cmyr cmyr self-requested a review May 17, 2020 13:33
Copy link
Member

@cmyr cmyr left a comment

Choose a reason for hiding this comment

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

Cool, I think this is a good solution to a hairy little problem.

self.request_focus = self.request_focus.or(child_state.request_focus);
self.timers.extend(&child_state.timers);
self.request_focus = child_state.request_focus.take().or(self.request_focus);
self.timers.extend(&mut child_state.timers.drain());
Copy link
Member

Choose a reason for hiding this comment

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

Was just looking at this yesterday; there's a small optimization we could make where if child has timers and we don't, we just do a mem::swap, which will save us an allocation?

@xStrom xStrom removed the S-needs-review waits for review label May 21, 2020
@xStrom xStrom merged commit e5e23c6 into linebender:master May 21, 2020
@xStrom xStrom deleted the multi-focus-req branch May 21, 2020 08:46
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.

2 participants