This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
wrtype is a Rust implementation of wtype - a Wayland virtual keyboard tool that types text and sends key events to applications. It's designed as a cross-platform replacement for xdotool on Wayland compositors.
# Using Nix (Recommended)
nix develop # Enter development environment
nix develop -c cargo build --release # Build optimized release version
nix develop -c cargo run -- "Hello World" # Run with text input
# Using Cargo directly (requires system dependencies)
nix develop -c cargo build # Build debug version
nix develop -c cargo build --release # Build release version
nix develop -c cargo test # Run all tests
nix develop -c cargo check # Check code without building
nix develop -c cargo clippy # Run linter
nix develop -c cargo fmt # Format code# Run tests
nix develop -c cargo test # All tests
nix develop -c cargo test -- --nocapture # Tests with output
nix develop -c cargo test test_name # Specific test
# Code quality
nix develop -c cargo fmt --check # Check formatting
nix develop -c cargo clippy -- -D warnings # Linting with warnings as errors
nix develop -c env RUST_BACKTRACE=1 cargo run # Run with stack traces# Format all code using treefmt
nix fmt # Format Nix and Rust files
nix develop -c cargo fmt # Format Rust code only
nix develop -c alejandra . # Format Nix files only# Build the package using Nix
nix build # Build wrtype package
nix build .#wrtype # Build specific package
nix run # Build and run wrtype
nix run . -- "Hello World" # Run with arguments# Type text
nix develop -c cargo run -- "Hello World"
# Press Ctrl+C
nix develop -c cargo run -- -M ctrl c -m ctrl
# Type with delays
nix develop -c cargo run -- foo -d 120 bar
# Read from stdin
echo "text" | nix develop -c cargo run -- --stdin -d 12The application follows a modular pipeline architecture:
main.rs- CLI parsing, command sequencing, and application lifecyclewayland.rs- Wayland protocol implementation and connection managementkeymap.rs- Dynamic XKB keymap generation for Unicode supportexecutor.rs- Sequential command execution with timing control
CLI Input → Command Parser → Command Executor → Keymap Builder → Wayland Protocol → Compositor
- Dynamic Keymap Generation: On-demand XKB keymaps support arbitrary Unicode characters
- Protocol-First Design: Direct Wayland virtual keyboard protocol implementation
- Synchronous Execution: Predictable command ordering with explicit timing control
- UTF-8 First: Full Unicode support throughout the pipeline
The Command enum represents all possible actions:
Text- Type strings with configurable delaysModPress/ModRelease- Modifier key controlKeyPress/KeyRelease- Named key controlSleep- Timing controlStdinText- Read from stdin
The WaylandState manages:
- Virtual keyboard protocol binding
- Seat discovery and management
- Modifier state tracking
- Protocol object lifecycle
The KeymapBuilder provides:
- Dynamic character-to-keysym mapping
- Efficient keycode allocation and caching
- XKB-compliant keymap generation
- Unicode character support
- Protocol Generation:
build.rshandles Wayland protocol code generation - Nix Integration:
flake.nixprovides reproducible development environment - Cross-Platform: Supports Linux distributions with different package managers
The flake provides a comprehensive development environment with:
Core Tools:
- Rust stable toolchain via rust-overlay
- Cargo and standard Rust development tools
Wayland Dependencies:
wayland- Core Wayland librarieswayland-protocols- Protocol definitionslibxkbcommon- XKB keymap supportpkg-config- Build configuration
Development Tools:
alejandra- Nix code formatternixd- Nix language serverstatix- Nix linterdeadnix- Dead code detector for Nixjust- Command runner
Code Quality:
rustfmt- Rust code formatter (via treefmt)cargo clippy- Rust linter- Integrated formatting pipeline
- Unit tests for individual components
- Integration tests for protocol interaction
- Manual testing with different Wayland compositors
- Unicode and timing edge case validation
- Requires Wayland compositor with
zwp_virtual_keyboard_manager_v1support - Uses standard XKB keymap format for character mapping
- Implements proper modifier state management
- Adding new commands: Extend the
Commandenum and update parser/executor - Protocol debugging: Use
WAYLAND_DEBUG=1environment variable - Keymap issues: Check XKB keysym mappings in
keymap.rs - Timing problems: Adjust delays in command execution logic
- Keymap lookup is O(1) for cached characters
- Memory usage grows linearly with unique characters used
- Protocol overhead is minimal per-event
- Large stdin inputs could benefit from streaming optimizations
If you need to develop outside the Nix environment:
Ubuntu/Debian:
sudo apt install libwayland-dev wayland-protocols libxkbcommon-dev pkg-config build-essentialFedora:
sudo dnf install wayland-devel wayland-protocols-devel libxkbcommon-devel pkgconf-pkg-config gcc