Expand description

Wayland cursor utilities

This crate aims to re-implement the functionality of the libwayland-cursor library in Rust.

It allows you to load cursors from the system and display them correctly.

First of all, you need to create a CursorTheme, which represents the full cursor theme.

From this theme, using the get_cursor method, you can load a specific Cursor, which can contain several images if the cursor is animated. It also provides you with the means of querying which frame of the animation should be displayed at what time, as well as handles to the buffers containing these frames, to attach them to a wayland surface.

Example

Several functions of this crate send wayland requests under the hood, requiring you to provide a ConnectionHandle to load a cursor theme.

use wayland_cursor::CursorTheme;
// Load the default cursor theme.
let mut cursor_theme = CursorTheme::load(&mut connection.handle(), shm, 32).expect("Could not load cursor theme");
let cursor = cursor_theme.get_cursor(&mut connection.handle(), "wait").expect("Cursor not provided by theme");

let start_time = Instant::now();
loop {
    // Obtain which frame we should show, and for how long.
    let millis = start_time.elapsed().as_millis();
    let fr_info = cursor.frame_and_duration(millis as u32);

    // Here, we obtain the right cursor frame...
    let buffer = &cursor[fr_info.frame_index];
    // and attach it to a wl_surface.
    cursor_surface.attach(&mut connection.handle(), Some(&buffer), 0, 0);
    cursor_surface.commit(&mut connection.handle());

    sleep(Duration::from_millis(fr_info.frame_duration as u64));
}

Structs

A cursor from a theme. Can contain several images if animated.

A buffer containing a cursor image.

Represents a cursor theme loaded from the system.

Which frame to show, and for how long.