### Create and Parse Hyprlang Config Programmatically (Rust) Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/examples/README.md Provides a template for creating your own Hyprlang examples. It shows how to initialize a `Config` object, parse a configuration file, and access values using typed getters like `get_int()`. This is the fundamental structure for building custom Hyprlang parsers. ```rust use hyprlang_rs::Config; use std::error::Error; fn main() -> Result<(), Box> { let mut config = Config::new(); config.parse_file("path/to/config.conf")?; // Replace with the actual path to your config file // Example of accessing a value: match config.get_int("some_key") { Ok(Some(value)) => { println!("Value for 'some_key': {}", value); } Ok(None) => { println!("'some_key' not found."); } Err(e) => { eprintln!("Error getting 'some_key': {}", e); } } Ok(()) } ``` -------------------------------- ### Complete Hyprland Configuration Example (Rust) Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md A comprehensive Rust example demonstrating how to use the `Hyprland` API to parse a Hyprland configuration file and access various settings, including general, decoration, animation, input, keybindings, window rules, variables, monitors, environment variables, and autostart commands. It shows typed access to configuration values and iteration over collections of settings. ```rust use hyprlang::Hyprland; use std::path::Path; fn main() -> Result<(), Box> { // Create Hyprland config (handlers auto-registered) let mut hypr = Hyprland::new(); // Parse your Hyprland config hypr.parse_file(Path::new("~/.config/hypr/hyprland.conf"))?; // === Access General Settings === println!("Border: {}", hypr.general_border_size()?); println!("Layout: {}", hypr.general_layout()?); println!("Gaps: {} / {}", hypr.general_gaps_in()?, hypr.general_gaps_out()?); let active = hypr.general_active_border_color()?; println!("Active border: rgba({}, {}, {}, {})", active.r, active.g, active.b, active.a); // === Access Decoration Settings === println!("\nRounding: {}", hypr.decoration_rounding()?); println!("Active opacity: {}", hypr.decoration_active_opacity()?); println!("Blur enabled: {}", hypr.decoration_blur_enabled()?); println!("Blur size: {}", hypr.decoration_blur_size()?); // === Access Animation Settings === if hypr.animations_enabled()? { println!("\nAnimations:"); for anim in hypr.all_animations() { println!(" - {}", anim); } println!("\nBezier curves:"); for bezier in hypr.all_beziers() { println!(" - {}", bezier); } } // === Access Input Settings === println!("\nKeyboard layout: {}", hypr.input_kb_layout()?); println!("Mouse sensitivity: {}", hypr.input_sensitivity()?); println!("Natural scroll: {}", hypr.input_touchpad_natural_scroll()?); // === Access Keybindings === println!("\nKeybindings ({}) :", hypr.all_binds().len()); for (i, bind) in hypr.all_binds().iter().enumerate() { println!(" [{}] {}", i + 1, bind); } // === Access Window Rules === println!("\nWindow rules ({}) :", hypr.all_windowrules().len()); for rule in hypr.all_windowrules() { println!(" - {}", rule); } // === Access Variables === println!("\nVariables:"); for (name, value) in hypr.variables() { println!(" ${} = {}", name, value); } // === Access Monitors === for monitor in hypr.all_monitors() { println!("Monitor: {}", monitor); } // === Access Environment Variables === for env in hypr.all_env() { println!("Env: {}", env); } // === Access Autostart === for exec in hypr.all_exec_once() { println!("Exec-once: {}", exec); } Ok(()) } ``` -------------------------------- ### Parse Real Hyprland Config File (Rust) Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/examples/README.md An example that parses a real Hyprland configuration file, demonstrating handler registration for Hyprland-specific keywords and graceful error handling. It's designed to work with complex, real-world configurations and pretty-prints the parsed results. Note that some advanced Hyprland syntax might not be fully supported. ```rust use hyprlang_rs::Config; use std::error::Error; fn main() -> Result<(), Box> { let mut config = Config::new(); // Register handlers for Hyprland-specific keywords if necessary. // For example: // config.register_handler_fn("bind", |key, value| { /* custom bind handling */ Ok(()) }); match config.parse_file("path/to/your/hyprland.conf") { // Replace with actual path Ok(_) => { println!("Successfully parsed Hyprland configuration."); // Pretty-printing logic would follow here. Ok(()) } Err(e) => { eprintln!("Error parsing Hyprland config: {}", e); // Provide more specific error handling or reporting if needed. Err(e.into()) } } } ``` -------------------------------- ### Get All Configuration Keys Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Returns a vector of all keys present in the configuration. This can be used to iterate over all available configuration parameters. ```rust // Querying config.keys() -> Vec<&str> ``` -------------------------------- ### Install hyprlang-rs with Hyprland Feature Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Enable the 'hyprland' feature to integrate with Hyprland configuration. This provides automatic handler registration and typed access to Hyprland-specific configuration options. ```toml [dependencies] hyprlang = { version = "0.4.0", features = ["hyprland"] } ``` -------------------------------- ### Install hyprlang-rs with Mutation Feature Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Enable the 'mutation' feature to gain the ability to modify configuration values, serialize them back to files, and track changes across multiple source files. ```toml [dependencies] hyprlang = { version = "0.4.0", features = ["mutation"] } ``` -------------------------------- ### Include Configuration Files with Source Directive Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Shows how to use the 'source' directive within Hyprlang to include the contents of other configuration files. This example demonstrates including a colors configuration file and using a variable defined within it. ```rust use hyprlang::{Config, ConfigOptions}; use std::path::PathBuf; let mut options = ConfigOptions::default(); options.base_dir = Some(PathBuf::from("/path/to/config")); let mut config = Config::with_options(options); // This will include another config file config.parse(r#"source = ./colors.conf general { border_size = $borderSize }"#)?; ``` -------------------------------- ### Pretty Print Hyprlang Config File (Rust) Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/examples/README.md Demonstrates parsing and pretty-printing a Hyprlang configuration file. It showcases features like variable definitions and expansion, nested categories, expression evaluation, color parsing, Vec2 values, type detection, and formatting. The output provides a structured view of variables, categorized values, and summary statistics. ```rust use hyprlang_rs::Config; use std::error::Error; fn main() -> Result<(), Box> { let mut config = Config::new(); config.parse_file("examples/pretty_print.rs")?; // Assuming pretty_print.rs is the file to parse for this example // The actual pretty-printing logic would be here, likely involving iterating through config.keys() and printing formatted values. // For demonstration, let's just print a confirmation and a few values. println!("Successfully parsed and will pretty-print the configuration."); if let Some(val) = config.get_string("monitor")? { println!("Monitor: {}", val); } if let Some(val) = config.get_int("refresh_rate")? { println!("Refresh Rate: {}", val); } // In a real scenario, you would implement detailed pretty-printing logic here. Ok(()) } ``` -------------------------------- ### Install hyprlang-rs Dependency Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Add the hyprlang crate to your project's Cargo.toml file to include the parser and configuration manager. Version 0.4.0 is recommended for Hyprland >= 0.53.0. ```toml [dependencies] hyprlang = "0.4.0" ``` -------------------------------- ### Get Configuration Value by Key Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Retrieves a configuration value associated with a specific key using the `get` method. This method returns a reference to a `ConfigValue` enum, wrapped in a `Result` to handle cases where the key might not exist or an error occurs. ```rust // Getting values config.get(key: &str) -> Result<&ConfigValue> ``` -------------------------------- ### Parse and Get Colors with Config API Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Shows how to parse color values in various formats (rgba, rgb, hex) and retrieve them as structured color objects using the `Config` API. ```rust use hyprlang::Config; let mut config = Config::new(); config.parse(r#" color1 = rgba(33ccffee) color2 = rgb(255, 128, 64) color3 = 0xff8040ff "#)?; let color = config.get_color("color1")?; println!("R: {}, G: {}, B: {}, A: {}", color.r, color.g, color.b, color.a); ``` -------------------------------- ### Get Source File for a Key (Mutation Feature) Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Requires the `mutation` feature to be enabled. Returns the path of the source file where a specific configuration key was defined. Returns `None` if the key is not found or was not loaded from a file. ```rust // Multi-file mutation (requires `mutation` feature) config.get_key_source_file(key: &str) -> Option<&Path> ``` -------------------------------- ### Rust: Get Hyprland Decoration Settings Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Retrieves various decoration-related settings from Hyprland. These functions return results, indicating potential errors during retrieval. Dependencies include the Hyprland environment. ```rust hypr.decoration_rounding() -> Result hypr.decoration_active_opacity() -> Result hypr.decoration_inactive_opacity() -> Result hypr.decoration_blur_enabled() -> Result hypr.decoration_blur_size() -> Result hypr.decoration_blur_passes() -> Result ``` -------------------------------- ### Get All Source Files (Mutation Feature) Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Requires the `mutation` feature to be enabled. Returns a vector of paths to all source files that have been loaded into the configuration. This provides an overview of the configuration's origin. ```rust // Multi-file mutation (requires `mutation` feature) config.get_source_files() -> Vec<&Path> ``` -------------------------------- ### Configure Hyprlang for Advanced Parsing with Rust Source: https://context7.com/spinualexandru/hyprlang-rs/llms.txt This Rust code snippet demonstrates how to configure `hyprlang` for advanced parsing behaviors. It shows setting options to collect all errors instead of stopping at the first one and to allow dynamic parsing for features like reloading configurations. The example also includes parsing initial and dynamic configurations, retrieving integer values, and setting values programmatically. ```rust use hyprlang::{Config, ConfigOptions}; use std::path::PathBuf; fn main() -> Result<(), Box> { // Create custom configuration options let mut options = ConfigOptions::default(); // Collect all errors instead of stopping at first error options.throw_all_errors = true; // Allow parsing after initial parse (for dynamic reloading) options.allow_dynamic_parsing = true; // Set base directory for source directives options.base_dir = Some(PathBuf::from("/home/user/.config")); let mut config = Config::with_options(options); // Parse initial configuration config.parse(r#" value1 = 100 value2 = 200 "#)?; // Parse additional configuration dynamically config.parse_dynamic("value3 = 300")?; // All values are available assert_eq!(config.get_int("value1")?, 100); assert_eq!(config.get_int("value2")?, 200); assert_eq!(config.get_int("value3")?, 300); // Set values programmatically config.set("value4".to_string(), hyprlang::ConfigValue::Int(400)); assert_eq!(config.get_int("value4")?, 400); Ok(()) } ``` -------------------------------- ### Rust: Get Hyprland Layout Settings Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Fetches specific layout management settings like dwindle pseudotile behavior and master new window status. These functions return results indicating success or failure. The Hyprland layout manager context is required. ```rust hypr.dwindle_pseudotile() -> Result hypr.dwindle_preserve_split() -> Result hypr.master_new_status() -> Result<&str> ``` -------------------------------- ### Rust: Get Hyprland Input Settings Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Retrieves various input device settings, such as keyboard layout, mouse following behavior, sensitivity, and touchpad natural scrolling. Functions return results for single values and booleans for toggles. Requires access to the Hyprland input configuration. ```rust hypr.input_kb_layout() -> Result<&str> hypr.input_follow_mouse() -> Result hypr.input_sensitivity() -> Result hypr.input_touchpad_natural_scroll() -> Result ``` -------------------------------- ### Get All User-Defined Variables Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Returns a reference to a hash map containing all user-defined variables. This allows inspection of custom variables set within the configuration. ```rust // Querying config.variables() -> &HashMap ``` -------------------------------- ### Rust: Get Hyprland Animation Settings Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Fetches animation-related configurations, including whether animations are enabled and lists of all defined animations and bezier curves. Returns boolean for enabled status and vectors of strings for definitions. Depends on the Hyprland context. ```rust hypr.animations_enabled() -> Result hypr.all_animations() -> Vec<&String> hypr.all_beziers() -> Vec<&String> ``` -------------------------------- ### Parse and Get Vec2 Coordinates with Config API Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Demonstrates parsing 2D coordinate values, which can be defined with or without parentheses, and retrieving them as `Vec2` objects using the `Config` API. ```rust use hyprlang::Config; let mut config = Config::new(); config.parse(r#" position1 = 100, 200 position2 = (50, 75) "#)?; let pos = config.get_vec2("position1")?; assert_eq!(pos.x, 100.0); assert_eq!(pos.y, 200.0); ``` -------------------------------- ### Get String Configuration Value Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Retrieves a configuration value as a string slice (`&str`) using the `get_string` method. This provides direct access to string-valued configuration parameters. It returns a `Result` to manage potential errors. ```rust // Getting values config.get_string(key: &str) -> Result<&str> ``` -------------------------------- ### Rust: Get Hyprland Miscellaneous Settings Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Retrieves miscellaneous Hyprland settings, such as disabling the Hyprland logo and forcing a default wallpaper. These functions return results with boolean or integer values. Access to Hyprland's misc configuration is needed. ```rust hypr.misc_disable_hyprland_logo() -> Result hypr.misc_force_default_wallpaper() -> Result ``` -------------------------------- ### Get Integer Configuration Value Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Retrieves a configuration value as an `i64` integer using the `get_int` method. This is a convenient way to access typed integer values from the configuration. It returns a `Result` to indicate success or failure. ```rust // Getting values config.get_int(key: &str) -> Result ``` -------------------------------- ### Rust: Get Hyprland Cursor Settings (0.53.0+) Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Retrieves cursor-related settings, such as hiding the cursor on tablet input, available from version 0.53.0. This function returns a boolean value. Requires Hyprland version 0.53.0 or later. ```rust hypr.cursor_hide_on_tablet() -> Result ``` -------------------------------- ### Rust: Direct Access to Hyprland Config Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Enables direct interaction with the underlying low-level Hyprland `Config` API. Provides immutable and mutable access to the configuration object, allowing methods like `get` and `register_handler_fn`. Requires careful handling to avoid unintended side effects. ```rust let config: &Config = hypr.config(); // Immutable access let config: &mut Config = hypr.config_mut(); // Mutable access // Use all Config methods let custom_value = config.get("custom:key")?; config.register_handler_fn("custom", |ctx| { /* ... */ Ok(()) }); ``` -------------------------------- ### Parse Configuration String in Rust Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Demonstrates how to initialize a `Config` object and parse a Hyprlang configuration string. It then shows how to retrieve integer values from the parsed configuration. ```rust use hyprlang::Config; fn main() -> Result<(), Box> { let mut config = Config::new(); // Parse a configuration string config.parse(r#" general { gaps_in = 5 gaps_out = 20 border_size = 2 } "#)?; // Access values let gaps_in = config.get_int("general:gaps_in")?; let gaps_out = config.get_int("general:gaps_out")?; println!("gaps_in: {}, gaps_out: {}", gaps_in, gaps_out); Ok(()) } ``` -------------------------------- ### Parse Configuration File in Rust Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md This Rust code snippet demonstrates the basic usage of parsing a configuration file using hyprlang. It initializes a `Config` object, parses a specified file (e.g., `config.conf`), and then iterates through all the keys present in the parsed configuration, printing each key to the console. This is a fundamental step for interacting with configuration files. ```rust use hyprlang::Config; use std::path::Path; let mut config = Config::new(); config.parse_file(Path::new("config.conf"))?; // Access all keys for key in config.keys() { println!("Key: {}", key); } ``` -------------------------------- ### Parse Configuration Files with Source Directives in Rust Source: https://context7.com/spinualexandru/hyprlang-rs/llms.txt Shows how to parse configuration files, including external ones using `source` directives, and how to set a base directory for resolving these relative paths. This is useful for managing complex configurations. It uses the `hyprlang` crate. ```rust use hyprlang::{Config, ConfigOptions}; use std::path::{Path, PathBuf}; fn main() -> Result<(), Box> { // Set base directory for resolving source directives let mut options = ConfigOptions::default(); options.base_dir = Some(PathBuf::from("/home/user/.config/hypr")); let mut config = Config::with_options(options); // Parse main config file config.parse_file(Path::new("/home/user/.config/hypr/hyprland.conf"))?; // Or parse with source directives config.parse(r#"#, // Include external files source = ~/.config/hypr/colors.conf source = ./keybindings.conf general { border_size = 2 gaps_in = 5 } "#)?; // Access values from all files let border = config.get_int("general:border_size")?; println!("Border size: {}", border); // List all configuration keys println!("\nAll configuration keys:"); for key in config.keys() { if let Ok(value) = config.get(key) { println!(" {}: {:?}", key, value); } } Ok(()) } ``` -------------------------------- ### Running Hyprlang-RS Benchmarks with Cargo Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/BENCHMARKS.md This snippet shows how to execute the benchmarks for Hyprlang-RS using Cargo. It includes commands for running all benchmarks, enabling specific features like 'mutation', filtering by benchmark group, and comparing results against a baseline. ```bash # Run all benchmarks cargo bench # Run with mutation feature cargo bench --features mutation # Run specific benchmark group cargo bench --bench parsing cargo bench --bench retrieval cargo bench --bench mutation --features mutation # Save baseline for comparison cargo bench -- --save-baseline v0.3.0 # Compare against baseline cargo bench -- --baseline v0.3.0 ``` -------------------------------- ### Get All Handler Calls Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Returns a reference to a hash map containing all handler calls registered in the configuration. This provides a comprehensive view of all active handlers and their associated values. ```rust // Handlers config.all_handler_calls() -> &HashMap> ``` -------------------------------- ### Get Modified Files (Mutation Feature) Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Requires the `mutation` feature to be enabled. Returns a vector of paths to files that have been modified since they were loaded. This is useful for tracking changes before saving. ```rust // Multi-file mutation (requires `mutation` feature) config.get_modified_files() -> Vec<&Path> ``` -------------------------------- ### Define and Access Special Categories in Rust Source: https://context7.com/spinualexandru/hyprlang-rs/llms.txt Illustrates how to define and utilize special category types (keyed, static) for organizing configurations, such as per-device or per-monitor settings. This functionality is provided by the `hyprlang` crate. ```rust use hyprlang::{Config, SpecialCategoryDescriptor, SpecialCategoryType}; fn main() -> Result<(), Box> { let mut config = Config::new(); // Register keyed special category for device-specific settings config.register_special_category( SpecialCategoryDescriptor::keyed("device", "name") ); // Register static special category config.register_special_category( SpecialCategoryDescriptor::static_category("plugin") ); config.parse(r#"#, # Keyed categories: device[key] device[mouse] { sensitivity = 0.5 accel_profile = flat natural_scroll = false } device[keyboard] { repeat_rate = 50 repeat_delay = 300 kb_layout = us } device[touchpad] { sensitivity = 0.3 natural_scroll = true tap_to_click = true } # Static category plugin { path = /usr/lib/hyprland-plugin.so enabled = true } "#)?; // Access keyed category instances let mouse = config.get_special_category("device", "mouse")?; if let Some(sensitivity) = mouse.get("sensitivity") { println!("Mouse sensitivity: {:?}", sensitivity.value); } let keyboard = config.get_special_category("device", "keyboard")?; if let Some(layout) = keyboard.get("kb_layout") { println!("Keyboard layout: {:?}", layout.value); } // List all keys in a special category let device_keys = config.list_special_category_keys("device"); println!("\nAll devices configured:"); for key in device_keys { println!(" - {}", key); let instance = config.get_special_category("device", &key)?; for (field, entry) in instance.iter() { println!(" {}: {:?}", field, entry.value); } } Ok(()) } ``` -------------------------------- ### Basic Configuration Parsing in Rust Source: https://context7.com/spinualexandru/hyprlang-rs/llms.txt Parses configuration strings or files into a structured format. Allows access to typed values (integers, floats, strings) and nested categories using colon-separated paths. Checks for key existence and retrieves all keys. ```rust use hyprlang::Config; fn main() -> Result<(), Box> { let mut config = Config::new(); config.parse(r#"# # Basic values count = 42 opacity = 0.95 terminal = kitty enabled = true # Nested categories with colon-separated access general { border_size = 2 gaps_in = 5 gaps_out = 20 gaps { inner = 5 outer = 10 } } "#)?; // Type-safe value access let count = config.get_int("count")?; assert_eq!(count, 42); let opacity = config.get_float("opacity")?; assert_eq!(opacity, 0.95); let terminal = config.get_string("terminal")?; assert_eq!(terminal, "kitty"); // Access nested values with colon-separated paths let border = config.get_int("general:border_size")?; assert_eq!(border, 2); let inner_gap = config.get_int("general:gaps:inner")?; assert_eq!(inner_gap, 5); // Check if key exists if config.contains("enabled") { println!("Config has 'enabled' key"); } // Get all keys let all_keys = config.keys(); println!("All keys: {:?}", all_keys); Ok(()) } ``` -------------------------------- ### Parse Basic Values with Config API Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Demonstrates how to use the low-level `Config` API to parse and retrieve basic data types such as integers, floats, strings, and booleans from a configuration string. ```rust use hyprlang::Config; let mut config = Config::new(); config.parse(r#" # Integers and floats count = 42 opacity = 0.95 # Strings terminal = kitty shell = "zsh" # Booleans enabled = true disabled = false "#)?; assert_eq!(config.get_int("count")?, 42); assert_eq!(config.get_float("opacity")?, 0.95); assert_eq!(config.get_string("terminal")?, "kitty"); ``` -------------------------------- ### Register Category-Specific Handlers in Rust Source: https://context7.com/spinualexandru/hyprlang-rs/llms.txt Demonstrates how to register and use custom handler functions that are executed only within specific categories. This allows for context-aware parsing and execution of configuration values. It requires the `hyprlang` crate. ```rust use hyprlang::Config; fn main() -> Result<(), Box> { let mut config = Config::new(); // Register handler that only works in 'animations' category config.register_category_handler_fn("animations", "animation", |ctx| { println!("Animation: {}", ctx.value); Ok(()) }); // Register handler for bezier curves in animations category config.register_category_handler_fn("animations", "bezier", |ctx| { println!("Bezier curve: {}", ctx.value); Ok(()) }); config.parse(r#"#, animations { enabled = true # These handlers only work within animations category bezier = easeOutQuint, 0.23, 1, 0.32, 1 bezier = easeInOut, 0.65, 0, 0.35, 1 animation = windows, 1, 4.79, easeOutQuint animation = fade, 1, 3.03, easeInOut animation = border, 1, 5.39, easeOutQuint } "#)?; // Access with category-prefixed names let anims = config.get_handler_calls("animations:animation").unwrap(); assert_eq!(anims.len(), 3); let beziers = config.get_handler_calls("animations:bezier").unwrap(); assert_eq!(beziers.len(), 2); println!("\nAnimations defined:"); for anim in anims { println!(" - {}", anim); } println!("\nBezier curves defined:"); for bezier in beziers { println!(" - {}", bezier); } Ok(()) } ``` -------------------------------- ### Get Handler Calls for a Handler Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Retrieves all registered calls for a specific handler keyword. Returns an `Option` containing a vector of strings representing the calls, or `None` if the handler has no registered calls. ```rust // Handlers config.get_handler_calls(handler: &str) -> Option<&Vec> ``` -------------------------------- ### Get Special Category Instance Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Retrieves a hash map of key-value pairs for a specific special category instance. This method is used to access structured data within custom categories. ```rust // Special categories config.get_special_category(category: &str, key: &str) -> Result> ``` -------------------------------- ### Get Mutable Variable Reference (Mutation Feature) Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Requires the `mutation` feature to be enabled. Returns a mutable reference to a user-defined variable if it exists. This allows direct modification of the variable's value. ```rust // Mutation (requires `mutation` feature) config.get_variable_mut(name: &str) -> Option ``` -------------------------------- ### Get Vec2 Configuration Value Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Retrieves a configuration value as a `Vec2` (2D coordinate) using the `get_vec2` method. This is specialized for accessing coordinates or dimensions stored in the configuration. It returns a `Result` to indicate success or failure. ```rust // Getting values config.get_vec2(key: &str) -> Result ``` -------------------------------- ### Configure Hyprlang Parsing Options Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Demonstrates how to customize parsing behavior using `ConfigOptions`. Options include collecting all errors instead of stopping at the first one (`throw_all_errors`), allowing dynamic parsing after initial load (`allow_dynamic_parsing`), and specifying a base directory for resolving source directives. ```rust use hyprlang::{Config, ConfigOptions}; use std::path::PathBuf; let mut options = ConfigOptions::default(); // Collect all errors instead of stopping at the first one options.throw_all_errors = false; // Allow parsing after initial parse options.allow_dynamic_parsing = true; // Base directory for resolving source directives options.base_dir = Some(PathBuf::from("/path/to/config")); let config = Config::with_options(options); ``` -------------------------------- ### Rust: Get Hyprland Group Settings (0.53.0+) Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Fetches group-related settings like groupbar blur effect, available from version 0.53.0. This function returns a boolean. Requires Hyprland version 0.53.0 or later. ```rust hypr.group_groupbar_blur() -> Result ``` -------------------------------- ### Low-level Config API Usage (Rust) Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Demonstrates the manual registration of handlers and string-based access to configuration values using the low-level `Config` API in Rust. This method requires explicit registration for each handler and type conversion for retrieved values. ```rust use hyprlang::Config; let mut config = Config::new(); // Manually register all handlers config.register_handler_fn("bind", |_| Ok(())); config.register_handler_fn("monitor", |_| Ok(())); config.register_handler_fn("windowrule", |_| Ok(())); // ... register 20+ more handlers config.register_category_handler_fn("animations", "animation", |_| Ok(())); config.register_category_handler_fn("animations", "bezier", |_| Ok(())); // Access values with string keys and manual type conversion let border_size = config.get_int("general:border_size")?; let gaps_in = config.get_string("general:gaps_in")?; // Could be int or string let binds = config.get_handler_calls("bind").unwrap_or(&vec![]); ``` -------------------------------- ### Get Color Configuration Value Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Retrieves a configuration value as a `Color` (RGBA) using the `get_color` method. This method is designed for accessing color values defined in the configuration. It returns a `Result` to handle potential errors. ```rust // Getting values config.get_color(key: &str) -> Result ``` -------------------------------- ### Parse and Access Windowrule v3 and Layerrule v2 Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Demonstrates how to parse new v3 windowrule and v2 layerrule syntax using Hyprland. This includes matching properties, applying effect properties, and accessing parsed rules with type-safe getters. It also shows compatibility with old v2 handler syntax. ```rust use hyprlang::Hyprland; let mut hypr = Hyprland::new(); hypr.parse(r#" # New v3 syntax - windowrule as special category windowrule[float-terminals] { # Match properties match:class = ^(kitty|alacritty)$ match:floating = false # Effect properties float = true size = 800 600 center = true opacity = 0.95 rounding = 10 border_color = rgba(33ccffee) } # Layerrule v2 syntax layerrule[blur-waybar] { match:namespace = waybar blur = true ignorealpha = 0.5 } "#)?; // Access windowrules let names = hypr.windowrule_names(); // vec!["float-terminals"] let rule = hypr.get_windowrule("float-terminals")?; // Get properties with type safety let class_match = rule.get_string("match:class")?; let is_float = rule.get_int("float")?; let opacity = rule.get_float("opacity")?; let color = rule.get_color("border_color")?; // Old v2 handler syntax still works for backward compatibility hypr.parse(r#"windowrulev2 = float, class:^(kitty)$"#)?; let v2_rules = hypr.all_windowrulesv2(); ``` -------------------------------- ### Migrate from Deprecated Windowrule v1/v2 Methods Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Illustrates the migration path from deprecated handler-based methods for accessing windowrules and layerrules to the new v3 special category syntax. The new approach offers named rules, structured properties, and type safety. ```rust // Old approach (deprecated): // Returns raw handler strings like "float, class:^(kitty)$" let rules = hypr.all_windowrulesv2(); for rule_str in rules { // Manual parsing required println!("{}", rule_str); } // New approach (v3 special categories): // Iterate all windowrules with structured access for name in hypr.windowrule_names() { let rule = hypr.get_windowrule(&name)?; // Type-safe property access if let Ok(class) = rule.get_string("match:class") { println!("Rule '{}' matches class: {}", name, class); } if let Ok(is_float) = rule.get_int("float") { println!(" float = {}", is_float == 1); } } // Same for layerrules for name in hypr.layerrule_names() { let rule = hypr.get_layerrule(&name)?; if let Ok(ns) = rule.get_string("match:namespace") { println!("Layerrule '{}' matches: {}", name, ns); } } ``` -------------------------------- ### Multi-File Configuration Mutation in Rust Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md This Rust snippet illustrates how the `mutation` feature in hyprlang-rs handles configurations that include other files via `source` directives. It shows how to parse a main configuration file, identify which file defines a specific key, mutate a value in an included file, check which files have been modified, and selectively save only those modified files. It also covers listing all source files and serializing the content of a specific file. ```rust use hyprlang::Config; use std::path::Path; // Assume config files exist as described in comments let mut config = Config::new(); config.parse_file(Path::new("main.conf"))?; // ===== Check which file defines a key ===== let source = config.get_key_source_file("decoration:rounding"); println!("rounding is defined in: {:?}", source); // ===== Mutate a value from appearance.conf ===== config.set_int("decoration:rounding", 15); // ===== Check which files were modified ===== let modified = config.get_modified_files(); println!("Modified files: {:?}", modified); // ===== Save only the modified files ===== let saved = config.save_all()?; println!("Saved files: {:?}", saved); // ===== List all source files ===== let all_files = config.get_source_files(); println!("All source files: {:?}", all_files); // ===== Serialize a specific file ===== let appearance_content = config.serialize_file(Path::new("./appearance.conf"))?; println!("appearance.conf:\n{}", appearance_content); ``` -------------------------------- ### Get Mutable Category Instance (Mutation Feature) Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Requires the `mutation` feature to be enabled. Retrieves a mutable reference to a specific category instance, allowing its properties to be modified. This is useful for dynamic updates of complex configuration sections. ```rust // Mutation (requires `mutation` feature) config.get_special_category_mut(category, key) -> Result ``` -------------------------------- ### Parse and Access Variables with Config API Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Illustrates parsing configuration strings that define variables and accessing both the raw variables and their expanded values using the `Config` API. ```rust use hyprlang::Config; let mut config = Config::new(); config.parse(r#" $terminal = kitty $mod = SUPER # Variables are expanded when used my_term = $terminal modifier = $mod "#)?; // Access variables directly let vars = config.variables(); assert_eq!(vars.get("terminal"), Some(&"kitty".to_string())); // Or access expanded values assert_eq!(config.get_string("my_term")?, "kitty"); ``` -------------------------------- ### Get Float Configuration Value Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Retrieves a configuration value as an `f64` floating-point number using the `get_float` method. This method is useful for accessing numerical values that are represented as floats. It returns a `Result` to handle potential errors. ```rust // Getting values config.get_float(key: &str) -> Result ``` -------------------------------- ### Parse Colors in Rust Source: https://context7.com/spinualexandru/hyprlang-rs/llms.txt Parses colors in various formats including rgba(), rgb(), and hex notation using the hyprlang::Config. It demonstrates accessing color components (r, g, b, a) and converting to ARGB and RGBA u32 formats. Dependencies include the 'hyprlang' crate. ```rust use hyprlang::Config; fn main() -> Result<(), Box> { let mut config = Config::new(); config.parse(r#"\ # RGBA with hex color1 = rgba(33ccffee) # RGB function notation color2 = rgb(255, 128, 64) # Hex with 0x prefix color3 = 0xff8040ff # RGBA function notation color4 = rgba(100, 150, 200, 255) "#)?; // Access as Color type let color1 = config.get_color("color1")?; println!("Color 1: R={}, G={}, B={}, A={}", color1.r, color1.g, color1.b, color1.a); let color2 = config.get_color("color2")?; assert_eq!(color2.r, 255); assert_eq!(color2.g, 128); assert_eq!(color2.b, 64); assert_eq!(color2.a, 255); // Default alpha // Convert to different formats let argb = color1.to_argb(); // ARGB as u32 let rgba = color1.to_rgba(); // RGBA as u32 println!("ARGB: 0x{:08x}", argb); println!("RGBA: 0x{:08x}", rgba); Ok(()) } ``` -------------------------------- ### Parse and Evaluate Expressions with Config API Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Explains how to parse and evaluate arithmetic expressions enclosed in double curly braces `{{}}` within configuration strings using the `Config` API. ```rust use hyprlang::Config; let mut config = Config::new(); config.parse(r#" $base = 10 # Arithmetic expressions with {{}} double = {{$base * 2}} sum = {{5 + 3}} complex = {{($base + 5) * 2}} "#)?; assert_eq!(config.get_int("double")?, 20); assert_eq!(config.get_int("sum")?, 8); assert_eq!(config.get_int("complex")?, 30); ``` -------------------------------- ### Rust: Get Hyprland Quirks Settings (0.53.0+) Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Fetches quirk settings introduced in version 0.53.0, specifically 'prefer HDR'. This function returns an integer representing the HDR mode. Requires Hyprland version 0.53.0 or later. ```rust hypr.quirks_prefer_hdr() -> Result ``` -------------------------------- ### Register Custom Handlers in Rust Source: https://context7.com/spinualexandru/hyprlang-rs/llms.txt Shows how to register custom handler functions for specific keywords in hyprlang. These handlers process the values associated with keywords as arrays of strings, enabling custom logic for directives like 'bind', 'windowrule', and 'exec-once'. Depends on the 'hyprlang' crate. ```rust use hyprlang::Config; fn main() -> Result<(), Box> { let mut config = Config::new(); // Register handler for 'bind' keyword config.register_handler_fn("bind", |ctx| { println!("Keybinding: {}", ctx.value); Ok(()) }); // Register handler for 'windowrule' keyword config.register_handler_fn("windowrule", |ctx| { println!("Window rule: {}", ctx.value); Ok(()) }); // Register handler for 'exec-once' keyword config.register_handler_fn("exec-once", |ctx| { println!("Autostart: {}", ctx.value); Ok(()) }); config.parse(r#"\ $mod = SUPER $terminal = kitty # Handlers are called when parsed bind = $mod, Q, exec, $terminal bind = $mod, C, killactive bind = $mod, M, exit bind = $mod, F, togglefloating windowrule = float, ^(kitty)$ windowrule = opacity 0.8, ^(kitty)$ exec-once = waybar exec-once = hyprpaper "#)?; // Access handler calls as arrays let binds = config.get_handler_calls("bind").unwrap(); assert_eq!(binds.len(), 4); println!("\nAll keybindings:"); for (i, bind) in binds.iter().enumerate() { println!(" [{}] {}", i + 1, bind); } let rules = config.get_handler_calls("windowrule").unwrap(); assert_eq!(rules.len(), 2); println!("\nAll window rules:"); for rule in rules { println!(" - {}", rule); } // Get all handler names let handler_names = config.handler_names(); println!("\nRegistered handlers: {:?}", handler_names); // Get all handler calls at once let all_calls = config.all_handler_calls(); println!("\nTotal handlers with calls: {}", all_calls.len()); Ok(()) } ``` -------------------------------- ### Rust: Get All Hyprland Handler Calls (Arrays) Source: https://github.com/spinualexandru/hyprlang-rs/blob/main/README.md Retrieves lists of all definitions for various Hyprland handlers, including binds, window rules, workspaces, monitors, and environment variables. These functions return vectors of strings. Deprecated v1 definitions are also listed. ```rust hypr.all_binds() -> Vec<&String> hypr.all_bindu() -> Vec<&String> hypr.all_bindm() -> Vec<&String> hypr.all_bindel() -> Vec<&String> hypr.all_bindl() -> Vec<&String> hypr.all_windowrules() -> Vec<&String> hypr.all_windowrulesv2() -> Vec<&String> hypr.all_layerrules() -> Vec<&String> hypr.all_workspaces() -> Vec<&String> hypr.all_monitors() -> Vec<&String> hypr.all_env() -> Vec<&String> hypr.all_exec() -> Vec<&String> hypr.all_exec_once() -> Vec<&String> ```