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

Add Event::MouseLeave for windows #821

Merged
merged 7 commits into from
Apr 13, 2020

Conversation

teddemunnik
Copy link
Contributor

Adds a new new event MouseLeft, and implemented it for windows.
The purpose for this event is to give a possibility of the OS to notifiy the druid app that it is no longer going to receive mouse events for some time. Either because the mouse has left the window rect, or because another app is blocking the mouse cursor.

@xStrom
Copy link
Member

xStrom commented Apr 9, 2020

Maybe there's a better name than MouseLeft? That name just immediately makes me think of the left mouse button. 🤔

MouseLost could be similar length but less ambiguous. There's also MouseExited which seems a bit more cumbersome but still clear.

@teddemunnik
Copy link
Contributor Author

Good point, didn't think of the confusion with left mouse button.. I started with MouseLeave, but then noticed that MouseMoved is past tense. MouseLost sounds good to me!

@teddemunnik teddemunnik changed the title Add Event::MouseLeft for windows Add Event::MouseLost for windows Apr 9, 2020
@raphlinus
Copy link
Contributor

raphlinus commented Apr 9, 2020

I think we generally follow web terminology (in this case, mouseleave) unless there is compelling reason to do otherwise. Though now I see the inconsistency with "mousemoved" as opposed to "mousemove". Hmm.

@xStrom
Copy link
Member

xStrom commented Apr 9, 2020

Following web terms would be fine, except we don't with e.g. MouseMoved while web has mousemove.

@raphlinus
Copy link
Contributor

Following web terms would be fine, except we don't with e.g. MouseMoved while web has mousemove.

Indeed. Now I regret that.

@xStrom
Copy link
Member

xStrom commented Apr 9, 2020

Well it's not too late to change it to MouseMove but then there's the question of Event::WindowConnected. Might as well change that to WindowConnect then and have everything consistent.

@teddemunnik
Copy link
Contributor Author

Alright! MouseMove and MouseLeave sounds perfect to me as well. How about I change this PR to be MouseLeave and we potentially rename MouseMove and WindowConnected in a future change then?

@xStrom
Copy link
Member

xStrom commented Apr 9, 2020

Yes I agree with that naming plan @teddemunnik, split it into two PRs.

@teddemunnik teddemunnik changed the title Add Event::MouseLost for windows Add Event::MouseLeave for windows Apr 9, 2020
Copy link
Member

@xStrom xStrom left a comment

Choose a reason for hiding this comment

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

Here are some initial thoughts. I got some deeper thoughts around this whole situation, but I'll have to describe that later as I'm out of time right now.

if !s.has_mouse_focus && is_point_in_client_rect(hwnd, x, y) {
s.has_mouse_focus = true;
let mut desc = TRACKMOUSEEVENT {
cbSize: std::mem::size_of::<TRACKMOUSEEVENT>() as DWORD,
Copy link
Member

Choose a reason for hiding this comment

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

Let's use just mem::size_of instead of std::mem::size_of.

Comment on lines 630 to 627
if TrackMouseEvent(&mut desc) == FALSE {
warn!(
"failed to TrackMouseEvent: {}",
Error::Hr(HRESULT_FROM_WIN32(GetLastError()))
);
Copy link
Member

Choose a reason for hiding this comment

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

This is an interesting failure possibility. I think it might be better to set s.has_mouse_focus to false so that we'll try again on the next move event. Otherwise we'll forever be without this tracking.

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'm curious in what circumstances this call would fail, besides being passed wrong arguments. But good call with not setting has_mouse_focus.

Comment on lines 87 to 90
/// Called when the mouse has left the application area.
///
/// The `MouseLeave` event is propagated to the active widget, if
/// there is one, otherwise to hot widgets (see `HotChanged`).
MouseLeave,
Copy link
Member

Choose a reason for hiding this comment

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

the application area the window

Also the event will be propagated to both active and hot widgets. Multiple can be active, and hot widgets will receive this regardless of whether there are active.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's true, I copied the comment and behavior from MouseMove, but I think they don't match there either?

Copy link
Member

Choose a reason for hiding this comment

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

Probably remnants of an era where druid was single window or something.

@cmyr cmyr added the S-needs-review waits for review label Apr 10, 2020
@xStrom
Copy link
Member

xStrom commented Apr 11, 2020

As per the discussion in zulip let's make MouseLeave internal. Pending #826 this doesn't actually mean anything in terms of code. However let's at least add a note to the Event::MouseLeave documentation stating that it is internal and LifeCycle::HotChanged should be used instead.

@xStrom xStrom added S-waiting-on-author waits for changes from the submitter and removed S-needs-review waits for review labels Apr 11, 2020
Copy link
Member

@xStrom xStrom left a comment

Choose a reason for hiding this comment

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

Okay so #826 is moving forward a bit quicker than anticipated. As such I'll just merge this as is and deal with the event internalizing as part of #826.

@xStrom xStrom merged commit f3a755f into linebender:master Apr 13, 2020
@teddemunnik teddemunnik deleted the windows_mouse_leave branch May 9, 2020 21:56
@xStrom xStrom removed the S-waiting-on-author waits for changes from the submitter label May 15, 2020
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.

None yet

4 participants