forge
Explore
Log in

Don't you dare go Hollow

Implement clicking on tab to switch

Browse files at this commit

6942ecc13a40867850fc26429da21603647e8026Ivan MolodetskikhParent: 963ff14
src/layout/mod.rsmodified+5 -2
@@ -466,7 +466,10 @@ pub enum HitType {
466 /// The hit can activate a window, but it is not in the input region so cannot send events.466 /// The hit can activate a window, but it is not in the input region so cannot send events.
467 ///467 ///
468 /// For example, this could be clicking on a tile border outside the window.468 /// For example, this could be clicking on a tile border outside the window.
469- Activate,469+ Activate {
470+ /// Whether the hit was on the tab indicator.
471+ is_tab_indicator: bool,
472+ },
470 }473 }
471 474
472 impl<W: LayoutElement> InteractiveMoveState<W> {475 impl<W: LayoutElement> InteractiveMoveState<W> {
@@ -515,7 +518,7 @@ impl HitType {
515 pub fn offset_win_pos(mut self, offset: Point<f64, Logical>) -> Self {518 pub fn offset_win_pos(mut self, offset: Point<f64, Logical>) -> Self {
516 match &mut self {519 match &mut self {
517 HitType::Input { win_pos } => *win_pos += offset,520 HitType::Input { win_pos } => *win_pos += offset,
518- HitType::Activate => (),521+ HitType::Activate { .. } => (),
519 }522 }
520 self523 self
521 }524 }
src/layout/scrolling.rsmodified+46 -1
@@ -14,7 +14,7 @@ use super::insert_hint_element::{InsertHintElement, InsertHintRenderElement};
14 use super::tab_indicator::{TabIndicator, TabIndicatorRenderElement, TabInfo};14 use super::tab_indicator::{TabIndicator, TabIndicatorRenderElement, TabInfo};
15 use super::tile::{Tile, TileRenderElement, TileRenderSnapshot};15 use super::tile::{Tile, TileRenderElement, TileRenderSnapshot};
16 use super::workspace::{InteractiveResize, ResolvedSize};16 use super::workspace::{InteractiveResize, ResolvedSize};
17-use super::{ConfigureIntent, InteractiveResizeData, LayoutElement, Options, RemovedTile};17+use super::{ConfigureIntent, HitType, InteractiveResizeData, LayoutElement, Options, RemovedTile};
18 use crate::animation::{Animation, Clock};18 use crate::animation::{Animation, Clock};
19 use crate::input::swipe_tracker::SwipeTracker;19 use crate::input::swipe_tracker::SwipeTracker;
20 use crate::niri_render_elements;20 use crate::niri_render_elements;
@@ -2645,6 +2645,51 @@ impl<W: LayoutElement> ScrollingSpace<W> {
2645 rv2645 rv
2646 }2646 }
2647 2647
2648+ pub fn window_under(&self, pos: Point<f64, Logical>) -> Option<(&W, HitType)> {
2649+ // This matches self.tiles_with_render_positions().
2650+ let scale = self.scale;
2651+ let view_off = Point::from((-self.view_pos(), 0.));
2652+ for (col, col_x) in self.columns_in_render_order() {
2653+ let col_off = Point::from((col_x, 0.));
2654+ let col_render_off = col.render_offset();
2655+
2656+ // Hit the tab indicator.
2657+ if col.display_mode == ColumnDisplay::Tabbed && !col.is_fullscreen {
2658+ let col_pos = view_off + col_off + col_render_off;
2659+ let col_pos = col_pos.to_physical_precise_round(scale).to_logical(scale);
2660+
2661+ if let Some(idx) = col.tab_indicator.hit(
2662+ col.tab_indicator_area(),
2663+ col.tiles.len(),
2664+ scale,
2665+ pos - col_pos,
2666+ ) {
2667+ let hit = HitType::Activate {
2668+ is_tab_indicator: true,
2669+ };
2670+ return Some((col.tiles[idx].window(), hit));
2671+ }
2672+ }
2673+
2674+ for (tile, tile_off, visible) in col.tiles_in_render_order() {
2675+ if !visible {
2676+ continue;
2677+ }
2678+
2679+ let tile_pos =
2680+ view_off + col_off + col_render_off + tile_off + tile.render_offset();
2681+ // Round to physical pixels.
2682+ let tile_pos = tile_pos.to_physical_precise_round(scale).to_logical(scale);
2683+
2684+ if let Some(rv) = HitType::hit_tile(tile, tile_pos, pos) {
2685+ return Some(rv);
2686+ }
2687+ }
2688+ }
2689+
2690+ None
2691+ }
2692+
2648 pub fn view_offset_gesture_begin(&mut self, is_touchpad: bool) {2693 pub fn view_offset_gesture_begin(&mut self, is_touchpad: bool) {
2649 if self.columns.is_empty() {2694 if self.columns.is_empty() {
2650 return;2695 return;
src/layout/tab_indicator.rsmodified+21 -0
@@ -182,6 +182,27 @@ impl TabIndicator {
182 }182 }
183 }183 }
184 184
185+ pub fn hit(
186+ &self,
187+ area: Rectangle<f64, Logical>,
188+ tab_count: usize,
189+ scale: f64,
190+ point: Point<f64, Logical>,
191+ ) -> Option<usize> {
192+ if self.config.off {
193+ return None;
194+ }
195+
196+ let count = tab_count;
197+ if self.config.hide_when_single_tab && count == 1 {
198+ return None;
199+ }
200+
201+ self.tab_rects(area, count, scale)
202+ .enumerate()
203+ .find_map(|(idx, rect)| rect.contains(point).then_some(idx))
204+ }
205+
185 pub fn render(206 pub fn render(
186 &self,207 &self,
187 renderer: &mut impl NiriRenderer,208 renderer: &mut impl NiriRenderer,
src/layout/tile.rsmodified+3 -1
@@ -658,7 +658,9 @@ impl<W: LayoutElement> Tile<W> {
658 let win_pos = self.buf_loc();658 let win_pos = self.buf_loc();
659 Some(HitType::Input { win_pos })659 Some(HitType::Input { win_pos })
660 } else if self.is_in_activation_region(point) {660 } else if self.is_in_activation_region(point) {
661- Some(HitType::Activate)661+ Some(HitType::Activate {
662+ is_tab_indicator: false,
663+ })
662 } else {664 } else {
663 None665 None
664 }666 }
src/layout/workspace.rsmodified+11 -7
@@ -1475,14 +1475,18 @@ impl<W: LayoutElement> Workspace<W> {
1475 }1475 }
1476 1476
1477 pub fn window_under(&self, pos: Point<f64, Logical>) -> Option<(&W, HitType)> {1477 pub fn window_under(&self, pos: Point<f64, Logical>) -> Option<(&W, HitType)> {
1478- self.tiles_with_render_positions()1478+ // This logic is consistent with tiles_with_render_positions().
1479- .find_map(|(tile, tile_pos, visible)| {1479+ if self.is_floating_visible() {
1480- if !visible {1480+ if let Some(rv) = self
1481- return None;1481+ .floating
1482- }1482+ .tiles_with_render_positions()
1483+ .find_map(|(tile, tile_pos)| HitType::hit_tile(tile, tile_pos, pos))
1484+ {
1485+ return Some(rv);
1486+ }
1487+ }
1483 1488
1484- HitType::hit_tile(tile, tile_pos, pos)1489+ self.scrolling.window_under(pos)
1485- })
1486 }1490 }
1487 1491
1488 pub fn resize_edges_under(&self, pos: Point<f64, Logical>) -> Option<ResizeEdge> {1492 pub fn resize_edges_under(&self, pos: Point<f64, Logical>) -> Option<ResizeEdge> {
src/niri.rsmodified+11 -1
@@ -5060,7 +5060,17 @@ impl Niri {
5060 5060
5061 if let Some(window) = &new_focus.window {5061 if let Some(window) = &new_focus.window {
5062 if current_focus.window.as_ref() != Some(window) {5062 if current_focus.window.as_ref() != Some(window) {
5063- let (window, _) = window;5063+ let (window, hit) = window;
5064+
5065+ // Don't trigger focus-follows-mouse over the tab indicator.
5066+ if matches!(
5067+ hit,
5068+ HitType::Activate {
5069+ is_tab_indicator: true
5070+ }
5071+ ) {
5072+ return;
5073+ }
5064 5074
5065 if !self.layout.should_trigger_focus_follows_mouse_on(window) {5075 if !self.layout.should_trigger_focus_follows_mouse_on(window) {
5066 return;5076 return;