hello everyone
I’ve read essential files for evdev input devices. like a mouse for the Linux system.
It seems that littleVGL indev doesn’t support the right-click mouse button.
how can I enable this feature
LittlevGL does not support right clicking. I don’t know the original reason for not supporting it, but in any case, you would inevitably have to tweak the application if you ever wanted to use it on a touchscreen. I would suggest using the press-and-hold idiom instead.
unfortunately, I want to handle the right-click button of a mouse in an embedded Linux system.
What sould the right click do in your application?
I want to open a menu when I’ve click right-button of mouse on screen.
Would it be possible to manage it in the input device level?
That is in read_cb()
when you see a right click, you can simply create list on the screen.
hello
I’ve just enabled the right-click mouse for littleVGL.
it was easy.
with slight changes, you can handle every mouse button. here is how I did that.
1- add two states to “States for input devices” enum in lvgl/src/lv_hal/lv_hal_indev.h file, line 50
the enum would be like
enum { LV_INDEV_STATE_REL = 0, LV_INDEV_STATE_PR ,LV_INDEV_STATE_RIGHT_REL, LV_INDEV_STATE_RIGHT_PR};
the second step depends on which input device you want to handle for example I handle evdev device for Linux based operating system
2- in lv_driver/indev/edev.c file in evdev_read() function
in line 141 in if(in.type == EV_KEY) statement to distinguish Right-click from left_click
add this
if(in.code == BTN_MOUSE || in.code == BTN_TOUCH) {
if(in.value == 0)
evdev_button = LV_INDEV_STATE_REL;
else if(in.value == 1)
evdev_button = LV_INDEV_STATE_PR;
}
if(in.code == BTN_RIGHT ) {
if(in.value == 0)
evdev_button = LV_INDEV_STATE_RIGHT_REL;
else if(in.value == 1)
evdev_button = LV_INDEV_STATE_RIGHT_PR;
}
3- in lvgl/src/lv_core/lv_indev.c
in “indev_pointer_proc(lv_indev_t * i, lv_indev_data_t * data)” function
change the following “if” statemens to
if(i->proc.state == LV_INDEV_STATE_PR || i->proc.state == LV_INDEV_STATE_RIGHT_PR ) {
indev_proc_press(&i->proc );
}
else if(i->proc.state == LV_INDEV_STATE_REL ){
indev_proc_release(&i->proc,false);
}
else if(i->proc.state == LV_INDEV_STATE_RIGHT_REL ){
indev_proc_release(&i->proc,true);
}
4- lvgl/src/lv_core/lv_indev.c
modify indev_proc_release() to
static void indev_proc_release(lv_indev_proc_t * proc , bool R_CLICK)
{
if(proc->wait_until_release != 0) {
proc->types.pointer.act_obj = NULL;
proc->types.pointer.last_obj = NULL;
proc->pr_timestamp = 0;
proc->longpr_rep_timestamp = 0;
proc->wait_until_release = 0;
}
indev_obj_act = proc->types.pointer.act_obj;
/*Forget the act obj and send a released signal */
if(indev_obj_act) {
/* If the object was protected against press lost then it possible that
* the object is already not pressed but still it is the `act_obj`.
* In this case send the `LV_SIGNAL_RELEASED/CLICKED` instead of `LV_SIGNAL_PRESS_LOST` if
* the indev is ON the `types.pointer.act_obj` */
if(lv_obj_is_protected(indev_obj_act, LV_PROTECT_PRESS_LOST)) {
indev_obj_act->signal_cb(indev_obj_act, LV_SIGNAL_RELEASED, indev_act);
if(indev_reset_check(proc)) return;
if(proc->types.pointer.drag_in_prog == 0) {
if(proc->long_pr_sent == 0) {
lv_event_send(indev_obj_act, LV_EVENT_SHORT_CLICKED, NULL);
if(indev_reset_check(proc)) return;
}
if (!R_CLICK)
lv_event_send(indev_obj_act, LV_EVENT_CLICKED, NULL);
else
lv_event_send(indev_obj_act, LV_EVENT_RIGHT_CLICKED, NULL);
if(indev_reset_check(proc)) return;
}
lv_event_send(indev_obj_act, LV_EVENT_RELEASED, NULL);
if(indev_reset_check(proc)) return;
}
/* The simple case: `act_obj` was not protected against press lost.
* If it is already not pressed then `indev_proc_press` would set `indev_obj_act = NULL`*/
else {
indev_obj_act->signal_cb(indev_obj_act, LV_SIGNAL_RELEASED, indev_act);
if(indev_reset_check(proc)) return;
if(proc->long_pr_sent == 0 && proc->types.pointer.drag_in_prog == 0) {
lv_event_send(indev_obj_act, LV_EVENT_SHORT_CLICKED, NULL);
if(indev_reset_check(proc)) return;
}
if(proc->types.pointer.drag_in_prog == 0) {
printf("here1\n");
if (!R_CLICK)
lv_event_send(indev_obj_act, LV_EVENT_CLICKED, NULL);
else
lv_event_send(indev_obj_act, LV_EVENT_RIGHT_CLICKED, NULL);
if(indev_reset_check(proc)) return;
}
lv_event_send(indev_obj_act, LV_EVENT_RELEASED, NULL);
if(indev_reset_check(proc)) return;
}
/*Send LV_EVENT_DRAG_THROW_BEGIN if required */
/*If drag parent is active check recursively the drag_parent attribute*/
lv_obj_t * drag_obj = get_dragged_obj(indev_obj_act);
if(drag_obj) {
if(lv_obj_get_drag_throw(drag_obj) && proc->types.pointer.drag_in_prog) {
if(drag_obj->signal_cb) drag_obj->signal_cb(drag_obj, LV_SIGNAL_DRAG_THROW_BEGIN, NULL);
if(indev_reset_check(proc)) return;
lv_event_send(drag_obj, LV_EVENT_DRAG_THROW_BEGIN, NULL);
if(indev_reset_check(proc)) return;
}
}
proc->types.pointer.act_obj = NULL;
proc->pr_timestamp = 0;
proc->longpr_rep_timestamp = 0;
}
/*The reset can be set in the signal function.
* In case of reset query ignore the remaining parts.*/
if(proc->types.pointer.last_obj != NULL && proc->reset_query == 0) {
indev_drag_throw(proc);
if(indev_reset_check(proc)) return;
}
}
5- in lvgl/src/lv_core/lv_obj.h
add LV_EVENT_RIGHT_CLICKED
to events enum line 104
NOW you call easily use
if(evt == LV_EVENT_RIGHT_CLICKED)
in call back function of objects
Great!
Thanks for sharing!