Rotary encoder and new screens

Description

My design is quite simple at this point. I have a main screen with a single button, and pressing the button launches a new screen also with a single button.

The first screen is created with lv_scr_act as it has no parent. The second screen is created with lv_obj_create with the first screen as a parent.

Screen transition is done with lv_disp_load_scr

What LVGL version are you using?

v8.3

What do you want to achieve?

My expectation is that a new screen should capture all events of my rotary encoder and only children of the new screen are able to be focused by the rotary encoder.

What have you tried so far?

So far I tried the steps described above and now I’m starting to work with what I found from this post:

However, I would expect that input device focus should be applicable only to the active screen. Am I missing something?

Okay… While I wait for more info here I decided to pursue the multi-group route.

Here is what I have:

For my Screen constructor, I’ll first capture the current default group, and, if using an encode/keypad, I’ll create a new group, set my indev to the newly created group, and assign this new group as the default.

For my destructor I undo my changes by deleting the new group, returning the indev to the original group, and reassigning the original group to default.

Does it make sense? Is there a better approach?

Screen::Screen()
    :  mp_parentGroup{lv_group_get_default()}
{
    lv_indev_t *p_curDrv{lv_indev_get_next(nullptr)};
    assert(nullptr != p_curDrv);

    if (true == IsRunningKeyEncoder(p_curDrv))
    {
        // If using an encoder or keypad create a new group and assign the
        // input device to this new group
        mp_group = lv_group_create();
        lv_indev_set_group(p_curDrv, mp_group);
        lv_group_set_default(mp_group);
    }
    else
    {
        // If not, the new screen will belong to the parent's group
        const lv_group_t *p_group =
          static_cast<lv_group_t *>(lv_obj_get_group(GetParentScreen()));

        // Current we assume that all screens belong to the 'current' default
        // group, so the parent screen must be in the default group. This
        // assumption might change depending on requirements, but for now,
        // enforce it.
        assert(p_group == nullptr);

        mp_group = mp_parentGroup;
    }
}
Screen::~Screen()
{
    lv_indev_t *p_curDrv{lv_indev_get_next(nullptr)};
    assert(nullptr != p_curDrv);

    // If running encode/keypad return the input device to the parent group and
    // delete the group created by this screen
    if (true == IsRunningKeyEncoder(p_curDrv))
    {
        // If using an encoder or keypad create a new group and assign the
        // input device to this new group

        lv_group_del(mp_group);
        lv_indev_set_group(p_curDrv, mp_parentGroup);
        lv_group_set_default(mp_parentGroup);
    }
}