{"id":22663378,"url":"https://github.com/efjerryyang/winshift-rs","last_synced_at":"2026-02-02T03:02:28.525Z","repository":{"id":253454422,"uuid":"843550557","full_name":"efJerryYang/winshift-rs","owner":"efJerryYang","description":null,"archived":false,"fork":false,"pushed_at":"2025-09-28T20:32:37.000Z","size":72,"stargazers_count":2,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-04T02:18:13.285Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/efJerryYang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-08-16T19:06:52.000Z","updated_at":"2025-10-23T02:40:27.000Z","dependencies_parsed_at":"2025-05-24T16:20:27.157Z","dependency_job_id":"a3a3f5a2-1626-40bd-9fda-e3a1c3a7c1a2","html_url":"https://github.com/efJerryYang/winshift-rs","commit_stats":null,"previous_names":["efjerryyang/winshift-rs"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/efJerryYang/winshift-rs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/efJerryYang%2Fwinshift-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/efJerryYang%2Fwinshift-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/efJerryYang%2Fwinshift-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/efJerryYang%2Fwinshift-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/efJerryYang","download_url":"https://codeload.github.com/efJerryYang/winshift-rs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/efJerryYang%2Fwinshift-rs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29002632,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-02T01:32:03.847Z","status":"online","status_checked_at":"2026-02-02T02:00:07.448Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-09T12:18:44.107Z","updated_at":"2026-02-02T03:02:28.520Z","avatar_url":"https://github.com/efJerryYang.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# winshift\n\n[![Crates.io](https://img.shields.io/crates/v/winshift)](https://crates.io/crates/winshift)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nA cross-platform library for monitoring window focus changes.\n\n## Features\n\n- Native window focus tracking on Linux via X11 (reference implementation)\n- macOS support via Accessibility API (requires app tracking workaround)\n- Event-driven callback system\n- Minimal overhead window monitoring\n- Optional embedded active window info in callbacks (macOS)\n\nNote: The app tracking functionality on macOS exists solely to work around\nplatform limitations for reliable window focus detection.\n\n## Supported Platforms\n\n- **Linux**: Native window focus tracking via X11 (reference implementation)\n- **macOS**: Window tracking via Accessibility API workaround (requires app tracking)\n- **Windows**: Planned (not yet implemented)\n\n## Quick Start\n\n```sh\ncargo add winshift\n```\n\nSee the [Examples](#examples) section for usage patterns.\n\n## Examples\n\n### Illustrative Usage Pattern\n\nThis simplified example shows the basic structure. For complete, working examples see the [examples/](examples/) directory.\n\n```rust,no_run\nuse winshift::{FocusChangeHandler, WindowFocusHook};\nuse std::sync::Arc;\n\nstruct MyHandler;\n\nimpl FocusChangeHandler for MyHandler {\n    fn on_app_change(\u0026self, pid: i32, app_name: String) {\n        println!(\"App changed: {} (PID: {})\", app_name, pid);\n    }\n\n    fn on_window_change(\u0026self, window_title: String) {\n        println!(\"Window changed: {}\", window_title);\n    }\n}\n\nfn main() -\u003e Result\u003c(), winshift::WinshiftError\u003e {\n    let handler = Arc::new(MyHandler);\n    let hook = WindowFocusHook::new(handler);\n    \n    // Start monitoring (runs in current thread)\n    hook.run()?;\n    \n    // On macOS, you can stop with:\n    // winshift::stop_hook();\n    \n    Ok(())\n}\n```\n\n### macOS: Embedded ActiveWindowInfo (no extra queries)\n\nWhen 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.\n\nHow to enable:\n\n```rust\nuse winshift::{FocusChangeHandler, WindowFocusHook, WindowHookConfig};\n\nstruct Handler;\n\nimpl FocusChangeHandler for Handler {\n    fn on_app_change(\u0026self, pid: i32, app_name: String) {\n        println!(\"app: {app_name} ({pid})\");\n    }\n    fn on_window_change(\u0026self, title: String) {\n        println!(\"win: {title}\");\n    }\n\n    // macOS-only rich payloads\n    #[cfg(target_os = \"macos\")]\n    fn on_app_change_info(\u0026self, info: winshift::ActiveWindowInfo) {\n        println!(\"app+info: {} pid={} exe={} wid={} bounds=({},{} {}x{})\",\n            info.app_name, info.process_id, info.proc_path, info.window_id,\n            info.bounds.x, info.bounds.y, info.bounds.width, info.bounds.height);\n    }\n    #[cfg(target_os = \"macos\")]\n    fn on_window_change_info(\u0026self, info: winshift::ActiveWindowInfo) {\n        println!(\"win+info: '{}' exe={}\", info.title, info.proc_path);\n    }\n}\n\nfn main() -\u003e Result\u003c(), winshift::WinshiftError\u003e {\n    winshift::env_logger::init();\n    let mut cfg = WindowHookConfig::default();\n    cfg.embed_active_info = true; // opt-in to richer payloads\n    let hook = WindowFocusHook::with_config(Handler, cfg);\n    hook.run()\n}\n```\n\nSee `examples/embed_info_monitor.rs` for a complete example.\n\n**Important Notes**:\n\n1. Handler must be thread-safe (use Arc/RwLock if needed)\n2. On macOS, call `stop_hook()` to clean up\n3. See [examples/](examples/) for complete implementations\n4. Linux uses same API but doesn't require combined tracking\n5. Note: Implementation uses unsafe code and assumes single-threaded usage for now\n6. Embedded info callbacks are currently macOS-only; other platforms still receive the base callbacks\n\n## Platform Notes\n\n### Linux (Reference Implementation)\n\n- Pure window focus tracking via X11 protocol\n- No app tracking required\n- Tested with common desktop environments (GNOME, KDE, etc.)\n\n### macOS Requirements\n\n- Requires Accessibility permissions\n- Enable in System Preferences \u003e Security \u0026 Privacy \u003e Privacy \u003e Accessibility\n\n### Windows\n\n- Not yet implemented (planned for future release)\n\n## API Documentation\n\nFull API documentation is available via `cargo doc --open`.\n\n## Contributing\n\nContributions are welcome! Please open issues or pull requests on GitHub.\n\n## License\n\nMIT - See [LICENSE](LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fefjerryyang%2Fwinshift-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fefjerryyang%2Fwinshift-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fefjerryyang%2Fwinshift-rs/lists"}