wayland: reject cursor hint requests that are outside the surface bound

This commit is contained in:
Skygrango 2026-06-05 23:35:29 +08:00 committed by Jacob Kauffmann
parent b6cab38528
commit 296b6bee23

View file

@ -2393,7 +2393,7 @@ impl State {
}); });
if let Some((output, geometry, surface_offset)) = found { if let Some((output, geometry, surface_offset)) = found {
let mut pos_in_element = location + surface_offset.to_f64(); let pos_in_element = location + surface_offset.to_f64();
let window_size = geometry.size.to_f64(); let window_size = geometry.size.to_f64();
let is_legal = |p: Point<f64, Logical>| { let is_legal = |p: Point<f64, Logical>| {
@ -2417,29 +2417,13 @@ impl State {
let workspace_origin = output.geometry().loc.to_f64(); let workspace_origin = output.geometry().loc.to_f64();
let origin = geometry.loc.to_f64(); let origin = geometry.loc.to_f64();
if !is_legal(pos_in_element) { if is_legal(pos_in_element) {
let original_global = pointer.current_location(); let x = workspace_origin.x + origin.x + pos_in_element.x;
let y = workspace_origin.y + origin.y + pos_in_element.y;
let original_pos_in_element = Point::new( Some((Point::new(x, y), output.clone()))
original_global.x - workspace_origin.x - origin.x, } else {
original_global.y - workspace_origin.y - origin.y, None
);
let y_only_pos = Point::new(original_pos_in_element.x, pos_in_element.y);
let x_only_pos = Point::new(pos_in_element.x, original_pos_in_element.y);
if is_legal(y_only_pos) {
pos_in_element = y_only_pos;
} else if is_legal(x_only_pos) {
pos_in_element = x_only_pos;
} else {
pos_in_element = original_pos_in_element;
}
} }
let x = workspace_origin.x + origin.x + pos_in_element.x;
let y = workspace_origin.y + origin.y + pos_in_element.y;
Some((Point::new(x, y), output.clone()))
} else { } else {
None None
} }