-
-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Find a way to check if window is focused for long-running apps #190
Comments
On macOS you can check for a.mp4 |
I created a file under use std::thread;
use xcap::Window;
fn main() {
thread::sleep(std::time::Duration::from_secs(3));
let windows = Window::all().unwrap();
loop {
let focused = windows.iter().find(|w| w.is_focused()).unwrap();
println!(
"Focused Window:\n id: {}\n title: {}\n app_name: {}\n pid: {}\n monitor: {:?}\n position: {:?}\n size {:?}\n state {:?}\n",
focused.id(),
focused.title(),
focused.app_name(),
focused.pid(),
focused.current_monitor().name(),
(focused.x(), focused.y(), focused.z()),
(focused.width(), focused.height()),
(focused.is_minimized(), focused.is_maximized(), focused.is_focused())
);
thread::sleep(std::time::Duration::from_secs(1));
}
} Here's the naive approach I've tried on turning pub fn is_focused(&self) -> bool {
let focused_app_pid = unsafe {
let workspace = NSWorkspace::sharedWorkspace();
let frontMostApplication = workspace.frontmostApplication();
frontMostApplication.map(|focused_app| focused_app.processIdentifier())
};
focused_app_pid.eq(&Some(self.pid as i32))
} |
@nashaofu although the current solution for checking if the window is focused is good and it works, it does not work for long-running apps such as mediar-ai/screenpipe.
it'd be good to have some way to either:
is_focused
a computed function, which will check againstpid
of currently focused windowWindow
from theMonitor
also @louis030195, please share if you can think of any alternative solution
The text was updated successfully, but these errors were encountered: