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

Try alternative cursor icon names #427

Merged
merged 3 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rustdoc-args = ["--cfg", "docsrs"]
[dependencies]
bitflags = "2.4"
bytemuck = { version = "1.13.0", optional = true }
cursor-icon = "1.0.0"
cursor-icon = "1.1.0"
libc = "0.2.148"
log = "0.4"
memmap2 = "0.9.0"
Expand Down
52 changes: 31 additions & 21 deletions src/seat/pointer/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
collections::{hash_map::Entry, HashMap},
env, mem,
env, iter, mem,
sync::{Arc, Mutex},
};

Expand Down Expand Up @@ -458,31 +458,41 @@ impl<U: PointerDataExt + 'static, S: SurfaceDataExt + 'static> ThemedPointer<U,
let mut themes = self.themes.lock().unwrap();

let scale = self.surface.data::<S>().unwrap().surface_data().scale_factor();
let cursor = themes
.get_cursor(conn, icon.name(), scale as u32, &self.shm)
.map_err(PointerThemeError::InvalidId)?
.ok_or(PointerThemeError::CursorNotFound)?;
for cursor_icon_name in iter::once(&icon.name()).chain(icon.alt_names().iter()) {
if let Some(cursor) = themes
.get_cursor(conn, cursor_icon_name, scale as u32, &self.shm)
.map_err(PointerThemeError::InvalidId)?
{
let image = &cursor[0];
let (w, h) = image.dimensions();
let (hx, hy) = image.hotspot();

self.surface.set_buffer_scale(scale);
self.surface.attach(Some(image), 0, 0);

if self.surface.version() >= 4 {
self.surface.damage_buffer(0, 0, w as i32, h as i32);
} else {
// Fallback for the old old surface.
self.surface.damage(0, 0, w as i32 / scale, h as i32 / scale);
}

let image = &cursor[0];
let (w, h) = image.dimensions();
let (hx, hy) = image.hotspot();
// Commit the surface to place the cursor image in the compositor's memory.
self.surface.commit();

self.surface.set_buffer_scale(scale);
self.surface.attach(Some(image), 0, 0);
// Set the pointer surface to change the pointer.
self.pointer.set_cursor(
serial,
Some(&self.surface),
hx as i32 / scale,
hy as i32 / scale,
);

if self.surface.version() >= 4 {
self.surface.damage_buffer(0, 0, w as i32, h as i32);
} else {
// Fallback for the old old surface.
self.surface.damage(0, 0, w as i32 / scale, h as i32 / scale);
return Ok(());
}
}

// Commit the surface to place the cursor image in the compositor's memory.
self.surface.commit();

// Set the pointer surface to change the pointer.
self.pointer.set_cursor(serial, Some(&self.surface), hx as i32 / scale, hy as i32 / scale);
Ok(())
Err(PointerThemeError::CursorNotFound)
}

/// Hide the cursor by providing empty surface for it.
Expand Down
Loading