1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-22 22:42:48 +03:00

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
This commit is contained in:
Wez Furlong 2023-04-19 10:29:01 -07:00
parent 21e19ca091
commit 048e8dd1ba
No known key found for this signature in database
GPG Key ID: 7A7F66A31EC9B387
2 changed files with 25 additions and 14 deletions

View File

@ -340,16 +340,26 @@ impl PointerDispatcher {
.insert(surface.as_ref().id(), Arc::clone(pending));
}
pub fn set_cursor(&self, name: Option<&str>, serial: Option<u32>) {
pub fn set_cursor(&self, names: &[&str], serial: Option<u32>) {
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(", "));
}
}
}

View File

@ -1107,15 +1107,16 @@ impl WaylandWindowInner {
}
fn set_cursor(&mut self, cursor: Option<MouseCursor>) {
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) {