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

Give me window resizes or give me death #26

Conversation

CosmicHorrorDev
Copy link
Collaborator

Resolves #25

The comment linked below covers things pretty well. The gist is that we can lazily handle window resizing since we will get a RedrawRequested afterwards. This prevents a bunch of WindowResizeds from clogging up the event queue

https://github.com/trimental/inlyne/compare/main...LovecraftianHorror:give-me-window-resizes-or-give-me-death?expand=1#diff-42cb6807ad74b3e201c5a7ca98b911c5fa08380e942be6e4ac5807f8377f87fcR191-R216

@CosmicHorrorDev
Copy link
Collaborator Author

Oh also

weeeeeeee

weeee.mp4

@trimental
Copy link
Collaborator

Unfortunately this doesn't work in its current state on macOS since theres no other events to process after a window resize. The result is that the window stays unrefreshed and resized until you do another winit action like click the window.

I've also experimented with a seperate rendering thread to help this issue but the one thing that always got me was resizing! The thing is that theres never going to be a ResizedFinished event since that would require psychic abilities to predict, so I think we have to treat every resize as if it's our last. Although I wonder what event on X11 is causing you to resize and whether its making it instantly resize after every resize event.

@CosmicHorrorDev
Copy link
Collaborator Author

Bleh, looks like we're running into platform specific differences since it appears that RedrawRequested gets called automatically for me (unless something else triggers it that I'm not aware of). Here is a snippet of me printing all ReleventEvents when dragging a window to resize

CursorMoved(PhysicalPosition { x: 615.0, y: 475.0 })
WindowResized(PhysicalSize { width: 615, height: 477 })
WindowResized(PhysicalSize { width: 615, height: 475 })
WindowResized(PhysicalSize { width: 615, height: 473 })
CursorMoved(PhysicalPosition { x: 614.0, y: 469.0 })
WindowResized(PhysicalSize { width: 614, height: 471 })
WindowResized(PhysicalSize { width: 614, height: 469 })
WindowResized(PhysicalSize { width: 614, height: 468 })
CursorMoved(PhysicalPosition { x: 613.0, y: 463.0 })
WindowResized(PhysicalSize { width: 613, height: 465 })
RedrawRequested
WindowResized(PhysicalSize { width: 613, height: 464 })
WindowResized(PhysicalSize { width: 613, height: 462 })
WindowResized(PhysicalSize { width: 613, height: 460 })
WindowResized(PhysicalSize { width: 613, height: 459 })
WindowResized(PhysicalSize { width: 613, height: 457 })
WindowResized(PhysicalSize { width: 613, height: 455 })
WindowResized(PhysicalSize { width: 614, height: 454 })
RedrawRequested
WindowResized(PhysicalSize { width: 614, height: 452 })
WindowResized(PhysicalSize { width: 614, height: 451 })
WindowResized(PhysicalSize { width: 614, height: 450 })
WindowResized(PhysicalSize { width: 615, height: 449 })
WindowResized(PhysicalSize { width: 616, height: 448 })
WindowResized(PhysicalSize { width: 616, height: 447 })
WindowResized(PhysicalSize { width: 617, height: 446 })
RedrawRequested
WindowResized(PhysicalSize { width: 618, height: 445 })
WindowResized(PhysicalSize { width: 619, height: 444 })
WindowResized(PhysicalSize { width: 620, height: 444 })
WindowResized(PhysicalSize { width: 621, height: 443 })
WindowResized(PhysicalSize { width: 623, height: 443 })
WindowResized(PhysicalSize { width: 624, height: 443 })
RedrawRequested

When dragging the window to shrink it will pick up on cursor movements on the window. When expanding it will just be WindowResized and RedrawRequested

I've just pushed changes to trigger the resize off of a MainEventsCleared event which is supposed to fire between finishing all the window/user/device events and a redraw requested event. Let me know if this causes the window to stay refreshed for you

@trimental
Copy link
Collaborator

Mmm it does work however I don't see any difference in what its doing then before. I thought that request_redraw already queues redraws to occur once the main events are cleared?

@CosmicHorrorDev
Copy link
Collaborator Author

I had an issue with endlessly looping redraws before, but i just realized that i was requesting a redraw on every redraw event 🤦‍♂️

I'll switch things around to simplify them after i wake up

@CosmicHorrorDev
Copy link
Collaborator Author

Actually I think main events cleared is still the ideal place to handle this since it doesn't involve having to special case any future window/user/device events that we may handle

Can you clarify what you mean by "before"?

@CosmicHorrorDev
Copy link
Collaborator Author

I think all the issues with this PR are resolved at this point

@trimental
Copy link
Collaborator

With my previous comment I meant to say that on macOS it showed that resizes were being triggered immediately after pending_resize was set. So

[src/main.rs:174] "pending resize" = "pending resize"
[src/main.rs:392] "actual resize" = "actual resize"
[src/main.rs:174] "pending resize" = "pending resize"
[src/main.rs:392] "actual resize" = "actual resize"

but after looking closer I've seen a few

[src/main.rs:174] "pending resize" = "pending resize"
[src/main.rs:174] "pending resize" = "pending resize"
[src/main.rs:392] "actual resize" = "actual resize"

so this PR is working 🎊. The only thing I'm unsure about is whether we still need RelevantEvent, it seems to now just be a clone of winit::Event with less information, unless I'm missing something.

@CosmicHorrorDev
Copy link
Collaborator Author

Yeah RelevantEvent isn't very useful at this point. I'll go ahead and switch to using Event again

@trimental
Copy link
Collaborator

Oh one last thing (sorry to be a pain) but there needs to be a self.renderer.set_scroll_y(self.renderer.scroll_y); in the resize handler because if you scroll to the bottom and then resize, everything moves up and your left outside of visible content bounds. set_scroll_y will make scroll_y be in bounds.

@CosmicHorrorDev
Copy link
Collaborator Author

Nice catch on that! Should be all good now 🤞

@trimental
Copy link
Collaborator

Looks good 👍

@trimental trimental merged commit 7be4c27 into Inlyne-Project:main Aug 20, 2022
@CosmicHorrorDev CosmicHorrorDev deleted the give-me-window-resizes-or-give-me-death branch April 6, 2024 04:13
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.

Bad window resize performance with large READMEs on some systems
2 participants