From ab7d81aae00e88395f85b629489512b4a7bac064 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Thu, 10 Oct 2024 09:24:20 +0300 Subject: layout: Reduce field visibility The outside code isn't supposed to mess with the fields. --- src/layout/mod.rs | 2 +- src/layout/monitor.rs | 22 +++++++++++++++------- src/layout/tile.rs | 2 +- src/layout/workspace.rs | 26 +++++++++++++++----------- 4 files changed, 32 insertions(+), 20 deletions(-) (limited to 'src/layout') diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 7c4d4618..05cbdccd 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -81,7 +81,7 @@ pub type LayoutElementRenderSnapshot = #[derive(Debug, Clone, Copy)] pub struct InteractiveResizeData { - pub edges: ResizeEdge, + pub(self) edges: ResizeEdge, } #[derive(Debug, Clone, Copy)] diff --git a/src/layout/monitor.rs b/src/layout/monitor.rs index 2bd84665..a4960012 100644 --- a/src/layout/monitor.rs +++ b/src/layout/monitor.rs @@ -33,19 +33,19 @@ const WORKSPACE_GESTURE_RUBBER_BAND: RubberBand = RubberBand { #[derive(Debug)] pub struct Monitor { /// Output for this monitor. - pub output: Output, + pub(super) output: Output, /// Cached name of the output. output_name: String, // Must always contain at least one. - pub workspaces: Vec>, + pub(super) workspaces: Vec>, /// Index of the currently active workspace. - pub active_workspace_idx: usize, + pub(super) active_workspace_idx: usize, /// ID of the previously active workspace. - pub previous_workspace_id: Option, + pub(super) previous_workspace_id: Option, /// In-progress switch between workspaces. - pub workspace_switch: Option, + pub(super) workspace_switch: Option, /// Configurable properties of the layout. - pub options: Rc, + pub(super) options: Rc, } #[derive(Debug)] @@ -59,7 +59,7 @@ pub struct WorkspaceSwitchGesture { /// Index of the workspace where the gesture was started. center_idx: usize, /// Current, fractional workspace index. - pub current_idx: f64, + pub(super) current_idx: f64, tracker: SwipeTracker, /// Whether the gesture is controlled by the touchpad. is_touchpad: bool, @@ -105,10 +105,18 @@ impl Monitor { } } + pub fn output(&self) -> &Output { + &self.output + } + pub fn output_name(&self) -> &String { &self.output_name } + pub fn active_workspace_idx(&self) -> usize { + self.active_workspace_idx + } + pub fn active_workspace_ref(&self) -> &Workspace { &self.workspaces[self.active_workspace_idx] } diff --git a/src/layout/tile.rs b/src/layout/tile.rs index 11c266d4..28b3ffd0 100644 --- a/src/layout/tile.rs +++ b/src/layout/tile.rs @@ -74,7 +74,7 @@ pub struct Tile { scale: f64, /// Configurable properties of the layout. - pub options: Rc, + pub(super) options: Rc, } niri_render_elements! { diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs index 179055ae..2b4133cd 100644 --- a/src/layout/workspace.rs +++ b/src/layout/workspace.rs @@ -37,7 +37,7 @@ pub struct Workspace { /// /// Most of the time this will be the workspace's current output, however, after an output /// disconnection, it may remain pointing to the disconnected output. - pub original_output: OutputId, + pub(super) original_output: OutputId, /// Current output of this workspace. output: Option, @@ -67,13 +67,13 @@ pub struct Workspace { working_area: Rectangle, /// Columns of windows on this workspace. - pub columns: Vec>, + pub(super) columns: Vec>, /// Extra per-column data. data: Vec, /// Index of the currently active column, if any. - pub active_column_idx: usize, + pub(super) active_column_idx: usize, /// Ongoing interactive resize. interactive_resize: Option>, @@ -107,13 +107,13 @@ pub struct Workspace { closing_windows: Vec, /// Configurable properties of the layout as received from the parent monitor. - pub base_options: Rc, + pub(super) base_options: Rc, /// Configurable properties of the layout with logical sizes adjusted for the current `scale`. - pub options: Rc, + pub(super) options: Rc, /// Optional name of this workspace. - pub name: Option, + pub(super) name: Option, /// Unique ID of this workspace. id: WorkspaceId, @@ -237,7 +237,7 @@ pub struct Column { /// Tiles in this column. /// /// Must be non-empty. - pub tiles: Vec>, + pub(super) tiles: Vec>, /// Extra per-tile data. /// @@ -245,19 +245,19 @@ pub struct Column { data: Vec, /// Index of the currently active tile. - pub active_tile_idx: usize, + pub(super) active_tile_idx: usize, /// Desired width of this column. /// /// If the column is full-width or full-screened, this is the width that should be restored /// upon unfullscreening and untoggling full-width. - pub width: ColumnWidth, + pub(super) width: ColumnWidth, /// Whether this column is full-width. - pub is_full_width: bool, + pub(super) is_full_width: bool, /// Whether this column contains a single full-screened window. - pub is_fullscreen: bool, + pub(super) is_fullscreen: bool, /// Animation of the render offset during window swapping. move_animation: Option, @@ -471,6 +471,10 @@ impl Workspace { self.id } + pub fn name(&self) -> Option<&String> { + self.name.as_ref() + } + pub fn unname(&mut self) { self.name = None; } -- cgit