56 releases

0.31.7 Oct 23, 2024
0.31.5 Jul 16, 2024
0.31.1 Jan 29, 2024
0.31.0 Sep 2, 2023
0.24.0 Sep 14, 2019

#934 in GUI

Download history 93303/week @ 2024-07-23 88435/week @ 2024-07-30 93748/week @ 2024-08-06 94310/week @ 2024-08-13 85958/week @ 2024-08-20 91184/week @ 2024-08-27 93495/week @ 2024-09-03 91412/week @ 2024-09-10 90662/week @ 2024-09-17 99130/week @ 2024-09-24 91675/week @ 2024-10-01 88401/week @ 2024-10-08 86730/week @ 2024-10-15 101683/week @ 2024-10-22 94290/week @ 2024-10-29 92432/week @ 2024-11-05

390,324 downloads per month
Used in 601 crates (8 directly)

MIT license

98KB
1K SLoC

crates.io docs.rs Continuous Integration codecov

wayland-cursor

Loading of XCursor images for Wayland client apps. This crate provides helpers to load the system provided cursor images and load them into WlBuffers as well as obtain the necessary metadata to properly display animated cursors.


lib.rs:

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()][CursorTheme::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

use wayland_cursor::CursorTheme;
// Load the default cursor theme.
let mut cursor_theme = CursorTheme::load(&connection, shm, 32)
    .expect("Could not load cursor theme");
let cursor = cursor_theme.get_cursor("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(Some(&buffer), 0, 0);
    cursor_surface.commit();

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

Dependencies

~3–12MB
~154K SLoC