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

feat(macOS): add window.set_visible_on_fullscreen() #189

Open
probablykasper opened this issue Aug 13, 2021 · 16 comments
Open

feat(macOS): add window.set_visible_on_fullscreen() #189

probablykasper opened this issue Aug 13, 2021 · 16 comments

Comments

@probablykasper
Copy link
Member

@probablykasper
Copy link
Member Author

@srsholmes was talking about how this could work in tauri-apps/tauri#2258 (as well as behavior across multiple spaces, which idk if there should be another issue for?)

@amrbashir amrbashir changed the title feat: Show window over fullscreen apps feat: expose set_visible_on_all_workspaces() Aug 13, 2021
@amrbashir
Copy link
Member

amrbashir commented Aug 13, 2021

on hold until #185 is done

@probablykasper
Copy link
Member Author

@amrbashir I don't think showing over fullscreen apps is necessarily the same as showing on all workspaces, though I don't know for sure

@amrbashir
Copy link
Member

amrbashir commented Aug 13, 2021

I guess that is true, it doesn't have to be coupled with set_visible_on_all_workspaces but it will be only for mac.
I will transfer to tao.

@amrbashir amrbashir changed the title feat: expose set_visible_on_all_workspaces() feat(macOS): add set_visible_on_fullscreen() Aug 13, 2021
@amrbashir amrbashir transferred this issue from tauri-apps/tauri Aug 13, 2021
@amrbashir amrbashir changed the title feat(macOS): add set_visible_on_fullscreen() feat(macOS): add window.set_visible_on_fullscreen() Aug 13, 2021
@srsholmes
Copy link

This can be achieved (at least on macos) by the work in #185. It might be possibly what the

      ns_window.setLevel_(10000);

is doing.

I havn't tested it without the setlevel, but I am able to have my tauri app show over full screen apps with the tweaks mentioned in that issue.

amrbashir referenced this issue Jan 15, 2023
* feat: add `set_visible_on_all_workspaces`, closes #185

* fix macOS implementation

* fix macOS

* remove moveToActiveSpace flag
@ParthJadhav
Copy link

Hey @srsholmes @probablykasper :

#[tauri::command]
pub fn show_tauri_window(window: Window) {
    let ns_window = window.ns_window().unwrap() as id;
    unsafe {
        let mut collection_behavior = ns_window.collectionBehavior();
        collection_behavior |= NSWindowCollectionBehavior::NSWindowCollectionBehaviorCanJoinAllSpaces;
        window.show().unwrap();
        ns_window.setLevel_(10000);
    }
}

As suggested this should be able to show the window above any fullscreen application. But it doesn't do that on release versions. It works fine on dev but not on realease.

MacOS: Ventura
Cpu: M2

@Kharya1337
Copy link

Hi
Any updates on this one?

@mrzhjyw
Copy link

mrzhjyw commented Dec 2, 2023

No new developments?

@G07cha
Copy link

G07cha commented Feb 11, 2024

I was able to make it work in release app by combining @ParthJadhav's example and adding

<key>LSUIElement</key>
<true/>

to Info.plist as mentioned in https://stackoverflow.com/a/35452482/6475535

@KarthikeyanKanniappan
Copy link

Hi, Do we have any update regarding this Issue

@amrbashir
Copy link
Member

@pewsheen can you research this and see if we can squeeze it before v2 rc?

@pewsheen
Copy link
Contributor

After some tries, I can make it work by setting ActivationPolicy::Accessory and setVisibleOnAllWorkspaces(true)

Can someone else confirm this works?

fn main() {
    tauri::Builder::default()
        .setup(| app | {
            app.set_activation_policy(tauri::ActivationPolicy::Accessory);
            Ok(())
        })
        .run(tauri::generate_context!())
        .expect("error while running tauri application");
}
import { Window } from '@tauri-apps/api/window';
const window = Window.getByLabel('main');
window?.setVisibleOnAllWorkspaces(true);
window?.setAlwaysOnTop(true);

@cdrani
Copy link

cdrani commented May 5, 2024

I can confirm. Tested using M1 on v2. I didn't use the js bindings, but setting the activation policy does work in having the window always on top. However, it doesn't seem to no-op on windows and linux. I tried placing it behind a macos cfg only, but it still fails for the other OSs on test builds in an action. The below is from an ubuntu-22.04 test build:

error[E0433]: failed to resolve: could not find `ActivationPolicy` in `tauri`
   --> src/app/setup.rs:81:42
    |
81  |         app.set_activation_policy(tauri::ActivationPolicy::Accessory);
    |                                          ^^^^^^^^^^^^^^^^ could not find `ActivationPolicy` in `tauri`
    |
note: found an item that was configured out
   --> /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tauri-2.0.0-beta.17/src/lib.rs:209:18
    |
209 | pub use runtime::ActivationPolicy;
    |                  ^^^^^^^^^^^^^^^^
    = note: the item is gated behind the `macos` feature

error[E0599]: no method named `set_activation_policy` found for mutable reference `&mut tauri::App` in the current scope
  --> src/app/setup.rs:81:13
   |
81 |         app.set_activation_policy(tauri::ActivationPolicy::Accessory);
   |             ^^^^^^^^^^^^^^^^^^^^^ method not found in `&mut App`

@pewsheen
Copy link
Contributor

pewsheen commented May 6, 2024

Try add target_os above the line:

#[cfg(target_os = "macos")]
app.set_activation_policy(tauri::ActivationPolicy::Accessory);

I can confirm. Tested using M1 on v2. I didn't use the js bindings, but setting the activation policy does work in having the window always on top. However, it doesn't seem to no-op on windows and linux. I tried placing it behind a macos cfg only, but it still fails for the other OSs on test builds in an action. The below is from an ubuntu-22.04 test build:

@cdrani
Copy link

cdrani commented May 6, 2024

Weird. This was what I was using originally, but still causing failed builds.

if cfg!(target_os = "macos") {
	app.set_activation_policy(tauri::ActivationPolicy::Accessory);
}

...

but the builds succeed now with this:

#[cfg(target_os = "macos")]
{
	app.set_activation_policy(tauri::ActivationPolicy::Accessory);
}

...

Ideally we don't need a cfg guard at all, and it's just a no-op on unsupported OSs.

@pewsheen
Copy link
Contributor

pewsheen commented May 7, 2024

I think that was because cfg! marco still compiles the code, it returns a boolean. #[cfg] will conditionally compile the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 📬Proposal
Development

No branches or pull requests

10 participants