@@ -5,7 +5,7 @@ use smithay::{
55 utils:: { Logical , Physical , Point , Transform } ,
66 wayland:: compositor:: with_states,
77} ;
8- use std:: { collections:: HashMap , fmt:: Debug , io:: Read , time:: Duration } ;
8+ use std:: { cell :: OnceCell , collections:: HashMap , fmt:: Debug , io:: Read , time:: Duration } ;
99use xcursor:: { CursorTheme , parser:: Image } ;
1010
1111const FALLBACK_CURSOR_DATA : & [ u8 ] = include_bytes ! ( "../resources/cursor.rgba" ) ;
@@ -16,7 +16,7 @@ pub enum RenderCursor<'a> {
1616 hotspot : Point < i32 , Logical > ,
1717 surface : WlSurface ,
1818 } ,
19- Named ( & ' a mut XCursor ) ,
19+ Named ( & ' a XCursor ) ,
2020}
2121
2222#[ derive( Debug ) ]
@@ -59,7 +59,7 @@ impl Cursor {
5959 self . cache . clear ( ) ;
6060 }
6161
62- fn get_named_cursor ( & mut self , icon : CursorIcon ) -> & mut XCursor {
62+ fn get_named_cursor ( & mut self , icon : CursorIcon ) -> & XCursor {
6363 self . cache . entry ( icon) . or_insert_with ( || {
6464 // todo scale
6565 let size = self . size ;
@@ -122,20 +122,23 @@ fn load_cursor_theme(
122122#[ derive( Debug ) ]
123123pub struct Frame {
124124 image : Image ,
125- buffer : Option < MemoryRenderBuffer > ,
125+ buffer : OnceCell < MemoryRenderBuffer > ,
126126}
127127
128128impl Frame {
129129 pub fn new ( image : Image ) -> Self {
130- Frame { image, buffer : None }
130+ Frame {
131+ image,
132+ buffer : OnceCell :: new ( ) ,
133+ }
131134 }
132135
133136 pub fn hotspot ( & self ) -> Point < i32 , Physical > {
134137 Point :: from ( ( self . image . xhot as i32 , self . image . yhot as i32 ) )
135138 }
136139
137- pub fn buffer ( & mut self ) -> & MemoryRenderBuffer {
138- self . buffer . get_or_insert_with ( || {
140+ pub fn buffer ( & self ) -> & MemoryRenderBuffer {
141+ self . buffer . get_or_init ( || {
139142 MemoryRenderBuffer :: from_slice (
140143 & self . image . pixels_rgba ,
141144 Fourcc :: Argb8888 ,
@@ -199,15 +202,15 @@ impl XCursor {
199202 }
200203 }
201204
202- pub fn frame ( & mut self , duration : Duration ) -> & mut Frame {
205+ pub fn frame ( & self , duration : Duration ) -> & Frame {
203206 if self . animation_duration == 0 {
204- return & mut self . frames [ 0 ] ;
207+ return & self . frames [ 0 ] ;
205208 }
206209
207210 let mut millis = duration. as_millis ( ) as u32 ;
208211 millis %= self . animation_duration ;
209212
210- for frame in & mut self . frames {
213+ for frame in & self . frames {
211214 if millis < frame. image . delay {
212215 return frame;
213216 }
0 commit comments