Skip to content

Commit

Permalink
docs: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
roosta committed Dec 17, 2024
1 parent 299fc77 commit 9b8d18a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 117 deletions.
56 changes: 2 additions & 54 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,6 @@
//! - Internal organization
//!
//! While you could technically use this as a library, it's not designed or maintained for that purpose.
//!
//! ## Internal Architecture
//!
//! The crate is organized into several main components:
//!
//! - Event handling (`handle_window_event`, `handle_ws_event`)
//! - Workspace management (`update_tree`, `get_workspaces`)
//! - Window title processing (`get_title`, `collect_titles`)
//! - Configuration management (`Config` module)
//! - Regular expression handling (`regex` module)
//!
//! ## Configuration
//!
//! Configuration is handled through the `Config` type, which supports:
//! - Icon mappings for applications
//! - Display options
//! - Separator customization
//! - Regular expression patterns for window matching
//!
//! ## Error Handling
//!
//! Errors are managed through the `AppError` enum, which encompasses:
//! - Configuration errors
//! - IPC connection issues
//! - Regular expression errors
//! - Event handling problems
//! - I/O errors
use swayipc::{
Connection,
Node,
Expand Down Expand Up @@ -149,6 +122,7 @@ fn format_with_icon(icon: &char, title: &str, no_names: bool, no_icon_names: boo
}
}

/// Gets a window title by trying to find an alias for the window, eventually falling back on class
pub fn get_title(
props: &WindowProperties,
config: &Config,
Expand Down Expand Up @@ -302,23 +276,9 @@ fn format_workspace_name(
}

/// Internal function to update all workspace names based on their current content.
///
/// This function is public for testing purposes and binary use only.
///
/// # Implementation Note
///
/// Core functionality that:
/// 1. Retrieves current window manager tree
/// 2. Processes each workspace's contents
/// 3. Generates new names based on configuration
/// 4. Sends rename commands when necessary
///
/// # Error Handling
///
/// Returns errors for:
/// - Failed IPC communication
/// - Invalid workspace names
/// - Command execution failures
/// Update all workspace names in tree
pub fn update_tree(
conn: &mut Connection,
config: &Config,
Expand Down Expand Up @@ -379,13 +339,6 @@ pub fn update_tree(
///
/// Processes various window events (new, close, move, title changes) and updates
/// workspace names accordingly. This is a core part of the event loop in the main binary.
///
/// # Events Handled
///
/// - `WindowChange::New`: New window created
/// - `WindowChange::Close`: Window closed
/// - `WindowChange::Move`: Window moved between workspaces
/// - `WindowChange::Title`: Window title changed
pub fn handle_window_event(
e: &WindowEvent,
conn: &mut Connection,
Expand Down Expand Up @@ -413,11 +366,6 @@ pub fn handle_window_event(
///
/// Processes workspace events (empty, focus changes) and updates workspace names
/// as needed. This is a core part of the event loop in the main binary.
///
/// # Events Handled
///
/// - `WorkspaceChange::Empty`: Workspace becomes empty
/// - `WorkspaceChange::Focus`: Workspace focus changed
pub fn handle_ws_event(
e: &WorkspaceEvent,
conn: &mut Connection,
Expand Down
63 changes: 0 additions & 63 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,48 +191,6 @@ struct Args {
}

/// Loads configuration from a TOML file or creates default configuration
///
/// # Configuration File Search Order
///
/// 1. Path specified via command line argument
/// 2. $XDG_CONFIG_HOME/i3wsr/config.toml
/// 3. Default configuration if no file found
///
/// # Configuration File Format
///
/// The configuration file uses TOML format with these main sections:
///
/// ```toml
/// [icons]
/// # Map window classes to icons
/// Firefox = "🌍"
/// default_icon = "💻"
///
/// [aliases.class]
/// # Map window classes to friendly names
/// "Google-chrome" = "Chrome"
///
/// [aliases.instance]
/// # Map window instances to friendly names
/// "web.whatsapp.com" = "WhatsApp"
///
/// [aliases.name]
/// # Map window names using regex
/// ".*mutt$" = "Mail"
///
/// [general]
/// # General settings
/// separator = " | " # Separator between window names
/// split_at = ":" # Character to split workspace number
/// empty_label = "🌕" # Label for empty workspaces
/// display_property = "class" # Default property to display
///
/// [options]
/// # Boolean options
/// remove_duplicates = false
/// no_names = false
/// no_icon_names = false
/// ```
fn load_config(config_path: Option<&str>) -> Result<Config, ConfigError> {
let xdg_config = config_dir()
.ok_or_else(|| ConfigError::IoError(io::Error::new(
Expand Down Expand Up @@ -286,13 +244,6 @@ fn apply_args_to_config(config: &mut Config, args: &Args) {
}

/// Sets up the program by processing arguments and initializing configuration
///
/// This function:
/// 1. Parses command line arguments
/// 2. Sets up verbose logging if requested
/// 3. Loads configuration from file
/// 4. Applies command line overrides to configuration
///
/// Command line arguments take precedence over configuration file settings.
fn setup() -> Result<Config, AppError> {
let args = Args::parse();
Expand All @@ -307,13 +258,6 @@ fn setup() -> Result<Config, AppError> {
}

/// Processes window manager events and updates workspace names accordingly
///
/// Handles two types of events:
/// - Window events (new, close, move, title changes)
/// - Workspace events (focus changes, empty workspace events)
///
/// For each event, it updates the relevant workspace names based on
/// the current configuration and window properties.
fn handle_event(
event: Fallible<Event>,
conn: &mut Connection,
Expand All @@ -336,13 +280,6 @@ fn handle_event(
}

/// Main event loop that monitors window manager events
///
/// This function:
/// 1. Initializes configuration and connections
/// 2. Subscribes to window and workspace events
/// 3. Performs initial workspace name updates
/// 4. Continuously processes events and updates workspace names
///
/// The program will continue running and handling events until
/// interrupted or an unrecoverable error occurs.
fn run() -> Result<(), AppError> {
Expand Down

0 comments on commit 9b8d18a

Please sign in to comment.