CursorTheme

Struct CursorTheme 

Source
pub struct CursorTheme { /* private fields */ }

Implementations§

Source§

impl CursorTheme

Source

pub fn load_from_env<F>( size: u32, create_pool_fn: F, ) -> Result<Self, CursorLoadError>
where F: FnOnce(&OwnedFd, u32) -> ObjectId,

Tries to load the cursor theme from the XCURSOR_THEME and XCURSOR_SIZE environment variables

See CursorTheme::load_from_name for an example of a create_pool_fn.

Source

pub fn load_from_name<F>( name: &str, size: u32, create_pool_fn: F, ) -> Result<Self, CursorLoadError>
where F: FnOnce(&OwnedFd, u32) -> ObjectId,

Tries to load the cursor theme from an str

create_pool_fn is a function that takes the shm file descriptor and the initial size. Typically, it will look like this (note in the example we are loading the generatec wayland glue code with waybackend-scanner in a module called wayland):

use waybackend_cursor::CursorTheme;
use waybackend::{types::ObjectId, objman, Waybackend};

#[derive(Clone, Copy, Debug, PartialEq)]
enum WaylandObject {
    Display,
    Shm,
    ShmPool,
    Buffer,
    Surface,
    // ...
}

fn load_cursor(
    backend: &mut Waybackend,
    objman: &mut objman::ObjectManager::<WaylandObject>,
    wayland_shm: ObjectId) -> CursorTheme {
    CursorTheme::load_from_name("default", 24, |fd, size| {
        let shm_pool = objman.create(WaylandObject::ShmPool);
        wayland::wl_shm::req::create_pool(
            backend,
            wayland_shm,
            shm_pool,
            fd,
            size as i32,
        )
        .unwrap();
        shm_pool
    }).unwrap()
}
Source

pub fn get_cursor<F1, F2>( &mut self, name: &str, backend: &mut Waybackend, create_buffer_fn: F1, resize_fn: F2, ) -> Option<&Cursor>
where F1: FnMut(&mut Waybackend, ObjectId, i32, i32, i32, i32) -> ObjectId, F2: FnMut(&mut Waybackend, ObjectId, u32),

Gets a cursor from the theme

  • backend will be fed to the two functions.
  • create_buffer_fn is a closure that returns a ObjectId: the ObjectId of the newly created wayland buffer. It accepts 6 inputs:
    • backend (should be waybackend::Waybackend)
    • the wl_shm_pool ObjectId
    • offset (see the wayland protocol documentation)
    • width (see the wayland protocol documentation)
    • height (see the wayland protocol documentation)
    • stride (see the wayland protocol documentation)
  • resize_fn is a closure that resizes the wl_shm_pool. It accepts 3 inputs:
    • the backend (should be waybackend::Waybackend)
    • the wl_shm_pool ObjectId
    • the new size

Here is an example of what this function call could look like:

use waybackend::{types::ObjectId, objman::Objman, Waybackend};
use waybackend_cursor::{Cursor, CursorTheme};
fn get_cursor(
    cursor_theme: &mut CursorTheme,
    backend: &mut Waybackend,
    objman: &mut Objman,
    name: &str,
) -> Option<&Cursor> {
    cursor_theme.get_cursor(
        name,
        backend,
        |backend, pool, offset, width, height, stride| {
            // NOTE: you probably also want to store this buffer id somewhere
            let buffer = objman.create(WaylandObject::Buffer);
            wayland::wl_shm_pool::req::create_buffer(
                backend,
                pool,
                buffer,
                offset,
                width,
                height,
                stride,
                wayland::wl_shm::Format::argb8888,
            )
            .unwrap();
            buffer
        },
        |backend, id, size| {
            wayland::wl_shm_pool::req::resize(backend, id, size as i32).unwrap()
        },
    )
}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.