Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read cursor file directly instead of first to Vec and then through xcursor #753

Open
psychon opened this issue Aug 10, 2024 · 0 comments
Open

Comments

@psychon
Copy link

psychon commented Aug 10, 2024

Hi there,

xcursor 0.3.7 just released and added an API that allows reading directly from a cursor file. The previously existing API could only read from an in-memory buffer, so the file had to be loaded into memory first and could then be parsed.

Basically, what I am trying to say is:

diff --git a/wayland-cursor/Cargo.toml b/wayland-cursor/Cargo.toml
index e940223d..51d8e05d 100644
--- a/wayland-cursor/Cargo.toml
+++ b/wayland-cursor/Cargo.toml
@@ -14,7 +14,7 @@ readme = "README.md"
 
 [dependencies]
 wayland-client = { version = "0.31.5", path = "../wayland-client" }
-xcursor = "0.3.1"
+xcursor = "0.3.7"
 rustix = { version = "0.38.15", features = ["shm"] }
 
 [package.metadata.docs.rs]
diff --git a/wayland-cursor/src/lib.rs b/wayland-cursor/src/lib.rs
index bc1751f8..e335cd79 100644
--- a/wayland-cursor/src/lib.rs
+++ b/wayland-cursor/src/lib.rs
@@ -49,7 +49,7 @@ use std::borrow::Cow;
 use std::env;
 use std::fmt::Debug;
 use std::fs::File;
-use std::io::{Error as IoError, Read, Result as IoResult, Seek, SeekFrom, Write};
+use std::io::{BufReader, Error as IoError, Result as IoResult, Seek, SeekFrom, Write};
 use std::ops::{Deref, Index};
 use std::os::unix::io::{AsFd, OwnedFd};
 use std::sync::Arc;
@@ -243,13 +243,9 @@ impl CursorTheme {
     fn load_cursor(&mut self, name: &str, size: u32) -> Option<Cursor> {
         let conn = Connection::from_backend(self.backend.upgrade()?);
         let icon_path = XCursorTheme::load(&self.name).load_icon(name)?;
-        let mut icon_file = File::open(icon_path).ok()?;
+        let mut icon_file = BufReader::new(File::open(icon_path).ok()?);
 
-        let mut buf = Vec::new();
-        let images = {
-            icon_file.read_to_end(&mut buf).ok()?;
-            xparser::parse_xcursor(&buf)?
-        };
+        let images = xparser::parse_xcursor_stream(&mut icon_file).ok()?;
 
         Some(Cursor::new(&conn, name, self, &images, size))
     }

I don't know about your version policy and I am too lazy to fork, so I am just leaving this here for your information. Feel free to just close this issue if this does not seem important to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant