Skip to content

Standardize window closing API#362

Merged
cmyr merged 1 commit intomasterfrom
window-will-close
Dec 12, 2019
Merged

Standardize window closing API#362
cmyr merged 1 commit intomasterfrom
window-will-close

Conversation

@cmyr
Copy link
Member

@cmyr cmyr commented Nov 28, 2019

We want to be notified when a window closes. For this to work we need
to handle the destroy() method in WinHandler.

After making this change, we ended up with two code paths for closing
windows: one for when we were closing the window ourselves (for
instance, when manually handling a menu command) and a second for when
we were closed by the system, such as when the user clicked on the
window's 'close' button. (all examples macOS).

This unifies these two cases; when we want to close a window we
call the WindowHandle's close method, which begins the platform
close routine; as part of this we are called back (at destroy())
and then we have a single place to handle cleaning up state
and posting the appropriate events.


  • this was motivated by runebender stuff; I only want a glyph open in a single window at once, which means i need to accurately know when a window has closed.

  • This will likely require work on win and gtk; I'm not sure if either of those platforms is correctly posting destroy().

We want to be notified when a window closes. For this to work we need
to handle the destroy() method in WinHandler.

After making this change, we ended up with two code paths for closing
windows: one for when we were closing the window ourselves (for
instance, when manually handling a menu command) and a second for when
we were closed by the system, such as when the user clicked on the
window's 'close' button. (all examples macOS).

This unifies these two cases; when we want to close a window we
call the WindowHandle's close method, which begins the platform
close routine; as part of this we are called back (at destroy())
and then we have a single place to handle cleaning up state
and posting the appropriate events.
@xStrom
Copy link
Member

xStrom commented Dec 3, 2019

I'm just starting my journey to understand druid internals, but I think the Windows platform code already triggers the destroying message.

I've been looking for window closing related functionality in druid but as best as I can make out, significant parts of it are not implemented yet. Standardizing on one single place to handle cleanup is definitely a good step forward. I have some additional thoughts here but my knowledge is mostly Windows based and I may be lacking understanding of druid given that I just started learning it. Also I don't want to balloon the scope of this PR any more than necessary, but for now this seems like an on-topic place to comment.

Exiting the RunLoop when all windows have been destroyed

On the surface this seems like a good idea to me. Currently the process keeps on running even after all the windows have been destroyed. Is there some specific reason why the runloop keeps going or is this just a matter of not having been implemented yet?

Edit: Found #265 which touches on this, although very light on details.

Handling user requested window close events, e.g. WM_CLOSE on Windows

Currently WM_CLOSE is handled by DefWindowProc which just destroys the window. To enable Exit without saving? type confirmations we should handle the WM_CLOSE event. My initial thought is that this should be translated into some sort of platform independent event. If the client application handles the event, then its their job to eventually destroy the window, or not. If the event is not handled then druid can fall back to destroying the window.

Edit: Found #296 which touches on this.

@cmyr
Copy link
Member Author

cmyr commented Dec 3, 2019

The reason a bunch of this stuff hasn't been implemented is because there are significant differences in expected behaviour on different platforms.

on windows, yes, we should terminate the application when the last window closes. We could implement this today, specifically for windows, with little trouble.

on mac, an application is not terminated by closing its windows; it can still be interacted with the menubar or the dock icon (and various other ways). Making this work correctly is what motivates #114.

I'm not sure about other platforms, e.g. GTK.

I agree that we want some sort of ShouldCloseWindow event. This is definitely in the "just not implemented yet" category.

@cmyr
Copy link
Member Author

cmyr commented Dec 12, 2019

self approving this, would like to clear up the queue

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