-
-
Notifications
You must be signed in to change notification settings - Fork 70
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
feat: list window in z order #173
Conversation
Work seamlessly on Windows @louis030195 👍 |
The implementation method on macOS is incorrect, which can lead to multiple windows being in a focused state simultaneously. use cocoa::base::{id, nil};
use cocoa::foundation::NSString;
use objc::{class, msg_send, sel, sel_impl};
fn main() {
unsafe {
// 获取 NSWorkspace 类的实例
let workspace: id = msg_send![class!(NSWorkspace), sharedWorkspace];
// 获取当前前台应用
let front_app: id = msg_send![workspace, frontmostApplication];
println!("front_app {:?}", front_app);
if front_app != nil {
let app_name: id = msg_send![front_app, localizedName];
let app_name_str = NSString::UTF8String(app_name);
println!("当前聚焦的应用程序: {}", std::ffi::CStr::from_ptr(app_name_str).to_str().unwrap());
} else {
println!("无法获取当前聚焦的应用程序。");
}
}
} |
isnt window inside apps anyway? |
An application may have multiple windows, but the system can only identify which application is currently in focus, not the specific window within that application that is focused. However, I am confident that there are other methods to obtain this information. For instance, Electron can retrieve it. |
MacOS can get a relatively accurate Focused window, but there are still some problems. For example, if an application has multiple windows and one of them is set to always stay on top, switching to another window within the same application may still retrieve information about the window that is always on top. To obtain accurate information about the focused window, accessibility permissions are likely required. |
f I return the window hierarchy, is the is_focused status no longer needed? |
maybe |
@louis030195 The return value of use std::thread;
use xcap::Window;
fn main() {
thread::sleep(std::time::Duration::from_secs(3));
let windows = Window::all().unwrap();
for window in windows.clone() {
println!(
"Window:\n id: {}\n title: {}\n app_name: {}\n pid: {}\n monitor: {:?}\n position: {:?}\n size {:?}\n state {:?}\n",
window.id(),
window.title(),
window.app_name(),
window.pid(),
window.current_monitor().name(),
(window.x(), window.y(), window.z()),
(window.width(), window.height()),
(window.is_minimized(), window.is_maximized())
);
}
} |
that's cool! what happen in these situations:
|
After consideration, the Z value will still remain unique, just like in Windows and Linux. |
* feat: 窗口按照z轴顺序返回 * refactor(BREAKING CHANGE): remove window.refresh() --------- Co-authored-by: nashaofu <[email protected]>
Co-authored-by: nashaofu <[email protected]>
@nashaofu fyi this does not work on macos minimized / maximized is always false and z is showing 0 even though it's in the background version 0.2.1 |
#172