Skip to content
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

System Notifications not working for "NSWindowDidMoveNotification" #120

Closed
swalker326 opened this issue Sep 13, 2024 · 1 comment
Closed

Comments

@swalker326
Copy link

swalker326 commented Sep 13, 2024

Maybe I misunderstand the use case but when I move a window, I would expect to see a log:

pub fn run() {
    tauri::Builder::default()
        .plugin(tauri_plugin_shell::init())
        .setup(|app| {
            #[cfg(all(desktop))]
            app.handle()
                .listen_workspace("NSWindowDidMoveNotification", |app_handle| {
                    println!("The window moved!");
                });
            Ok(())
        })
        .invoke_handler(tauri::generate_handler![greet])
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}

Are there some notifications this just doesn't work with?

@ahkohd
Copy link
Owner

ahkohd commented Sep 23, 2024

Yes, you cannot use this notification as you're not the main actor.

See what the docs says:
https://developer.apple.com/documentation/appkit/nswindowdidmovenotification
image

unlike NSWorkspaceActiveSpaceDidChangeNotification which the system posts this notification on an arbitrary actor.
https://developer.apple.com/documentation/appkit/nsworkspaceactivespacedidchangenotification
image

To detect when a window moves, you can easily use the accessibility APIs. Another method is to get the list of windows on the screen every X seconds and compare their positions to identify changes.

@ahkohd ahkohd pinned this issue Oct 7, 2024
@ahkohd ahkohd closed this as completed Oct 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants