-
Notifications
You must be signed in to change notification settings - Fork 922
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
Event now takes a lifetime #1387
Comments
I think your second point is resolved here, right? |
I also agree with you here and share your thoughts. We faced similar issue in
I'm not sure how some parts of Anyway, I'm here to just share some thoughts, since I was fine with the fact that alacritty can't adopt without some unsafe tricks to a new winit, since we're a bit odd in some cases. However if one more downstream client also having troubles then maybe the problem is a bit wider than "alacritty can't adopt without unsafe tricks", as I've initially thought about this lifetime addition. cc @chrisduerr , since he is aware more than I on our event loop and will likely correct me here. |
I don't like the lifetime on the event and it is completely useless to Alacritty, but based on my understanding there simply is no alternative, right? If I understand the reason behind this correctly, having a mutable new size is the only way for applications to resize to a specific size on scale factor change without flickering between multiple sizes. So as far as I understand it, if the lifetime should be removed, winit would need an alternative way to solve this problem. I don't think it's a great idea to create an API that makes it impossible to do certain things, only because it's a minor inconvenience for a few "popular" downstream users. |
That PR would be a slight improvement as
The mutability should be inside |
@murarth brought something like this up, but in my opinion it adds unneeded complexity that's not so obvious to the user. |
So that everyone is on the same page: what would be an use case of wanting to resize the window when the DPI changes? Alacritty is not doing it and I'm not sure why glium's examples should do it. I'm curious. |
It's actually done by default. So when DPI changes, Alacritty will resize. So I'd imagine one usecase might be if you want the window size to be consistent, even if DPI changes. |
@chrisduerr sorry I expressed myself wrongly. what would be the use case to set the reference? |
This is a mix of several things actually. Basically, the field in Then, in #695 (comment) it was deemed relevant to add an event with a reference to efficiently handle resize increments for apps that desire so. IIRC the choice of such a design was for taking into account some platform constraints (MacOS ?) that don't allow apps to do a lot of things if a resize is in progress. The 2nd objective is not yet implemented, but as it was going to add a lifetime to |
I'm just spitballing here, but could winit do the |
I cannot create a |
I think the problems caused by the lifetime are not worth it. For me it means removing the 'a and continuing with a fork as I gain nothing by it and it blocks me from progressing. |
So for glium, I've ended up using the |
I've looked at the Edit: I suppose it does have some advantage though. Currently it will create UB in Alacritty if winit adds a new event with a lifetime that we do not handle. |
It isn't. In fact it's only done in glium's example code where the priority is to allow a quick start without worrying about everything that can go wrong. Here, caring about DPI changes is in fact a liability as it makes the code harder to understand. It's obviously a different tradeoff in production apps like alacritty. User events fortunately require |
I've hacked together a basic prototype (mechanically fixing compiler errors--not reading the code very closely yet!) replacing the lifetime with Open questions:
Edit: I realize it probably would've been a good idea for me to look at the original discussions leading to the current design... I'll dig into that the next chance I get. Edit 2: Here's a diagram documenting the consequences of many different approaches: #939 (comment) |
I don't see why one can't just call resize() after a ScaleFactorChanged event. |
@s3bk I believe it has to do with avoiding flicker. See the thread at #939 for more context. However, I think an implementation that works without the mutable size on At the very least, we should consider adding an example that shows both the flickering case and the same case fixed by the mutable size on |
@tangmi : @murarth demonstrated that it can be done without a lifetime. While it may add some complexity, it makes handling events a lot easier. |
One can create resize implementations that avoid flickering if you call them right after receiving the ScaleFactorChanged event, simply by updating internal state. I've suggested the same above: #1387 (comment) See @goddessfreya 's reply to my comment as to why this approach wasn't taken. To explain the reasoning, I think the issue is that you'd need to call that improved resize implementation right after reception of that event. At any later point it causes flicker. Keeping that in mind would probably confuse users, so they added a lifetime to ensure that the event handling happens soon enough so that you can still override the size. While this measure is perfectly making sure that flickering is prevented, it forces a certain design onto programs, onto all programs. In most cases, even if they care about preventing flickers, people don't want to override that size so it's a niche use case. But everyone is forced to change the design of their program for it, including folks who write their first ever glium program. It's a wrong tradeoff IMO. The lifetime free variant of #1456 is a bit better, as it doesn't force a design pattern onto users. But my favourite would still be doing this via a function, either making the existing resize functions smart, or by adding a custom specialized function. The reason why I prefer separate functions is separation of concerns: events should be pure information instead of containing references that can be used to influence behaviour of the program. |
Check out my PR #1456 if it will help your use case. I'm approaching the problem from the view that while we must resize inside thre Note that the web backend doesn't (as far as I know) respond to zooming yet.
I agree, but tbh the problem space is still very abstract to me. I think a runnable example may help me better understand the problem... I may work on that next, since it's unclear to me how the resizing of a window while the DPI is changing could be smooth, given on Windows the OS seems to go crazy when DPI changes. |
Zooming works: |
Wow! I'm curious how that works--I don't think I (or anyone else) implemented the |
@tangmi I am using the |
An alternative to fixing this would be that we embrace this design; that some events are effectively just callbacks with a return value, and hence need a lifetime. This could probably avoid the need for callbacks in e.g. #1759 and probably smooth out a lot of other cases where we need to react with a return value to an event, rather than just acting on it. Not sure which option I prefer, but I think a decision needs to be made. |
Lifetimes don't work nicely when dealing with multithreaded environments in the current design of the existing winit's event handling model, so remove it in favor of `Weak` fences passed to client, so they could try to update the size. Fixes rust-windowing#1387.
Lifetimes don't work nicely when dealing with multithreaded environments in the current design of the existing winit's event handling model, so remove it in favor of `Weak` fences passed to client, so they could try to update the size. Fixes rust-windowing#1387.
Lifetimes don't work nicely when dealing with multithreaded environments in the current design of the existing winit's event handling model, so remove it in favor of `InnerSizeWriter` fences passed to client, so they could try to update the size. Fixes rust-windowing#1387.
Lifetimes don't work nicely when dealing with multithreaded environments in the current design of the existing winit's event handling model, so remove it in favor of `InnerSizeWriter` fences passed to client, so they could try to update the size. Fixes rust-windowing#1387.
Lifetimes don't work nicely when dealing with multithreaded environments in the current design of the existing winit's event handling model, so remove it in favor of `InnerSizeWriter` fences passed to client, so they could try to update the size. Fixes rust-windowing#1387.
Lifetimes don't work nicely when dealing with multithreaded environments in the current design of the existing winit's event handling model, so remove it in favor of `InnerSizeWriter` fences passed to client, so they could try to update the size. Fixes rust-windowing#1387.
Lifetimes don't work nicely when dealing with multithreaded environments in the current design of the existing winit's event handling model, so remove it in favor of `InnerSizeWriter` fences passed to client, so they could try to update the size. Fixes rust-windowing#1387.
Lifetimes don't work nicely when dealing with multithreaded environments in the current design of the existing winit's event handling model, so remove it in favor of `InnerSizeWriter` fences passed to client, so they could try to update the size. Fixes rust-windowing#1387.
Lifetimes don't work nicely when dealing with multithreaded environments in the current design of the existing winit's event handling model, so remove it in favor of `InnerSizeWriter` fences passed to client, so they could try to update the size. Fixes #1387.
Lifetimes don't work nicely when dealing with multithreaded environments in the current design of the existing winit's event handling model, so remove it in favor of `InnerSizeWriter` fences passed to client, so they could try to update the size. Fixes rust-windowing#1387.
Lifetimes don't work nicely when dealing with multithreaded environments in the current design of the existing winit's event handling model, so remove it in favor of `InnerSizeWriter` fences passed to client, so they could try to update the size. Fixes #1387.
Since the 0.20.0 release,
Event
as well asWindowEvent
are now taking lifetimes (old docs.rs, new docs.rs). The reason for this is theScaleFactorChanged
event'snew_inner_size
field. I think this change is bad: First, separation of concerns is violated. Events are supposed to be immutable input to the program, not provide means for the program to react to that input. Second, Event now ceased to be Clone and the lifetime means I have to think about workarounds in glium's example support code: glium/glium#1817.The PR that has added the lifteime seems to be #895 where it was still called
new_inner_rect_opt
.Can this feedback maybe be implemented in a different way?
I have great respect for you folks. Thanks for maintaining glutin/winit.
PRs to watch:
Event
type #1456lifetime
from theEvent
#2981The text was updated successfully, but these errors were encountered: