mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-21 02:01:55 +07:00
Implement focus-follows-mouse
This commit is contained in:
@@ -71,6 +71,8 @@ pub struct Input {
|
||||
pub disable_power_key_handling: bool,
|
||||
#[knuffel(child)]
|
||||
pub warp_mouse_to_focus: bool,
|
||||
#[knuffel(child)]
|
||||
pub focus_follows_mouse: bool,
|
||||
}
|
||||
|
||||
#[derive(knuffel::Decode, Debug, Default, PartialEq, Eq)]
|
||||
@@ -1596,6 +1598,7 @@ mod tests {
|
||||
disable-power-key-handling
|
||||
|
||||
warp-mouse-to-focus
|
||||
focus-follows-mouse
|
||||
}
|
||||
|
||||
output "eDP-1" {
|
||||
@@ -1736,6 +1739,7 @@ mod tests {
|
||||
},
|
||||
disable_power_key_handling: true,
|
||||
warp_mouse_to_focus: true,
|
||||
focus_follows_mouse: true,
|
||||
},
|
||||
outputs: vec![Output {
|
||||
off: false,
|
||||
|
||||
@@ -70,6 +70,9 @@ input {
|
||||
|
||||
// Uncomment this to make the mouse warp to the center of newly focused windows.
|
||||
// warp-mouse-to-focus
|
||||
|
||||
// Focus windows and outputs automatically when moving the mouse into them.
|
||||
// focus-follows-mouse
|
||||
}
|
||||
|
||||
// You can configure outputs by their name, which you can find
|
||||
|
||||
@@ -903,6 +903,8 @@ impl State {
|
||||
}
|
||||
}
|
||||
|
||||
self.niri.handle_focus_follows_mouse(&under);
|
||||
|
||||
// Activate a new confinement if necessary.
|
||||
self.niri.maybe_activate_pointer_constraint(new_pos, &under);
|
||||
|
||||
@@ -967,6 +969,9 @@ impl State {
|
||||
}
|
||||
|
||||
let under = self.niri.surface_under_and_global_space(pos);
|
||||
|
||||
self.niri.handle_focus_follows_mouse(&under);
|
||||
|
||||
self.niri.maybe_activate_pointer_constraint(pos, &under);
|
||||
self.niri.pointer_focus.clone_from(&under);
|
||||
|
||||
|
||||
+22
@@ -3305,6 +3305,28 @@ impl Niri {
|
||||
warn!("error spawning a thread to send MonitorsChanged: {err:?}");
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_focus_follows_mouse(&mut self, new_focus: &PointerFocus) {
|
||||
if !self.config.borrow().input.focus_follows_mouse {
|
||||
return;
|
||||
}
|
||||
|
||||
if self.seat.get_pointer().unwrap().is_grabbed() {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(output) = &new_focus.output {
|
||||
if self.pointer_focus.output.as_ref() != Some(output) {
|
||||
self.layout.focus_output(output);
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(window) = &new_focus.window {
|
||||
if self.pointer_focus.window.as_ref() != Some(window) {
|
||||
self.layout.activate_window(window);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ClientState {
|
||||
|
||||
Reference in New Issue
Block a user