tauri icon indicating copy to clipboard operation
tauri copied to clipboard

[feat] add window.set_level API

Open Lydanne opened this issue 3 years ago • 8 comments

Describe the problem

I hope that the window layer can be set by setLevel.

Describe the solution you'd like

#![cfg_attr(
    all(not(debug_assertions), target_os = "windows"),
    windows_subsystem = "windows"
)]

use tauri::{LogicalPosition, Manager, Position};

fn main() {
    let context = tauri::generate_context!();

    tauri::Builder::default()
        .setup(|app| {
            let main_window = app.get_window("main").unwrap();

            #[cfg(target_os = "macos")]
            {
                use cocoa::appkit::{NSMainMenuWindowLevel, NSWindow};
                use cocoa::base::id;
                let ns_win = main_window.ns_window().unwrap() as id;
                unsafe {
                    ns_win.setLevel_(((NSMainMenuWindowLevel + 1) as u64).try_into().unwrap());
                }
            } 
            // main_window.set_level(WindowLevel::MainMenu+1); // ideal setup
 
            Ok(())
        })
        .menu(tauri::Menu::os_default(&context.package_info().name))
        .run(context)
        .expect("error while running tauri application");
}

Alternatives considered

No response

Additional context

No response

Lydanne avatar Jul 07 '22 15:07 Lydanne

/upstream tauri-apps/tao

lucasfernog avatar Jul 07 '22 16:07 lucasfernog

Hey @WumaCoder , Did u get it to be in front of Full screen applications? For me it works in Dev, But when I build it; It Doesn't work...

ParthJadhav avatar Jan 14 '23 06:01 ParthJadhav

I only tried dev

Hey @WumaCoder , Did u get it to be in front of Full screen applications? For me it works in Dev, But when I build it; It Doesn't work...

Lydanne avatar Jan 15 '23 08:01 Lydanne

Has anyone figured out a workaround for this? It works perfectly in dev, but once I build it it doesn't work - same as @ParthJadhav

harrismcc avatar Aug 07 '23 16:08 harrismcc

Hey @WumaCoder , Did u get it to be in front of Full screen applications? For me it works in Dev, But when I build it; It Doesn't work...

Hey @harrismcc ,

yes, @ahkohd implemented this and it works great. https://github.com/ahkohd/tauri-macos-spotlight-example

ParthJadhav avatar Aug 07 '23 16:08 ParthJadhav

Thanks! I also found https://github.com/BillGoldenWater/ChaosDanmuTool/blob/dev/backend/src/utils/window_utils/macos.rs which I got working, but what you sent seems like it could be a better implementation so I'll look it over!

harrismcc avatar Aug 07 '23 17:08 harrismcc

Workaround works but I would love to see support for this feature.

dimaportenko avatar Nov 22 '23 19:11 dimaportenko