slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
15.89k stars 518 forks source link

LinuxKMS: Add support for mouse cursor rendering with the software renderer #5379

Open tronical opened 2 weeks ago

tronical commented 2 weeks ago

As a follow-up to #4334 , this issue exists to remind about the missing support for rendering the mouse cursor when using renderer-software with backend-linuxkms.

The approach discussed in #4334 to implement this cleanly is briefly outlined in https://github.com/slint-ui/slint/pull/4334#discussion_r1451556820 : Add support for this type of mouse cursor rendering in the core library by synthesizing an Image that's rendered on top of the scene.

ogoffart commented 2 weeks ago

We probably need a public API in the software renderer as this would also be in used for the uefi example.

Just wondering at which level to do. The API could look like

impl SoftwareRenderer { // Or should it be in slint::Window?
   pub fn set_draw_mouse_cursor(cursor: Option<slint::Image>);
tronical commented 2 weeks ago

Maybe fn set_cursor_image(&self, image: Option<slint::Image>). I think Wayland also supports specifying an image for use a cursor, so this could indeed be on the Window.

ogoffart commented 2 weeks ago

No, no. The API i have in mind would be that Slint draws the cursor with its own renderer.

So an implementation of a backend would look like

impl WindowAdapter for MyBackendWindow {
 // ...

 // this is currently in WindowAdapterInternal, but we should make it public at some point)
 fn set_mouse_cursor(&self, cursor: MouseCursor) {
    let cursor_image: Option<slint::Image> = load_png_for_cursor(cursor);
    self.renderer.set_draw_mouse_cursor(cursor_image);
 }
}

I think Wayland also supports specifying an image for use a cursor, so this could indeed be on the Window.

That is something else, and should be somehow in the MouseCursor enum, we could pass an image to TouchArea::mouse-cursor or an extra property.