love2d / love

LÖVE is an awesome 2D game framework for Lua.
https://love2d.org
Other
5.09k stars 401 forks source link

Emit an event for SDL_WINDOWEVENT_EXPOSED #2004

Closed doesntgolf closed 4 weeks ago

doesntgolf commented 10 months ago

In the i3 window manager, when switching from one workspace to the workspace with an SDL application running, SDL emits the SDL_WINDOWEVENT_EXPOSED event. (I'm guessing this happens in other X desktops as well, and probably elsewhere, but I haven't tested anything else.)

I proposed emitting love.visible(true) when this happens (#2003), and @slime73 thought this didn't quite align with love.visible well enough. She suggested waiting to add something for this until SDL3, which is also adding an occluded event, which will be the opposite half of exposed.

(Edit: also, for what it's worth, I'm working on a non-game desktop app in Love. My graphics are static most of the time, so I have my own main loop where I only redraw when necessary, etc. I imagine in a game this isn't much of a concern, so I understand if this isn't added or isn't a priority.)

This issue is to track getting those events in a future Love version.

HDPLocust commented 4 months ago

Personally, I see the point in using love.visible and other similar events only if you, for example, are playing a video, and want to stop it from redrawing if the user minimizes the window. But even so, it is advisable to maintain some frame rate (3-5 frames per second) to update the preview window while it's changes (OS-dependent preview like this one). image

Most of non-immediate UI engines redraw the window only when strictly necessary - some internal event occurs (for example, the player moves the mouse), and the game screen is redrawn. Or while something is animatted, a redraw event was created and redraw entire UI window. Or something keeps getting redrawn every frame (like playing a video), and so you have to redraw the window.

Btw, good UI engines redraw only those areas that require redrawing, like this: ui node changes background color on redraw, being true static canvas otherwise (animated buttons emits redraw event up to UI node tree while animation goes on) and it's quite heavy optimization: UI complexity no longer affects performance, since only those UI elements that have been changed are redrawed. https://github.com/love2d/love/assets/13125395/6feb1039-a820-478e-9b42-ae369d1df70f