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

warp cursor to center of window for cursor_follows_focus #884

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 7 additions & 7 deletions src/shell/focus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,29 +231,29 @@ fn update_focus_state(
if target.is_some() {
//need to borrow mutably for surface under
let mut shell = state.common.shell.write().unwrap();
// get the top left corner of the target element
// get geometry of the target element
let geometry = shell.focused_geometry(target.unwrap());
//to avoid the nested mutable borrow of state
if geometry.is_some() {
let top_left = geometry.unwrap().loc.to_f64();
if let Some(geometry) = geometry {
// get the center of the target element
let new_pos = (geometry.loc + geometry.size.downscale(2).to_point()).to_f64();

// create a pointer target from the target element
let output = shell
.outputs()
.find(|output| output.geometry().to_f64().contains(top_left))
.find(|output| output.geometry().to_f64().contains(new_pos))
.cloned()
.unwrap_or(seat.active_output());

let focus = shell
.surface_under(top_left, &output)
.surface_under(new_pos, &output)
.map(|(focus, loc)| (focus, loc.as_logical()));
//drop here to avoid multiple mutable borrows
mem::drop(shell);
seat.get_pointer().unwrap().motion(
state,
focus,
&MotionEvent {
location: top_left.as_logical(),
location: new_pos.as_logical(),
serial: SERIAL_COUNTER.next_serial(),
time: 0,
},
Expand Down
Loading