aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2023-10-26 17:28:28 +0400
committerIvan Molodetskikh <yalterz@gmail.com>2023-10-29 10:45:24 +0400
commit0e0764ef37b3182c98fb63a1c3b180e223e3f943 (patch)
tree2f7b691077f8179676a3b3f1c7eab19d60d2061d /src
parent345428bce76281efeee91336768c2d38282f8027 (diff)
downloadniri-0e0764ef37b3182c98fb63a1c3b180e223e3f943.tar.gz
niri-0e0764ef37b3182c98fb63a1c3b180e223e3f943.tar.bz2
niri-0e0764ef37b3182c98fb63a1c3b180e223e3f943.zip
cursor: Make cache.get() accept &self
Diffstat (limited to 'src')
-rw-r--r--src/cursor.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/cursor.rs b/src/cursor.rs
index 1ed3600f..46d2b689 100644
--- a/src/cursor.rs
+++ b/src/cursor.rs
@@ -1,3 +1,4 @@
+use std::cell::RefCell;
use std::collections::HashMap;
use std::env;
use std::fs::File;
@@ -13,10 +14,12 @@ use xcursor::CursorTheme;
static FALLBACK_CURSOR_DATA: &[u8] = include_bytes!("../resources/cursor.rgba");
+type CursorCache = HashMap<i32, (TextureBuffer<GlesTexture>, Point<i32, Physical>)>;
+
pub struct Cursor {
images: Vec<Image>,
size: i32,
- cache: HashMap<i32, (TextureBuffer<GlesTexture>, Point<i32, Physical>)>,
+ cache: RefCell<CursorCache>,
}
impl Cursor {
@@ -47,16 +50,17 @@ impl Cursor {
Self {
images,
size: size as i32,
- cache: HashMap::new(),
+ cache: Default::default(),
}
}
pub fn get(
- &mut self,
+ &self,
renderer: &mut GlesRenderer,
scale: i32,
) -> (TextureBuffer<GlesTexture>, Point<i32, Physical>) {
self.cache
+ .borrow_mut()
.entry(scale)
.or_insert_with_key(|scale| {
let _span = tracy_client::span!("create cursor texture");
@@ -93,7 +97,7 @@ impl Cursor {
}
pub fn get_cached_hotspot(&self, scale: i32) -> Option<Point<i32, Physical>> {
- self.cache.get(&scale).map(|(_, hotspot)| *hotspot)
+ self.cache.borrow().get(&scale).map(|(_, hotspot)| *hotspot)
}
}