aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/layout/mod.rs16
-rw-r--r--src/layout/workspace.rs31
-rw-r--r--src/niri.rs10
3 files changed, 55 insertions, 2 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index ab7d7ec6..fadde1fb 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -947,6 +947,22 @@ impl<W: LayoutElement> Layout<W> {
}
}
+ pub fn scroll_amount_to_activate(&self, window: &W::Id) -> f64 {
+ let MonitorSet::Normal { monitors, .. } = &self.monitor_set else {
+ return 0.;
+ };
+
+ for mon in monitors {
+ for ws in &mon.workspaces {
+ if ws.has_window(window) {
+ return ws.scroll_amount_to_activate(window);
+ }
+ }
+ }
+
+ 0.
+ }
+
pub fn activate_window(&mut self, window: &W::Id) {
let MonitorSet::Normal {
monitors,
diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs
index c5ddfd21..625f4d5c 100644
--- a/src/layout/workspace.rs
+++ b/src/layout/workspace.rs
@@ -1391,6 +1391,37 @@ impl<W: LayoutElement> Workspace<W> {
}
}
+ pub fn scroll_amount_to_activate(&self, window: &W::Id) -> f64 {
+ let column_idx = self
+ .columns
+ .iter()
+ .position(|col| col.contains(window))
+ .unwrap();
+
+ if self.active_column_idx == column_idx {
+ return 0.;
+ }
+
+ let current_x = self.view_pos();
+ let new_view_offset = self.compute_new_view_offset_for_column(
+ current_x,
+ column_idx,
+ Some(self.active_column_idx),
+ );
+
+ // Consider the end of an ongoing animation because that's what compute to fit does too.
+ let final_x = if let Some(ViewOffsetAdjustment::Animation(anim)) = &self.view_offset_adj {
+ current_x - self.view_offset + anim.to()
+ } else {
+ current_x
+ };
+
+ let new_col_x = self.column_x(column_idx);
+ let from_view_offset = final_x - new_col_x;
+
+ (from_view_offset - new_view_offset).abs() / self.working_area.size.w
+ }
+
pub fn activate_window(&mut self, window: &W::Id) {
let column_idx = self
.columns
diff --git a/src/niri.rs b/src/niri.rs
index 08331bef..2ff2f014 100644
--- a/src/niri.rs
+++ b/src/niri.rs
@@ -4140,9 +4140,9 @@ impl Niri {
}
pub fn handle_focus_follows_mouse(&mut self, new_focus: &PointerFocus) {
- if !self.config.borrow().input.focus_follows_mouse {
+ let Some(ffm) = self.config.borrow().input.focus_follows_mouse else {
return;
- }
+ };
let pointer = &self.seat.get_pointer().unwrap();
if pointer.is_grabbed() {
@@ -4160,6 +4160,12 @@ impl Niri {
if let Some(window) = &new_focus.window {
if current_focus.window.as_ref() != Some(window) {
+ if let Some(threshold) = ffm.max_scroll_amount {
+ if self.layout.scroll_amount_to_activate(window) > threshold.0 {
+ return;
+ }
+ }
+
self.layout.activate_window(window);
}
}