Skip to content

Commit 0402ced

Browse files
authored
Fix fullscreen apps on macOS (#108)
❤️ @LucFauvel @boek
1 parent a556fce commit 0402ced

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

apps/desktop/src-tauri/src/main.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ use tray::Tray;
2222
use window_custom::WindowExt;
2323

2424
#[cfg(target_os = "macos")]
25-
use tauri::{App, Window};
25+
use tauri::Window;
2626

2727
pub struct Pinned(AtomicBool);
2828

2929
#[cfg(target_os = "macos")]
30-
fn apply_macos_specifics(_app: &mut App, window: &Window) {
30+
fn apply_macos_specifics(window: &Window) {
3131
window.set_visisble_on_all_workspaces(true);
3232
window.set_transparent_titlebar(true, true);
3333
}
@@ -51,6 +51,7 @@ fn main() {
5151
let settings = app.get_window(SETTINGS_WINDOW_NAME).unwrap();
5252

5353
// the window should always be on top
54+
#[cfg(not(target_os = "macos"))]
5455
window.set_always_on_top(true);
5556

5657
// set the document title for the main window
@@ -66,7 +67,7 @@ fn main() {
6667

6768
// add mac things
6869
#[cfg(target_os = "macos")]
69-
apply_macos_specifics(app, &window);
70+
apply_macos_specifics(&window);
7071

7172
// Open dev tools only when in dev mode
7273
#[cfg(debug_assertions)]

apps/desktop/src-tauri/src/window_custom.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ use cocoa::appkit::{
44
NSWindowTitleVisibility,
55
};
66

7+
#[cfg(target_os = "macos")]
8+
use cocoa::foundation::NSInteger;
9+
710
#[cfg(target_os = "macos")]
811
use objc::runtime::YES;
912

@@ -12,6 +15,9 @@ use cocoa::base::id;
1215

1316
use tauri::{Runtime, Window};
1417

18+
#[cfg(target_os = "macos")]
19+
use objc::msg_send;
20+
1521
pub trait WindowExt {
1622
#[cfg(target_os = "macos")]
1723
fn set_transparent_titlebar(&self, title_transparent: bool, remove_toolbar: bool);
@@ -24,10 +30,12 @@ impl<R: Runtime> WindowExt for Window<R> {
2430
#[cfg(target_os = "macos")]
2531
fn set_visisble_on_all_workspaces(&self, enabled: bool) {
2632
{
33+
const HIGHER_LEVEL_THAN_LEAGUE: NSInteger = 1001;
2734
let ns_win = self.ns_window().unwrap() as id;
35+
2836
unsafe {
2937
if enabled {
30-
ns_win.setLevel_(((NSMainMenuWindowLevel + 1) as u64).try_into().unwrap());
38+
ns_win.setLevel_(HIGHER_LEVEL_THAN_LEAGUE);
3139
ns_win.setCollectionBehavior_(
3240
NSWindowCollectionBehavior::NSWindowCollectionBehaviorCanJoinAllSpaces,
3341
);

0 commit comments

Comments
 (0)