winshift
A cross-platform library for monitoring window focus changes.
Features
- Native window focus tracking on Linux via X11 (reference implementation)
- macOS support via Accessibility API (requires app tracking workaround)
- Event-driven callback system
- Minimal overhead window monitoring
- Optional embedded active window info in callbacks (macOS)
Note: The app tracking functionality on macOS exists solely to work around platform limitations for reliable window focus detection.
Supported Platforms
- Linux: Native window focus tracking via X11 (reference implementation)
- macOS: Window tracking via Accessibility API workaround (requires app tracking)
- Windows: Planned (not yet implemented)
Quick Start
See the Examples section for usage patterns.
Examples
Illustrative Usage Pattern
This simplified example shows the basic structure. For complete, working examples see the examples/ directory.
use ;
use Arc;
;
macOS: Embedded ActiveWindowInfo (no extra queries)
When enabled, macOS event callbacks also include the full ActiveWindowInfo so apps don’t need to call get_active_window_info() after each event. This reduces overhead and simplifies consumers like chronicle.
How to enable:
use ;
;
See examples/embed_info_monitor.rs for a complete example.
Important Notes:
- Handler must be thread-safe (use Arc/RwLock if needed)
- On macOS, call
stop_hook()to clean up - See examples/ for complete implementations
- Linux uses same API but doesn't require combined tracking
- Note: Implementation uses unsafe code and assumes single-threaded usage for now
- Embedded info callbacks are currently macOS-only; other platforms still receive the base callbacks
Platform Notes
Linux (Reference Implementation)
- Pure window focus tracking via X11 protocol
- No app tracking required
- Tested with common desktop environments (GNOME, KDE, etc.)
macOS Requirements
- Requires Accessibility permissions
- Enable in System Preferences > Security & Privacy > Privacy > Accessibility
Windows
- Not yet implemented (planned for future release)
API Documentation
Full API documentation is available via cargo doc --open.
Contributing
Contributions are welcome! Please open issues or pull requests on GitHub.
License
MIT - See LICENSE for details.