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
- Window information (title, process name, PID)
- Icon extraction with configurable sizes
- Sync and async APIs
- Configurable polling intervals
- Graceful shutdown with stop signals
Installation
Add to your Cargo.toml:
[]
= "*"
For async support:
[]
= { = "*", = ["async"] }
= { = "1", = ["full"] }
Quick Start - Channel-Based
Subscribe to focus changes and receive them via a channel:
use subscribe_focus_changes;
Async Usage
For async/await workflows, use the async API with tokio:
use FocusTracker;
use Arc;
use ;
async
Configuration
Customize behavior with FocusTrackerConfig:
use ;
let config = new
.with_poll_interval_ms // Faster polling (default: 100ms)
.with_icon_config;
let tracker = with_config;
Examples
Run the included examples:
# Channel-based focus tracking
# Async focus tracking (requires async feature)
# 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.