focus-tracker
A cross-platform focus tracker for Linux (X11), macOS, and Windows that monitors window focus changes and provides detailed information about the currently focused window.
Features
- Cross-platform support (Linux X11, macOS, Windows)
- Real-time focus tracking with automatic deduplication
- Window information (title, process name, PID)
- Icon extraction with configurable sizes and bounded cache
- Async API with tokio
- Configurable polling intervals
- Graceful shutdown with stop signals
Installation
Add to your Cargo.toml:
[]
= "1.0.0"
= { = "1", = ["full"] }
Quick Start
Track focus changes using the async API with tokio:
use FocusTracker;
use Arc;
use ;
async
Configuration
Customize behavior with FocusTrackerConfig:
use ;
let config = builder
.poll_interval.unwrap // Faster polling (default: 100ms)
.icon // Custom icon size (default: 128)
.icon_cache_capacity.unwrap // Bounded icon cache (default: 64)
.build;
let tracker = builder.config.build;
Examples
Run the included examples:
# Basic focus tracking
# Advanced example with icon saving and statistics
Platform Support
| Platform | Window System | Status |
|---|---|---|
| Linux | X11 | ✅ Full support |
| Linux | Wayland | ❌ Not supported |
| macOS | Cocoa | ✅ Full support |
| Windows | Win32 API | ✅ Full support |
Platform Notes
- Linux X11: Full support
- Linux Wayland: Not supported (technical limitations)
- macOS: Requires accessibility permissions
- Windows: Full support on Windows 7+
System Requirements
macOS
Accessibility permissions required. Grant in: System Preferences > Security & Privacy > Accessibility
Linux
X11 development libraries required (pre-installed on most distributions)
Windows
No additional requirements
API Documentation
For detailed API documentation, visit docs.rs/focus-tracker.
License
Licensed under the Apache License, Version 2.0. See LICENSE for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.