From 048e8dd1bac2f680b223039e4c916050c52f91ff Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Wed, 19 Apr 2023 10:29:01 -0700 Subject: [PATCH] wayland: fall back to 'default' for pointers that are not found This allows for potentially listing multiple candidate cursor names, like we do for x11, but doesn't add any. Attempt to load default if our desired cursor is not found. refs: https://github.com/wez/wezterm/issues/3334 --- window/src/os/wayland/pointer.rs | 22 ++++++++++++++++------ window/src/os/wayland/window.rs | 17 +++++++++-------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/window/src/os/wayland/pointer.rs b/window/src/os/wayland/pointer.rs index 5dc2f0f41..ec9f579df 100644 --- a/window/src/os/wayland/pointer.rs +++ b/window/src/os/wayland/pointer.rs @@ -340,16 +340,26 @@ impl PointerDispatcher { .insert(surface.as_ref().id(), Arc::clone(pending)); } - pub fn set_cursor(&self, name: Option<&str>, serial: Option) { + pub fn set_cursor(&self, names: &[&str], serial: Option) { let inner = self.inner.lock().unwrap(); let serial = serial.unwrap_or(inner.serial); - if let Some(name) = name { - if let Err(err) = self.auto_pointer.set_cursor(name, Some(serial)) { - log::error!("Unable to set cursor to {}: {:#}", name, err); - } - } else { + if names.is_empty() { (*self.auto_pointer).set_cursor(0, None, 0, 0); + } else { + let mut errors = vec![]; + for name in names { + match self.auto_pointer.set_cursor(name, Some(serial)) { + Ok(_) => return, + Err(err) => errors.push(format!("Unable to set cursor to {name}: {err:#}")), + } + } + + if let Err(err) = self.auto_pointer.set_cursor("default", Some(serial)) { + errors.push(format!("Unable to set cursor to 'default': {err:#}")); + } + + log::error!("set_cursor: {}", errors.join(", ")); } } } diff --git a/window/src/os/wayland/window.rs b/window/src/os/wayland/window.rs index 74c181280..4e57ccc0a 100644 --- a/window/src/os/wayland/window.rs +++ b/window/src/os/wayland/window.rs @@ -1107,15 +1107,16 @@ impl WaylandWindowInner { } fn set_cursor(&mut self, cursor: Option) { - let cursor = cursor.map(|cursor| match cursor { - MouseCursor::Arrow => "arrow", - MouseCursor::Hand => "hand", - MouseCursor::SizeUpDown => "ns-resize", - MouseCursor::SizeLeftRight => "ew-resize", - MouseCursor::Text => "xterm", - }); + let names: &[&str] = match cursor { + Some(MouseCursor::Arrow) => &["arrow"], + Some(MouseCursor::Hand) => &["hand"], + Some(MouseCursor::SizeUpDown) => &["ns-resize"], + Some(MouseCursor::SizeLeftRight) => &["ew-resize"], + Some(MouseCursor::Text) => &["xterm"], + None => &[], + }; let conn = Connection::get().unwrap().wayland(); - conn.pointer.borrow().set_cursor(cursor, None); + conn.pointer.borrow().set_cursor(names, None); } fn invalidate(&mut self) {