pub struct CursorTheme { /* private fields */ }
Implementations§
Source§impl CursorTheme
impl CursorTheme
Sourcepub fn load_from_env<F>(
size: u32,
create_pool_fn: F,
) -> Result<Self, CursorLoadError>
pub fn load_from_env<F>( size: u32, create_pool_fn: F, ) -> Result<Self, CursorLoadError>
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
.
Sourcepub fn load_from_name<F>(
name: &str,
size: u32,
create_pool_fn: F,
) -> Result<Self, CursorLoadError>
pub fn load_from_name<F>( name: &str, size: u32, create_pool_fn: F, ) -> Result<Self, CursorLoadError>
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()
}
Sourcepub fn get_cursor<F1, F2>(
&mut self,
name: &str,
backend: &mut Waybackend,
create_buffer_fn: F1,
resize_fn: F2,
) -> Option<&Cursor>
pub fn get_cursor<F1, F2>( &mut self, name: &str, backend: &mut Waybackend, create_buffer_fn: F1, resize_fn: F2, ) -> Option<&Cursor>
Gets a cursor from the theme
backend
will be fed to the two functions.create_buffer_fn
is a closure that returns aObjectId
: 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)
- backend (should be
resize_fn
is a closure that resizes thewl_shm_pool
. It accepts 3 inputs:- the backend (should be
waybackend::Waybackend
) - the
wl_shm_pool
ObjectId - the new size
- the backend (should be
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§
impl Freeze for CursorTheme
impl RefUnwindSafe for CursorTheme
impl Send for CursorTheme
impl Sync for CursorTheme
impl Unpin for CursorTheme
impl UnwindSafe for CursorTheme
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more