-
-
Notifications
You must be signed in to change notification settings - Fork 219
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
move window creation and management to Lua #1751
Conversation
EDIT: will be done in a later PR |
data/core/commandview.lua
Outdated
@@ -348,7 +348,7 @@ function CommandView:draw_line_gutter(idx, x, y) | |||
local color = common.lerp(style.text, style.accent, self.gutter_text_brightness / 100) | |||
core.push_clip_rect(pos.x, pos.y, self:get_gutter_width(), self.size.y) | |||
x = x + style.padding.x | |||
renderer.draw_text(self:get_font(), self.label, x, y + yoffset, color) | |||
renderer.draw_text(core.window, self:get_font(), self.label, x, y + yoffset, color) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a discussion around this API change already happened on discord, so I'm marking this to get more feedback.
The current implementation requires that the first argument is the relevant window, but this change would be backwards incompatible.
Alternatives include:
- making window argument optional (checking arg count, putting it at the end, etc.)
- this would make adding arguments more painful in the future
- turning the window into a global
- Personally I am not the biggest fan of it because its likely going to introduce race conditions if done wrong.
- The only way I could see this being done is by having a set and unset (push and pop?) function and erroring out if you are trying to set when its already unset
- leaving the existing draw functions as is and adding
renwindow:draw_*
functions which act directly on the relevant window- the
renderer.draw_*
methods could then be redirected to the main window methods
- the
- implement a new
draw_*_ex
family of functions- same as the non ex version, except it takes a window instance (name is up to debate)
- accept that window is an argument of the draw function
- this is way more explicit and ensures that intended behavior
DrawCurrently drawing only works (or at least, works without weird issues) when done between Lines 1391 to 1395 in 62d7ec8
So no drawing in a If we don't want to allow mixing draws to a window and draws to another (which makes sense not to imho), we could pass the window to draw to as a parameter to Another possibility is to set it as a global variable on the Lua side, and retrieve it on the C side when needed by rendering functions, but this approach might slow things down a little bit (needs testing to see how much, if at all). Both of these solutions would allow us to avoid breaking This is only valid for Update + inputSome If we move them to If we consider that each window will have its own The issue with this approach is that So the possible solutions are:
The issue with 1 and 2 is for example with dealing with We also need to keep in mind how all of this will behave when a Possible conclusionsWe could have a single C-side global variable that will be used when the generic This would be called by Moreover When a This would allow us to keep the "legacy" API, and allow the usage of the Any thoughts? |
core.window_title = current_title | ||
end | ||
|
||
-- draw | ||
renderer.begin_frame() | ||
renderer.begin_frame(core.window) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making a review comment to consider what Guldo said so replies can be focused.
I'm okay with simply setting a global active window when passed to renderer.begin_frame
(with end_frame unsetting the global and doing sanity checks)
What about the other functions though, which aren't directly rendering related?
(such as system.set_window_title
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, all the rendering code no longer takes a window as a parameter and instead works with the active window for the current frame.
I'm probably going to move over the system
window functions into renwindow
and remove them completely since they are a lot more flexible and not suited for this.
a2c958a
to
932e1b5
Compare
Ideally we'd keep the first window always open until lite-xl exits, so that we have a smooth restart, like we do now. |
the restart issue has been fixed I'd say this PR is done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code-wise this is good aside from random inconsistent brace indents. As for the functionality I cannot comment much since I didn't actively participate in the discussion, but I will try to follow and see there are other points to consider.
I read the comments here, and I have just a question.
Other than that, other aspects seem fairly okay to me; you'd be expected to pass various things into system, but also this is a chance to move those code into |
As for persisting the window, will it be worth it to preserve the window list somehow (I recall the windows are being stored in a list somewhere), so like windows that are not closed are preserved, and a Lua function can be called to re-associate them with a Lua userdata and get a list of them. The GC will not "close" windows but disown them, and they're actually closed when the runtime exits (instead of restart). |
Ideally the Lua side would supply the font size to the rendering functions, and it would not be a property of the font. |
In my opinion And its not like this is gonna cause major issues since scaling is busted as is (though may be worth documenting in #1750)
I do agree that its worth preserving all windows. Currently the Windows has its lifetime managed in Lua and as soon as the garbage collector finds it dangling it will get destroyed. I think windows should be managed entirely in Lua until ownership is given up (for example with a the above solution is the best I can think of right now, but I really really really do not want to pack this PR with any more stuff and think this can be best put into a separate, smaller PR to make it easier to review, test, merge as well as reason about at a later date. |
another topic regarding windows storage: |
Not sure if this would work, but you could probably store it as a lightuserdata (basically a C pointer). |
Outside of bikeshedding I consider this PR done as is and any additions should be put into a follow-up PR |
I'm ok to merge this PR, how about @Guldoman and @adamharrison? |
There is a noticeable period where the window is just blank before first draw that I don't notice with the current build; this could be either an actual regression in terms of performance, or just a seeming one where we're showing the window earlier. It's not necessarily a blocker for me, but if we can resolve it to have roughly the same performance (either real or imagined) as before, that'd be good. I'll do some investigation in a bit to see if it's simply a hiding window thing. |
I've tried recreating the blank window thing and can't. |
Found the issue. It's because on master we pass You call So what I'd suggest we do is change the creation to:
and change the update_rects call to:
This fixes the issue on my end. Technically, actually, we should probably store |
for the time being its been hardcoded to 1 for the non SDL Renderer basewin setup, so nothing is lost for non MacOS users. will be revisited in the future when scaling is improved with SDL3 and moved into scripts.
39cd363
to
228ed0b
Compare
Looks good! Merging. |
for reference, since this was discussed on Discord: |
window_renderer
globalren_create
andren_destroy
ren_init
andren_free
names for global allocations (draw_rect_surface, freetype)Due to this change being quite invasive with no easy backwards compatibility, the mod verison would need to be bumped.