#wayland #client

wayland-cursor

Bindings to libwayland-cursor

40 releases

0.30.0-beta.8 Jul 15, 2022
0.30.0-beta.6 Jun 25, 2022
0.30.0-alpha9 Mar 29, 2022
0.29.1 Oct 17, 2021
0.24.0 Sep 14, 2019

#14 in #wayland

Download history 19063/week @ 2022-04-22 20509/week @ 2022-04-29 19805/week @ 2022-05-06 19586/week @ 2022-05-13 18878/week @ 2022-05-20 19259/week @ 2022-05-27 20997/week @ 2022-06-03 20525/week @ 2022-06-10 19360/week @ 2022-06-17 18048/week @ 2022-06-24 20936/week @ 2022-07-01 19591/week @ 2022-07-08 22086/week @ 2022-07-15 20337/week @ 2022-07-22 25444/week @ 2022-07-29 25911/week @ 2022-08-05

97,291 downloads per month
Used in 75 crates (2 directly)

MIT license

76KB
821 lines

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() 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::ops::Deref;
# use std::thread::sleep;
# use std::time::{Instant, Duration};
# fn test(connection: &wayland_client::Connection, cursor_surface: &wayland_client::protocol::wl_surface::WlSurface, shm: wayland_client::protocol::wl_shm::WlShm) {
// 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

~2.5MB
~50K SLoC