Skip to content

Commit

Permalink
Add on all macOS workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Hacksore committed Dec 30, 2023
1 parent 5f669a1 commit 5a478ab
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 3 additions & 0 deletions apps/desktop/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ fn main() {
// NOTE: this might be a bug?
window.set_decorations(false);

// allow on all workspaces
window.set_visisble_on_all_workspaces(true);

// add mac things
#[cfg(target_os = "macos")]
apply_macos_specifics(app, &window);
Expand Down
29 changes: 28 additions & 1 deletion apps/desktop/src-tauri/src/window_custom.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
#[cfg(target_os = "macos")]
use cocoa::appkit::{NSWindow, NSWindowButton, NSWindowStyleMask, NSWindowTitleVisibility};
use cocoa::appkit::{
NSMainMenuWindowLevel, NSWindow, NSWindowButton, NSWindowCollectionBehavior, NSWindowStyleMask,
NSWindowTitleVisibility,
};

#[cfg(target_os = "macos")]
use objc::runtime::YES;

#[cfg(target_os = "macos")]
use cocoa::base::id;

use tauri::{Runtime, Window};

pub trait WindowExt {
#[cfg(target_os = "macos")]
fn set_transparent_titlebar(&self, title_transparent: bool, remove_toolbar: bool);
#[cfg(target_os = "macos")]
fn set_visisble_on_all_workspaces(&self, enabled: bool);
}

impl<R: Runtime> WindowExt for Window<R> {
#[cfg(target_os = "macos")]
fn set_visisble_on_all_workspaces(&self, enabled: bool) {
{
let ns_win = self.ns_window().unwrap() as id;
unsafe {
if enabled {
ns_win.setLevel_(((NSMainMenuWindowLevel + 1) as u64).try_into().unwrap());
ns_win.setCollectionBehavior_(
NSWindowCollectionBehavior::NSWindowCollectionBehaviorCanJoinAllSpaces,
);
} else {
ns_win.setLevel_(((NSMainMenuWindowLevel - 1) as u64).try_into().unwrap());
ns_win
.setCollectionBehavior_(NSWindowCollectionBehavior::NSWindowCollectionBehaviorDefault);
}
}
}
}
#[cfg(target_os = "macos")]
fn set_transparent_titlebar(&self, title_transparent: bool, remove_tool_bar: bool) {
unsafe {
Expand Down

0 comments on commit 5a478ab

Please sign in to comment.