Set LV_STATE_FOCUSED manually and catch the LV_EVENT_DEFOCUSED


I want to catch the defocus event of a roller, whenever I touch other areas than rollers.
So after the creation of the roller, I added this line:

lv_obj_add_state(roller_spo2_min, LV_STATE_FOCUSED);

But it doesn’t catch this event unless I touch the roller.-changing its value or click on it.-

What MCU/Processor/Board and compiler are you using?

stm32f429, gcc

What LVGL version are you using?

lvgl 8.1

What do you want to achieve?

catch the defocus event of an object -here it is a roller- even if I didn’t touch it.

What have you tried so far?

setting the roller’s state manually to LV_STATE_FOCUSED after its creation.

AFAIU, it’s because of this line:

proc->types.pointer.last_pressed = obj_to_focus;

in the body of indev_click_focus function. which is called when we really touch the CTP. right?
So, Any suggestions for solving the problem?

So Is there any idea?:thinking: @kisvegabor @embeddedt

You are right that indev_click_focus won’t defocus any arbitrary items but only the one which was clicked before.

You can do hack like this:

    lv_obj_add_state(roller1, LV_STATE_FOCUSED);
    extern lv_indev_t * my_indev;
    my_indev->proc.types.pointer.last_pressed = roller1;

There could be an API function for this, but I’m not sure if it’s a good idea to expose this internal functionality to the user.

1 Like

It worked, thanks.:tada::pray:
But you know, when we use this:

   lv_obj_add_state(roller1, LV_STATE_FOCUSED);

we expect to catch a defocused event in the roller’s callback.
Can’t we do sth about this? What do you think?

The problem is that the roller won’t be defocused as the pointer defocuses only the widget is focused earlier.