Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Mouse input device support #4909

Closed
XuNeo opened this issue Dec 1, 2023 · 18 comments
Closed

[Feature Request] Mouse input device support #4909

XuNeo opened this issue Dec 1, 2023 · 18 comments

Comments

@XuNeo
Copy link
Collaborator

XuNeo commented Dec 1, 2023

Introduce the problem

Currently we have pointer and encoder type of input device. But for platform that uses mouse directly like in simulator, the scroll wheel should not be treated as simple encoder.
Ideally the wheel could also scroll the page or change slider value or send event to whatever widget currently focused.

Add a unified solution for mouse use case could benefit lot of user cases.

Examples and cases

Suggested solution

@kisvegabor
Copy link
Member

We can add an lv_point_t scroll field to lv_indev_data_t. If it's set, a widget will be scrolled accordingly. However, I'm not sure which widget should be scrolled?

  1. The widget under the current pointer position?
  2. The last activated widget?

(They can be different if the cursor was moved without clicking.)

I vote for 1) because PCs work like this as well. (At least my Linux Mint)

@XuNeo
Copy link
Collaborator Author

XuNeo commented Dec 4, 2023

For touch screen with crown, the focused widget could be used for sending event to.

@kisvegabor
Copy link
Member

With crown, can you position the "cursor" above the focused widget so that we can use option 1) ?

@kisvegabor kisvegabor mentioned this issue Dec 4, 2023
22 tasks
@XuNeo
Copy link
Collaborator Author

XuNeo commented Dec 5, 2023

With crown, can you position the "cursor" above the focused widget so that we can use option 1) ?

That sounds a bit of hacky.
The focused state could be better to decide which obj to scroll right?
LV_OBJ_FLAG_CLICK_FOCUSABLE can be used by app to auto-focus widget by touch.
Indev will send scroll event if the focused obj is scrollable and send encoder value instead if non-scrollable?

I haven't investigate much on this, please do check if any other options available.

@kisvegabor
Copy link
Member

I prefer scrolling based the object under the cursor to mimic PC behavior. I haven't clicked just scrolled:
scroll

At worst case we can make it a config option, but it would be better have a single solution which works in general.

What if we really create a function for that. Probably it would be the most flexible solution. I mean something like this in the indev read_cb:

if(scroll_up) {
  lv_indev_scroll_throw_manual(indev, lv_indev_get_last_clicked(), scroll_size, LV_DIR_TOP);
  
  //OR
  lv_obj_t * obj = lv_indev_search_scrollable_obj(&point, scroll_size, LV_DIR_TOP);
  lv_indev_scroll_throw_manual(indev, obj, scroll_size, LV_DIR_TOP);
}

@XuNeo
Copy link
Collaborator Author

XuNeo commented Dec 5, 2023

cc @W-Mai

@W-Mai
Copy link
Contributor

W-Mai commented Dec 5, 2023

Maybe we can add a new hover state when pointer is enabled.

Auto scrolling occurs when the pointer is hovering an object.

@kisvegabor
Copy link
Member

Auto scrolling occurs when the pointer is hovering an object.

That's my idea too. LV_STATE_HOVER is already added to LVGL but it's not used yet. I think we shouldn't add full HOVER support now, just find the object on and x,y coordinate which can be scrolled in the given direction.

@xaowang96
Copy link
Contributor

xaowang96 commented Dec 7, 2023

With crown, can you position the "cursor" above the focused widget so that we can use option 1) ?

That sounds a bit of hacky. The focused state could be better to decide which obj to scroll right? LV_OBJ_FLAG_CLICK_FOCUSABLE can be used by app to auto-focus widget by touch. Indev will send scroll event if the focused obj is scrollable and send encoder value instead if non-scrollable?

I haven't investigate much on this, please do check if any other options available.

@XuNeo There may be a contradiction here. The crown should also support scrolling propagation, but it cannot be propagated after specifying focused obj.

@kisvegabor
Copy link
Member

What do you mean by "rectifying"?

@xaowang96
Copy link
Contributor

What do you mean by "rectifying"?

@kisvegabor It is a typo, it should be "specifying".

@kisvegabor
Copy link
Member

There may be a contradiction here. The crown should also support scrolling propagation, but it cannot be propagated after specifying focused obj.

We could still say to try scrolling the focused object, but propagate the scroll if needed.

@kdschlosser
Copy link
Contributor

kdschlosser commented Dec 11, 2023

what gets scrolled is whatever the mouse is hovering over. If that item is not able to be scrolled then it's parent is what gets scrolled. and if the parent is not able to be scrolled... etc etc all the way down to the screen level.

To further assist something like that you would need to add 2 events, one would be mouse_enter and the other is mouse_leave. when the mouse moves hot tests would need to be done to locate the object it is hovering over. if the mouse was not over the
object the last time but it is now then an event should be triggered that the mouse has entered a new widget but only after an event is triggered that it left a widget if it did leave a widget.

@XuNeo
Copy link
Collaborator Author

XuNeo commented Dec 12, 2023

We could still say to try scrolling the focused object, but propagate the scroll if needed.

There's a corner case that a slider is focused and is not scrollable. But the parent of slider is scrollable.
The expected behavior should send event to focused slider.

Hovering on the slider should simply scroll the parent though.

So the logic for low level indev becomes that firstly check if there's focused obj, if so, send the event anyway.
Otherwise, send scroll event and propagate it to obj hovered.

@kisvegabor
Copy link
Member

On our meeting we have concluded to create a new input device for it.

Is it required to add to v9.0, or adding it by the end of January is still ok?

@lvgl-bot
Copy link

We need some feedback on this issue.

Now we mark this as "stale" because there was no activity here for 14 days.

Remove the "stale" label or comment else this will be closed in 7 days.

@lvgl-bot lvgl-bot added the stale label Dec 28, 2023
@kisvegabor
Copy link
Member

Not stale

@lvgl-bot lvgl-bot removed the stale label Dec 31, 2023
@kisvegabor
Copy link
Member

Continued in #5057

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants