Skip to main content

ClientGrid

Struct ClientGrid 

pub(super) struct ClientGrid {
    pub cols: i32,
    pub rows: i32,
    last_row_count: i32,
    cells: Vec<GridCell>,
    by_pid: HashMap<u32, usize>,
}
Expand description

Spatial-grid view over the tracked client PIDs.

Fields§

§cols: i32

Number of columns in the dense upper rows.

§rows: i32

Total number of rows (>= 1 whenever there is at least one cell).

§last_row_count: i32

Cell count in the last row. 0 means the last row is also dense; otherwise 1..cols last-row cells are stretched proportionally.

§cells: Vec<GridCell>

Cells sorted by (row, col) so the top-left cell is at index 0.

§by_pid: HashMap<u32, usize>

PID lookup table.

Implementations§

§

impl ClientGrid

pub(super) fn from_tiled_pids( cells: &[(u32, usize)], layout_n: i32, cols: i32, rows: i32, ) -> Self

Build the grid from (pid, tile_index) pairs and the dimensions returned by grid_dimensions for the same layout_n.

tile_index is the position each client was assigned the last time the tiler positioned its window. Surviving clients keep their tile_index across closures, so passing them here together with the layout’s original layout_n produces a grid whose cells land at the same (row, col) the user sees on screen - with gaps where a window was closed but no retile has happened yet.

§Arguments
  • cells - (pid, tile_index) pairs for every surviving client.
  • layout_n - The number_of_consoles the on-screen layout was last computed with. Used to derive the partial-last-row stretch.
  • cols - Columns from grid_dimensions for layout_n.
  • rows - Rows from grid_dimensions for layout_n.
§Returns

A populated ClientGrid.

pub(super) fn cell(&self, pid: u32) -> Option<&GridCell>

Look up the cell owned by pid.

§Arguments
  • pid - Process id to look up.
§Returns

Some(&GridCell) when present, None otherwise.

pub(super) fn top_left_pid(&self) -> Option<u32>

PID of the top-left cell, or None for an empty grid. Used to re-anchor the submenu selection onto a sensible visual default.

pub(super) fn is_empty(&self) -> bool

true when the grid has no cells.

pub(super) fn anchor_for(&self, cell: &GridCell) -> i32

Compute the anchor column for a cell. Horizontal moves overwrite the in-flight anchor with the destination cell’s anchor.

Upper-row cells: their col (each cell occupies exactly one upper-grid column). Partial-last-row cells: the upper-grid column containing the cell’s x-midpoint. The latter makes a Down + Up roundtrip return to the original cell from any starting point.

§Arguments
  • cell - The destination cell.
§Returns

The anchor column for the cell.

pub(super) fn step( &self, pid: u32, anchor_col: i32, direction: NavigationDirection, edge: EdgeBehavior, ) -> Option<(u32, i32)>

Compute the next selection after one navigation keystroke.

§Arguments
  • pid - Currently highlighted PID.
  • anchor_col - Anchor column carried from earlier moves.
  • direction - Direction of the keystroke.
  • edge - Behavior when the move would leave the grid.
§Returns

Some((new_pid, new_anchor_col)) on a successful step. None when pid is not present in this grid (caller should re-anchor).

fn step_horizontal( &self, current: &GridCell, anchor_col: i32, direction: NavigationDirection, edge: EdgeBehavior, ) -> Option<(u32, i32)>

Horizontal step within current.row. Returns None only when the row somehow contains no cells (cannot happen for a valid current looked up from the grid). A clamped no-op preserves the in-flight anchor_col so a subsequent vertical step still targets the column the user originally carried over.

fn step_vertical( &self, current: &GridCell, anchor_col: i32, direction: NavigationDirection, edge: EdgeBehavior, ) -> (u32, i32)

Vertical step into the target row, preserving the in-flight anchor_col.

fn anchor_distance( &self, cell: &GridCell, anchor_col: i32, is_partial_last_row: bool, ) -> i64

Spatial distance between a cell and an anchor column, used to pick the target on a vertical step. Dense rows reduce to |c.col - anchor|; partial-last-row cells use their stretched x-extent so the cell whose midpoint is closest to the anchor’s centerline wins. The result is in arbitrary integer units valid only for comparisons within the same row.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.