-
Notifications
You must be signed in to change notification settings - Fork 919
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 support for WM_CREATE
and WM_COMMAND
messages on Windows
#506
Conversation
Note: I am not sure if adding / removing menu items at runtime is thread-safe. Maybe this will need an extra API in the future, but that shouldn't interfere with the current API. |
I wouldn't call this "very simple", since it introduces two unprecedented API changes. Do you mind if I just go ahead and release 0.14.0? Alacritty wouldn't upgrade to 0.13.1 due to a few regressions, so releasing 0.14.0 would allow for a bunch of problems to be fixed over there. Releases are pretty frequent now anyway, and I really don't feel comfortable being under pressure to merge this. I don't know about exporting I think |
Alright. I'll think about the event handling API. The reexporting doesn't have large ramifications IMO, but I'll wait for feedback. |
@francesca64 I have nothing to say regarding the reexport. It can indeed simplify version handling in general. However, I agree that Going in the direction of #450, adding the possibility in platform-specific extension traits to add a callback for platform-specific messages not handled by winit seens a good direction to look, I think. |
It looks like the main reason the As far as platform-specific |
@Osspial I am in favor of a custom The Or we could say that we put the IMO callbacks are a bit unwieldy to handle, so I'd favor a catch-all So, I'd wait until #459 is done. Because that would resolve at least the inconsistency of |
Actually, Windows provides a subclassing API that let's users pass a custom pointer to the windows event function. Using that to provide a function pointer would be pretty easy (see https://msdn.microsoft.com/en-us/library/windows/desktop/bb773183(v=vs.85).aspx#subclassing_v6). Also, I'd prefer the callback approach in this case. It seems to me that the primary purpose of a callback would be to modify how the window behaves, rather than how the application behaves as a whole, and as such seems out-of-place in the application's main event loop. Putting it in the main loop also complicates how we handle return values, as the windows API attaches some significant semantics to those. |
I'm against re-exporting |
Closing this because I ran into issues using this in practice. While yes, you can create menus, there is no way to pass custom data into the |
menu fix until proper application menus are implemented in azul
This PR allows to register a custom callback (only on Windows) that can be used to set up application menus / native Win32 menu bars. The reason why it has to be a callback and can't be just a
WindowEvent
is because the Win32 API isn't thread-safe. If you call the callback from a different thread than the one on which the window was created, Windows will freeze your application on theSetMenu
call.Regular Win32 programming guides want you to register your application menus directly in the
winuser::WM_CREATE
message. Since we can't expose this directly to the user of this library, the only place to call the callback is directly after the window has been created.In the callback, it is usual to set up custom IDs for getting a message back when the user has clicked an item. To return this ID to the user of the library, I've added a
WindowEvent::Command
. Currently this event is available on all platforms, but only gets emitted on Windows. It is debatable if we should put this behind acfg
flag, I've decided not to do that because it makes the event handling code a bit cleaner.Also note that I've exported the
winapi
crate. This is done so that libraries can sayuse winit::winapi
instead of having to match their version of winapi to whatever versionwinit
is using. This leads to less version conflicts, when, for examplewinit
useswinapi 0.3
, but I want to usewinapi 0.4
in my crate. This isn't critical, but it's nicer to re-export it. It's not critical though and could be removed from the PR.