How to load screens when using multiple displays

Description

I am currently having issues when creating multiple screens for multiple displays.

I create all displays, then all the screens, before iterating through loading each one onto its respective display by calling lv_disp_set_default, followed by lv_scr_load. This, however, only displays the content on the display that I created first (with the last screen being shown, as it was last to load).

According to the Overview → Displays → Screens section of the documentation, lv_scr_load should operate on the default display, however it appears that the screens are always loaded onto the display that was the default when the display was initialised. When looking at the LVGL source, this can be explained, as lv_scr_load calls lv_disp_load_scr, which calls lv_obj_get_disp to determine the display to draw the screen to.

Furthermore, the same section of the documentation lists lv_disp_load_scr as a separate function to lv_scr_load, and shows it as having 2 arguments:

lv_disp_load_scr(disp, scr)

However the LVGL source shows that lv_disp_load_scr only has 1 argument (the screen):

lv_disp_load_scr(scr)

Are these discrepancies due to the documentation being out of date? Or am I missing something here?

Basically, is there any way of loading screens to different displays, having created them at once, or do I have to set the correct default display before creating each screen?

Thanks in advance for any help!

What LVGL version are you using?

8.0.2

After some more digging in the LVGL source code (specifically the lv_obj_class_create_obj function definition), it does appear that the screens are assigned to the default screen when they are created, rather than when they are loaded.
It seems, therefore, that perhaps that particular section of the documentation needs updating to reflect this (and provide the correct function prototype for lv_disp_load_scr. I am happy to try updating it myself and create a PR, if that’s the best way forward.

In terms of my initial problem (of needing to load screens to particular displays after creating them, I have altered lv_disp_load_scr with the following changes, which works (though doesn’t handle the removing of the screen from the previous display it was assigned to, and probably has other issues).

void lv_disp_load_scr(lv_obj_t * scr)
{
    //Start of changes
    lv_disp_t * d = lv_disp_get_default();
    d->screen_cnt++;
    d->screens = lv_mem_realloc(d->screens, sizeof(lv_obj_t *) * d->screen_cnt);
    d->screens[d->screen_cnt - 1] = scr;
    //End of changes

    if(!d) return;  /*Shouldn't happen, just to be sure*/
    d->act_scr = scr;

    lv_obj_invalidate(scr);
}

Does anyone have a better way of achieving this? Or is it best to just accept that I should set the correct default display before creating the screen object?