wayland: Improve cursor (#10516)
Fixes the cursor not updating when (a) switching windows from another program via a shortcut and (b) when cursor updates were triggered by something other than moving the mouse (e.g. when scrolling or pressing a key). Release Notes: - N/A
This commit is contained in:
parent
58f57491b1
commit
3eb8464d19
2 changed files with 33 additions and 12 deletions
|
@ -8,7 +8,7 @@ use wayland_cursor::{CursorImageBuffer, CursorTheme};
|
|||
|
||||
pub(crate) struct Cursor {
|
||||
theme: Option<CursorTheme>,
|
||||
current_icon_name: String,
|
||||
current_icon_name: Option<String>,
|
||||
surface: WlSurface,
|
||||
serial_id: u32,
|
||||
}
|
||||
|
@ -24,19 +24,29 @@ impl Cursor {
|
|||
pub fn new(connection: &Connection, globals: &Globals, size: u32) -> Self {
|
||||
Self {
|
||||
theme: CursorTheme::load(&connection, globals.shm.clone(), size).log_err(),
|
||||
current_icon_name: "default".to_string(),
|
||||
current_icon_name: None,
|
||||
surface: globals.compositor.create_surface(&globals.qh, ()),
|
||||
serial_id: 0,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mark_dirty(&mut self) {
|
||||
self.current_icon_name = None;
|
||||
}
|
||||
|
||||
pub fn set_serial_id(&mut self, serial_id: u32) {
|
||||
self.serial_id = serial_id;
|
||||
}
|
||||
|
||||
pub fn set_icon(&mut self, wl_pointer: &WlPointer, mut cursor_icon_name: Option<&str>) {
|
||||
let mut cursor_icon_name = cursor_icon_name.unwrap_or("default");
|
||||
if self.current_icon_name != cursor_icon_name {
|
||||
pub fn set_icon(&mut self, wl_pointer: &WlPointer, mut cursor_icon_name: &str) {
|
||||
let need_update = self
|
||||
.current_icon_name
|
||||
.as_ref()
|
||||
.map_or(true, |current_icon_name| {
|
||||
current_icon_name != cursor_icon_name
|
||||
});
|
||||
|
||||
if need_update {
|
||||
if let Some(theme) = &mut self.theme {
|
||||
let mut buffer: Option<&CursorImageBuffer>;
|
||||
|
||||
|
@ -68,7 +78,7 @@ impl Cursor {
|
|||
self.surface.damage(0, 0, width as i32, height as i32);
|
||||
self.surface.commit();
|
||||
|
||||
self.current_icon_name = cursor_icon_name.to_string();
|
||||
self.current_icon_name = Some(cursor_icon_name.to_string());
|
||||
}
|
||||
} else {
|
||||
log::warn!("Linux: Wayland: Unable to load cursor themes");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue