Focus window on mouse hover

This commit is contained in:
Victor Timofei 2021-12-11 14:14:12 +02:00
parent 6b1788d002
commit 145c0bc2df
Signed by: vtimofei
GPG Key ID: B790DCEBE281403A
1 changed files with 19 additions and 14 deletions

View File

@ -112,18 +112,7 @@ impl<Backend> AnvilState<Backend> {
let serial = SCOUNTER.next_serial();
let button = evt.button_code();
let state = match evt.state() {
input::ButtonState::Pressed => {
// change the keyboard focus unless the pointer is grabbed
if !self.pointer.is_grabbed() {
let under = self
.window_map
.borrow_mut()
.get_surface_and_bring_to_top(self.pointer_location);
self.keyboard
.set_focus(under.as_ref().map(|&(ref s, _)| s), serial);
}
wl_pointer::ButtonState::Pressed
}
input::ButtonState::Pressed => wl_pointer::ButtonState::Pressed,
input::ButtonState::Released => wl_pointer::ButtonState::Released,
};
self.pointer.button(button, state, serial, evt.time());
@ -236,7 +225,15 @@ impl<Backend> AnvilState<Backend> {
let pos = evt.position_transformed(output_size);
self.pointer_location = pos;
let serial = SCOUNTER.next_serial();
let under = self.window_map.borrow().get_surface_under(pos);
let under;
// set focus for this window
if !self.pointer.is_grabbed() {
under = self.window_map.borrow_mut().get_surface_and_bring_to_top(pos);
self.keyboard
.set_focus(under.as_ref().map(|&(ref s, _)| s), serial);
} else {
under = self.window_map.borrow().get_surface_under(pos);
}
self.pointer.motion(pos, under, serial, evt.time());
}
}
@ -358,7 +355,15 @@ impl AnvilState<UdevData> {
// this event is never generated by winit
self.pointer_location = self.clamp_coords(self.pointer_location);
let under = self.window_map.borrow().get_surface_under(self.pointer_location);
let under;
// set focus for this window
if !self.pointer.is_grabbed() {
under = self.window_map.borrow_mut().get_surface_and_bring_to_top(self.pointer_location);
self.keyboard
.set_focus(under.as_ref().map(|&(ref s, _)| s), serial);
} else {
under = self.window_map.borrow().get_surface_under(self.pointer_location);
}
self.pointer
.motion(self.pointer_location, under, serial, evt.time());
}