#wayland #client

wayland-cursor

Bindings to libwayland-cursor

11 releases (4 breaking)

new 0.28.0 Sep 14, 2020
0.27.0 Jul 3, 2020
0.26.6 May 23, 2020
0.26.3 Apr 22, 2020
0.24.0 Sep 14, 2019

#337 in GUI

Download history 3365/week @ 2020-05-28 3053/week @ 2020-06-04 3230/week @ 2020-06-11 2771/week @ 2020-06-18 2670/week @ 2020-06-25 2865/week @ 2020-07-02 3633/week @ 2020-07-09 3893/week @ 2020-07-16 3908/week @ 2020-07-23 4643/week @ 2020-07-30 4606/week @ 2020-08-06 4501/week @ 2020-08-13 4894/week @ 2020-08-20 4755/week @ 2020-08-27 4354/week @ 2020-09-03 3983/week @ 2020-09-10

16,902 downloads per month
Used in 17 crates (2 directly)

MIT license

145KB
2.5K 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 reimplement 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

use wayland_cursor::CursorTheme;
# use std::thread::sleep;
# use std::time::{Instant, Duration};

let cursor_theme = CursorTheme::load(32, wl_shm);
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(fr_info.frame_duration);
}

Dependencies

~2MB
~40K SLoC