tauri-apps / plugins-workspace

All of the official Tauri plugins in one place!
https://tauri.app
Apache License 2.0
991 stars 278 forks source link

[positioner] `TrayCenter` not working on extended monitor when using multiple monitors [macOS] #724

Open DefectingCat opened 1 year ago

DefectingCat commented 1 year ago

When using menu.move_window(Position::TrayCenter)?; to put a system tray menu on the menu icon center, it's works on main monitor. But not any response in the extended monitor, also no error throwed.

Main monitor:

image

Extended monitor:

image

Code:

/// Create new system tray window
pub fn handle_tray_menu(app: &AppHandle) -> Result<()> {
    use tauri_plugin_positioner::{Position, WindowExt};

    // get or create a new menu window
    let (menu, is_build) = {
        let window = app.get_window("menu");
        if let Some(win) = window {
            (win, false)
        } else {
            let win = WindowBuilder::new(app, "menu", WindowUrl::App("system-tray".into()))
                .decorations(false)
                .transparent(true)
                .build()?;
            win.set_size(Size::Logical(LogicalSize {
                width: 300.0,
                height: 600.0,
            }))?;
            (win, true)
        }
    };

    if menu.is_visible()? && !is_build {
        menu.hide()?;
    } else {
        menu.move_window(Position::TrayCenter)?;
        menu.show()?;
        menu.set_focus()?;
        menu.set_always_on_top(true)?;
    }
    Ok(())
}
Lurrobert commented 7 months ago

Second this. Have similar code structure

.on_tray_icon_event(move |app, event| {
                    tauri_plugin_positioner::on_tray_event(app.app_handle(), &event);
                    // Use move to capture app_handle
                    if event.click_type == ClickType::Left {
                        println!("tray icon clicked");
                        // let window = app_handle.get_webview_window("editor").unwrap();
                        let mut win = app_handle.get_webview_window("editor").unwrap();
                        let _ = win.as_ref().window().move_window(Position::TrayCenter);

                        win.show();
                        win.set_focus().unwrap();
                    }

and it shows up some CleanShot 2024-04-28 at 15 18 28@2x where else on both screen in any kind of set up, single or double with monitor

0-don commented 2 weeks ago

have the same isssue on x11 kde linux