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 {
466466 /// The hit can activate a window, but it is not in the input region so cannot send events.
467467 ///
468468 /// 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+ },
470473 }
471474
472475 impl<W: LayoutElement> InteractiveMoveState<W> {
@@ -515,7 +518,7 @@ impl HitType {
515518 pub fn offset_win_pos(mut self, offset: Point<f64, Logical>) -> Self {
516519 match &mut self {
517520 HitType::Input { win_pos } => *win_pos += offset,
518- HitType::Activate => (),
521+ HitType::Activate { .. } => (),
519522 }
520523 self
521524 }
src/layout/scrolling.rsmodified+46 -1
@@ -14,7 +14,7 @@ use super::insert_hint_element::{InsertHintElement, InsertHintRenderElement};
1414 use super::tab_indicator::{TabIndicator, TabIndicatorRenderElement, TabInfo};
1515 use super::tile::{Tile, TileRenderElement, TileRenderSnapshot};
1616 use super::workspace::{InteractiveResize, ResolvedSize};
17-use super::{ConfigureIntent, InteractiveResizeData, LayoutElement, Options, RemovedTile};
17+use super::{ConfigureIntent, HitType, InteractiveResizeData, LayoutElement, Options, RemovedTile};
1818 use crate::animation::{Animation, Clock};
1919 use crate::input::swipe_tracker::SwipeTracker;
2020 use crate::niri_render_elements;
@@ -2645,6 +2645,51 @@ impl<W: LayoutElement> ScrollingSpace<W> {
26452645 rv
26462646 }
26472647
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+
26482693 pub fn view_offset_gesture_begin(&mut self, is_touchpad: bool) {
26492694 if self.columns.is_empty() {
26502695 return;
src/layout/tab_indicator.rsmodified+21 -0
@@ -182,6 +182,27 @@ impl TabIndicator {
182182 }
183183 }
184184
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+
185206 pub fn render(
186207 &self,
187208 renderer: &mut impl NiriRenderer,
src/layout/tile.rsmodified+3 -1
@@ -658,7 +658,9 @@ impl<W: LayoutElement> Tile<W> {
658658 let win_pos = self.buf_loc();
659659 Some(HitType::Input { win_pos })
660660 } else if self.is_in_activation_region(point) {
661- Some(HitType::Activate)
661+ Some(HitType::Activate {
662+ is_tab_indicator: false,
663+ })
662664 } else {
663665 None
664666 }
src/layout/workspace.rsmodified+11 -7
@@ -1475,14 +1475,18 @@ impl<W: LayoutElement> Workspace<W> {
14751475 }
14761476
14771477 pub fn window_under(&self, pos: Point<f64, Logical>) -> Option<(&W, HitType)> {
1478- self.tiles_with_render_positions()
1479- .find_map(|(tile, tile_pos, visible)| {
1480- if !visible {
1481- return None;
1482- }
1478+ // This logic is consistent with tiles_with_render_positions().
1479+ if self.is_floating_visible() {
1480+ if let Some(rv) = self
1481+ .floating
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+ }
14831488
1484- HitType::hit_tile(tile, tile_pos, pos)
1485- })
1489+ self.scrolling.window_under(pos)
14861490 }
14871491
14881492 pub fn resize_edges_under(&self, pos: Point<f64, Logical>) -> Option<ResizeEdge> {
src/niri.rsmodified+11 -1
@@ -5060,7 +5060,17 @@ impl Niri {
50605060
50615061 if let Some(window) = &new_focus.window {
50625062 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+ }
50645074
50655075 if !self.layout.should_trigger_focus_follows_mouse_on(window) {
50665076 return;