API Documentation
Open Sesame provides a library crate (open_sesame) with reusable components for building Wayland window management applications.
Online API Reference
View the complete API documentation at:
https://scopecreep-zip.github.io/open-sesame/doc/open_sesame/
Building Documentation Locally
# Build API docs
cargo doc --no-deps --open
# Or via mise
mise run docs:api
This opens the documentation in your browser at target/doc/open_sesame/index.html.
Module Overview
The open_sesame crate is organized into several modules:
app
Application orchestration and event loop.
Key types:
App- Main application coordinatorAppState- UI state machine
Responsibilities:
- Wayland event loop integration
- State management (idle, showing overlay, window selected)
- Event dispatching to appropriate handlers
- Render coordination
Example:
#![allow(unused)]
fn main() {
use open_sesame::app::App;
use open_sesame::Config;
let config = Config::load()?;
let hints = vec![/* ... */];
let result = App::run(config, hints, None, true, None)?;
}
config
Configuration loading and validation.
Key types:
Config- Main configuration structSettings- Global settings (delays, colors, etc.)KeyBinding- Per-key app associationsLaunchConfig- Launch command configurationColor- RGBA color with hex serializationConfigValidator- Configuration validation
Responsibilities:
- TOML parsing and serialization
- XDG config file discovery
- Layered configuration merging
- Schema validation
Example:
#![allow(unused)]
fn main() {
use open_sesame::Config;
// Load from default paths
let config = Config::load()?;
// Get key for app
if let Some(key) = config.key_for_app("firefox") {
println!("Firefox is bound to '{}'", key);
}
// Generate default config
let default_toml = Config::default_toml();
}
core
Domain types and business logic.
Key types:
Window- Window information (ID, app ID, title, focused state)WindowId- Opaque window identifierAppId- Application identifierWindowHint- Assigned hint for a windowHintAssignment- Complete hint assignmentHintMatcher- Input matching logicLaunchCommand- Command execution abstraction
Responsibilities:
- Hint assignment algorithm (Vimium-style)
- Input matching and disambiguation
- Window filtering and sorting
- Launch command abstraction
Example:
#![allow(unused)]
fn main() {
use open_sesame::core::{HintAssignment, Window, AppId, WindowId};
let windows = vec![
Window {
id: WindowId::new("1"),
app_id: AppId::new("firefox"),
title: "Mozilla Firefox".to_string(),
is_focused: false,
},
];
let assignment = HintAssignment::assign(&windows, |app_id| {
if app_id == "firefox" { Some('f') } else { None }
});
assert_eq!(assignment.hints[0].hint, "f");
}
input
Keyboard input processing.
Key types:
InputBuffer- Typed character bufferInputHandler- Key event processorMatchResult- Result of hint matching
Responsibilities:
- Key event handling
- Multi-key hint matching (g, gg, ggg)
- Backspace handling
- Arrow key navigation
Example:
#![allow(unused)]
fn main() {
use open_sesame::input::{InputBuffer, HintMatcher, MatchResult};
let mut buffer = InputBuffer::new();
buffer.push('g');
let matcher = HintMatcher::new(hints);
match matcher.match_input(&buffer) {
MatchResult::Exact(idx) => println!("Matched window {}", idx),
MatchResult::Partial => println!("Partial match, continue typing"),
MatchResult::NoMatch => println!("No match"),
}
}
platform
Platform abstraction layer for Wayland and COSMIC.
Key functions:
enumerate_windows()- List all windows via Wayland protocolsactivate_window()- Activate and focus a windowsetup_keybinding()- Configure COSMIC keybindingremove_keybinding()- Remove COSMIC keybindingkeybinding_status()- Check keybinding configuration
Wayland protocols:
wlr-foreign-toplevel-management- Window enumerationcosmic-workspace- Workspace informationcosmic-window-management- Window activation
Example:
#![allow(unused)]
fn main() {
use open_sesame::platform;
use open_sesame::WindowId;
// Enumerate windows
let windows = platform::enumerate_windows()?;
// Activate a window
let window_id = WindowId::new("wayland-1");
platform::activate_window(&window_id)?;
}
render
Software rendering pipeline.
Key types:
Renderer- Main rendering coordinatorBuffer- Wayland shared memory bufferFontCache- Cached font glyphs
Rendering stack:
fontdue- Font rasterizationtiny-skia- 2D graphics primitiveswayland-client- Buffer management
Responsibilities:
- Overlay rendering
- Font rasterization and caching
- Primitive drawing (rectangles, text)
- Buffer management for Wayland
Note: Rendering is primarily internal and not exposed as public API.
ui
User interface components.
Key types:
Overlay- Main overlay componentTheme- Color scheme and stylingLayout- Window card positioning
Responsibilities:
- Overlay window creation
- Layout calculations
- Theme management
- Component coordination
Example:
#![allow(unused)]
fn main() {
use open_sesame::ui::{Overlay, Theme};
let theme = Theme::from_config(&config.settings);
let overlay = Overlay::new(theme);
}
util
Shared utilities and helpers.
Key types:
InstanceLock- Single-instance lockingIpcServer/IpcClient- Inter-process communicationMruState- Most Recently Used window trackingError/Result- Error types
Key functions:
load_mru_state()- Load MRU state from cachesave_activated_window()- Save MRU stateload_env_files()- Parse environment fileslog::init()- Initialize logging
Example:
#![allow(unused)]
fn main() {
use open_sesame::util::{InstanceLock, load_mru_state};
// Single-instance locking
let _lock = InstanceLock::acquire()?;
// MRU tracking
let mru = load_mru_state();
println!("Previous window: {:?}", mru.previous);
}
Error Handling
Open Sesame uses custom error types for clear error reporting:
#![allow(unused)]
fn main() {
use open_sesame::{Error, Result};
fn example() -> Result<()> {
let config = Config::load()
.map_err(|e| Error::Config(e.to_string()))?;
Ok(())
}
}
Error types:
Error::Config- Configuration errorsError::Platform- Wayland/platform errorsError::InvalidColor- Color parsing errorsError::Io- I/O errorsError::Other- Other errors
Re-exports
Commonly used types are re-exported at the crate root:
#![allow(unused)]
fn main() {
use open_sesame::{
Config, // Configuration
Window, // Window info
WindowId, // Window identifier
AppId, // App identifier
HintAssignment, // Hint assignment
HintMatcher, // Input matching
Error, // Error type
Result, // Result type
};
}
Feature Flags
Current features:
default- All default featuresdebug-logging- Always enable debug logging (off by default)
Example:
# In Cargo.toml
[dependencies]
open-sesame = { version = "*", features = ["debug-logging"] }
Examples
The repository includes example programs in the examples/ directory:
# List examples
ls examples/
# Run an example
cargo run --example window_enumeration
Available examples:
window_enumeration- Enumerate windows and print detailshint_assignment- Demonstrate hint assignment algorithmconfig_loading- Load and display configuration
Documentation Standards
All public APIs follow these documentation standards:
- Module docs (
//!) - Overview and examples - Type docs (
///) - Purpose and usage - Function docs (
///) - Parameters, returns, examples, errors - Examples - Working code examples in docs
- Links - Cross-references to related types
Example:
#![allow(unused)]
fn main() {
/// Parse a color from hex string.
///
/// Supports both RGB (`#RRGGBB`) and RGBA (`#RRGGBBAA`) formats.
///
/// # Arguments
///
/// * `s` - Hex string (with or without leading `#`)
///
/// # Examples
///
/// ```
/// use open_sesame::config::Color;
///
/// let red = Color::from_hex("#ff0000").unwrap();
/// assert_eq!(red.r, 255);
///
/// let transparent = Color::from_hex("#00000080").unwrap();
/// assert_eq!(transparent.a, 128);
/// ```
///
/// # Errors
///
/// Returns [`Error::InvalidColor`] if the string is not valid hex.
///
/// # See Also
///
/// * [`Color::to_hex`] - Convert color to hex string
pub fn from_hex(s: &str) -> Result<Color> {
// ...
}
}
Building Documentation
Standard Build
cargo doc --no-deps
With Private Items
cargo doc --no-deps --document-private-items
With All Features
cargo doc --no-deps --all-features
Check for Warnings
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps
Contributing to Documentation
See the Contributing Guide for documentation standards and guidelines.
Quick tips:
- Document all public items
- Include examples for complex functionality
- Use intra-doc links for cross-references
- Keep examples short and focused
- Test examples with
cargo test --doc
Next Steps
- Architecture Guide - Understand the design
- Building Guide - Build from source
- Testing Guide - Run tests
- Contributing Guide - Contribute code