handling resizes #2160
Replies: 3 comments 20 replies
-
how this all works together is kinda tricky and subtle, so let me go into deeper detail: fundamentally, we find out about a screen resize at render time, because we do an for(ncplane* rootn = pile->roots ; rootn ; rootn = rootn->bnext){
if(rootn->resizecb){
ret |= rootn->resizecb(rootn);
}
} this is calling the resize callback of all the root planes of the pile. by default, you only have one pile, and it only has one root plane: the standard plane. note that this is done before the render begins. so you have a chance to change things up however you would like before Notcurses ever writes (what the terminal did on its own initiative upon the resize is its own business, and this is why you want to render quickly after a resize). now, when a resize happens, a SIGWINCH is sent to us. POSIX signals are unreliable -- you're not guaranteed to receive a signal you're sent (otherwise, we'd only need to run the so to quickly update the screen following a resize (and thus retake control of it), you need either be continuously rendering, or at least responsive to input. to update the screen meaningfully for the new size, you might need to do any number of things, entirely dependent on your UI. if all your program does is display the last input in the origin cell, you probably never need do anything to respond to a resize. if you need to keep all your planes in the visible area, a resize callback involving a move is probably sufficient. if you're trying to keep a perimeter drawn around the standard plane, you're likely going to need to erase the plane and redraw the perimeter. i provide a few simple resize callbacks as part of Notcurses; see |
Beta Was this translation helpful? Give feedback.
-
thanks - i was going to write a lightdm greeter using ncursers but decided to try and use notcurses. Therefore, i will be deep diving to make sure i understand how everything works. I was planning on linking the greeter to a static libnotcurses archive. |
Beta Was this translation helpful? Give feedback.
-
#2164 is a PR for the changes discussed. |
Beta Was this translation helpful? Give feedback.
-
Someone mailed me a question about handling resizes, and I thought I'd put the answer here.
yeah, there's some pretty extensive resize handling, though it's not all as documented as i would like.
so first off, you are correct: the resize event is going to screw up your display. Notcurses can't do anything about this by itself for two reasons:
so you have to do two things:
if you want to respond to resize events, you need always be looking for input with
notcurses_get()
unless you're continuously rendering. you'll see anNCKEY_RESIZE
come down the pipe, at which point you can callnotcurses_render()
. but you need set things up, still...when
notcurses_render()
is called, and a resize has happened, it begins a callback chain, started at the root planes (almost always the standard plane, unless you did some reparenting). each plane has a resize callback, which may be NULL. if the plane is resized, that callback is invoked. the logic for what to do should be placed there. if you want, you can then invoke your childrens' callbacks recursively.does that make sense? essentially, there's no way for Notcurses to "get between" the resize and the redraw. the terminal is in charge of that logic. but, it can determine that a resize has happened, and then let you deal with it.
if you look at the source for
notcurses-demo
, you'll see for instance that the FPS graph uses a resize callback so that if the screen is made smaller, the FPS graph is moved back into the visible area. you can see this runningnotcurses-demo
.Beta Was this translation helpful? Give feedback.
All reactions