deps: smithay + egui update

This commit is contained in:
Victoria Brekenfeld 2022-11-17 20:32:54 +01:00
parent aa3ee245d1
commit 7a034c8e52
20 changed files with 906 additions and 657 deletions

View file

@ -15,7 +15,7 @@ use smithay::{
},
reexports::wayland_server::protocol::wl_surface,
render_elements,
utils::{IsAlive, Logical, Point, Scale, Transform},
utils::{IsAlive, Logical, Monotonic, Point, Scale, Time, Transform},
wayland::compositor::{get_role, with_states},
};
use std::{
@ -24,6 +24,7 @@ use std::{
collections::HashMap,
io::Read,
sync::Mutex,
time::Duration,
};
use xcursor::{
parser::{parse_xcursor, Image},
@ -193,93 +194,85 @@ pub fn draw_cursor<R>(
seat: &Seat<State>,
location: Point<f64, Logical>,
scale: Scale<f64>,
start_time: &std::time::Instant,
time: Time<Monotonic>,
draw_default: bool,
) -> Vec<CursorRenderElement<R>>
where
R: Renderer + ImportAll + ImportMem,
R: Renderer + ImportMem + ImportAll,
<R as Renderer>::TextureId: Clone + 'static,
{
// draw the cursor as relevant
{
// reset the cursor if the surface is no longer alive
let cursor_status = seat
.user_data()
.get::<RefCell<CursorImageStatus>>()
.map(|cell| {
let mut cursor_status = cell.borrow_mut();
if let CursorImageStatus::Surface(ref surface) = *cursor_status {
if !surface.alive() {
*cursor_status = CursorImageStatus::Default;
}
// reset the cursor if the surface is no longer alive
let cursor_status = seat
.user_data()
.get::<RefCell<CursorImageStatus>>()
.map(|cell| {
let mut cursor_status = cell.borrow_mut();
if let CursorImageStatus::Surface(ref surface) = *cursor_status {
if !surface.alive() {
*cursor_status = CursorImageStatus::Default;
}
cursor_status.clone()
})
.unwrap_or(CursorImageStatus::Default);
}
cursor_status.clone()
})
.unwrap_or(CursorImageStatus::Default);
if let CursorImageStatus::Surface(ref wl_surface) = cursor_status {
return draw_surface_cursor(wl_surface, location.to_i32_round(), scale);
} else if draw_default && CursorImageStatus::Default == cursor_status {
let integer_scale = scale.x.max(scale.y).ceil() as u32;
if let CursorImageStatus::Surface(ref wl_surface) = cursor_status {
return draw_surface_cursor(wl_surface, location.to_i32_round(), scale);
} else if draw_default && CursorImageStatus::Default == cursor_status {
let integer_scale = scale.x.max(scale.y).ceil() as u32;
let seat_userdata = seat.user_data();
seat_userdata.insert_if_missing(CursorState::default);
let state = seat_userdata.get::<CursorState>().unwrap();
let frame = state
.cursor
.get_image(integer_scale, start_time.elapsed().as_millis() as u32);
let seat_userdata = seat.user_data();
seat_userdata.insert_if_missing(CursorState::default);
let state = seat_userdata.get::<CursorState>().unwrap();
let frame = state.cursor.get_image(
integer_scale,
Into::<Duration>::into(time).as_millis() as u32,
);
let mut cache = state.image_cache.borrow_mut();
let pointer_images = cache
.entry((
TypeId::of::<TextureBuffer<<R as Renderer>::TextureId>>(),
renderer.id(),
))
.or_default();
let mut cache = state.image_cache.borrow_mut();
let pointer_images = cache
.entry((TypeId::of::<TextureBuffer<R::TextureId>>(), renderer.id()))
.or_default();
let maybe_image = pointer_images
.iter()
.find_map(|(image, texture)| if image == &frame { Some(texture) } else { None })
.and_then(|texture| {
texture.downcast_ref::<TextureBuffer<<R as Renderer>::TextureId>>()
});
let pointer_image = match maybe_image {
Some(image) => image,
None => {
let texture = TextureBuffer::from_memory(
renderer,
&frame.pixels_rgba,
(frame.width as i32, frame.height as i32),
false,
integer_scale as i32,
Transform::Normal,
None,
)
.expect("Failed to import cursor bitmap");
pointer_images.push((frame.clone(), Box::new(texture.clone())));
pointer_images
.last()
.and_then(|(_, i)| {
i.downcast_ref::<TextureBuffer<<R as Renderer>::TextureId>>()
})
.unwrap()
}
};
let hotspot =
Point::<i32, Logical>::from((frame.xhot as i32, frame.yhot as i32)).to_f64();
*state.current_image.borrow_mut() = Some(frame);
return vec![CursorRenderElement::Static(
TextureRenderElement::from_texture_buffer(
(location - hotspot).to_physical(scale),
pointer_image,
let maybe_image = pointer_images
.iter()
.find_map(|(image, texture)| if image == &frame { Some(texture) } else { None })
.and_then(|texture| texture.downcast_ref::<TextureBuffer<R::TextureId>>());
let pointer_image = match maybe_image {
Some(image) => image,
None => {
let texture = TextureBuffer::from_memory(
renderer,
&frame.pixels_rgba,
(frame.width as i32, frame.height as i32),
false,
integer_scale as i32,
Transform::Normal,
None,
None,
),
)];
} else {
Vec::new()
}
)
.expect("Failed to import cursor bitmap");
pointer_images.push((frame.clone(), Box::new(texture.clone())));
pointer_images
.last()
.and_then(|(_, i)| i.downcast_ref::<TextureBuffer<R::TextureId>>())
.unwrap()
}
};
let hotspot = Point::<i32, Logical>::from((frame.xhot as i32, frame.yhot as i32)).to_f64();
*state.current_image.borrow_mut() = Some(frame);
return vec![CursorRenderElement::Static(
TextureRenderElement::from_texture_buffer(
(location - hotspot).to_physical(scale),
pointer_image,
None,
None,
None,
),
)];
} else {
Vec::new()
}
}