From 8596bf20873ec8b7f7a20b54207608f4ecfe07e5 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sun, 24 Aug 2025 12:34:37 -0400 Subject: [PATCH] fix drag region --- Cargo.lock | 54 +++++++++++++++++++ crates/desktop/artcraft/Cargo.toml | 6 +++ .../artcraft/capabilities/default.json | 14 ++--- .../src/core/lifecycle/startup/mod.rs | 3 +- .../lifecycle/startup/setup_main_window.rs | 51 ++++++++++++++++++ crates/desktop/artcraft/src/lib.rs | 3 ++ .../tauri.artcraft_3d.no_dev.conf.json | 7 --- .../src/components/signaled/TopBar/TopBar.tsx | 13 +++-- frontend/apps/editor3d/app/src/index.tsx | 5 +- frontend/apps/editor3d/app/src/root.tsx | 4 +- 10 files changed, 139 insertions(+), 21 deletions(-) create mode 100644 crates/desktop/artcraft/src/core/lifecycle/startup/setup_main_window.rs diff --git a/Cargo.lock b/Cargo.lock index e37695827e..0b2cf80b3a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -659,6 +659,7 @@ dependencies = [ "build_metadata", "bytes 1.10.1", "chrono", + "cocoa", "cookie_store 0.0.1", "directories", "dirs", @@ -1327,6 +1328,12 @@ dependencies = [ "constant_time_eq 0.3.0", ] +[[package]] +name = "block" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" + [[package]] name = "block-buffer" version = "0.9.0" @@ -2026,6 +2033,35 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "cocoa" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad36507aeb7e16159dfe68db81ccc27571c3ccd4b76fb2fb72fc59e7a4b1b64c" +dependencies = [ + "bitflags 2.5.0", + "block", + "cocoa-foundation", + "core-foundation 0.10.0", + "core-graphics", + "foreign-types 0.5.0", + "libc", + "objc", +] + +[[package]] +name = "cocoa-foundation" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81411967c50ee9a1fc11365f8c585f863a22a9697c89239c452292c40ba79b0d" +dependencies = [ + "bitflags 2.5.0", + "block", + "core-foundation 0.10.0", + "core-graphics-types", + "objc", +] + [[package]] name = "collections" version = "0.0.1" @@ -6104,6 +6140,15 @@ dependencies = [ "tiger", ] +[[package]] +name = "malloc_buf" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" +dependencies = [ + "libc", +] + [[package]] name = "markdown" version = "0.0.1" @@ -6869,6 +6914,15 @@ dependencies = [ "libc", ] +[[package]] +name = "objc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" +dependencies = [ + "malloc_buf", +] + [[package]] name = "objc-sys" version = "0.3.5" diff --git a/crates/desktop/artcraft/Cargo.toml b/crates/desktop/artcraft/Cargo.toml index 7b1e44fedd..99ad50df90 100644 --- a/crates/desktop/artcraft/Cargo.toml +++ b/crates/desktop/artcraft/Cargo.toml @@ -79,6 +79,12 @@ tauri-plugin-http = { path = "../../vendor/tauri-plugin-http" } # types and can't do threading. We need to wait for a new version to unpin from Git. discord-rich-presence = { git = "https://github.com/vionya/discord-rich-presence" } +# Transparent title bar on MacOS +# NB: See the notes here: +# https://v2.tauri.app/learn/window-customization/ +[target."cfg(target_os = \"macos\")".dependencies] +cocoa = "0.26" + [dev-dependencies] serial_test = "3.2.0" diff --git a/crates/desktop/artcraft/capabilities/default.json b/crates/desktop/artcraft/capabilities/default.json index 3f400e29e9..a7b3380d5f 100644 --- a/crates/desktop/artcraft/capabilities/default.json +++ b/crates/desktop/artcraft/capabilities/default.json @@ -5,13 +5,16 @@ "windows": ["main"], "permissions": [ "core:default", - "log:default", - "core:window:allow-minimize", - "core:window:allow-toggle-maximize", "core:window:allow-close", + "core:window:allow-minimize", + "core:window:allow-start-dragging", + "core:window:allow-toggle-maximize", + "core:window:default", + "dialog:default", + "http:allow-fetch", + "log:default", "upload:allow-download", "upload:default", - "http:allow-fetch", { "identifier": "http:default", "allow": [ @@ -22,7 +25,6 @@ "url": "http://localhost:12345" } ] - }, - "dialog:default" + } ] } diff --git a/crates/desktop/artcraft/src/core/lifecycle/startup/mod.rs b/crates/desktop/artcraft/src/core/lifecycle/startup/mod.rs index d50b223b7b..07db4020c0 100644 --- a/crates/desktop/artcraft/src/core/lifecycle/startup/mod.rs +++ b/crates/desktop/artcraft/src/core/lifecycle/startup/mod.rs @@ -1,2 +1,3 @@ +mod tasks; pub mod handle_tauri_startup; -mod tasks; \ No newline at end of file +pub mod setup_main_window; \ No newline at end of file diff --git a/crates/desktop/artcraft/src/core/lifecycle/startup/setup_main_window.rs b/crates/desktop/artcraft/src/core/lifecycle/startup/setup_main_window.rs new file mode 100644 index 0000000000..c2cd7239d3 --- /dev/null +++ b/crates/desktop/artcraft/src/core/lifecycle/startup/setup_main_window.rs @@ -0,0 +1,51 @@ +use tauri::{AppHandle, TitleBarStyle, WebviewUrl, WebviewWindowBuilder}; +use tauri::window::Color; +use errors::AnyhowResult; + +pub async fn setup_main_window( + app: &AppHandle, +) -> AnyhowResult<()> { + + let win_builder = + WebviewWindowBuilder::new(app, "main", WebviewUrl::default()) + .title("Artcraft") + //.decorations(false) // NB: This breaks Mac! + .resizable(true) + .fullscreen(false) + .background_color(Color(0, 0, 0, 0)) + .enable_clipboard_access() + .inner_size(800.0, 600.0); + + // set transparent title bar only when building for macOS + #[cfg(target_os = "macos")] + let win_builder = win_builder + .decorations(true) // NB: Mac requires decorations. Tons of capabilities disappear without it. + .title_bar_style(TitleBarStyle::Overlay) + .hidden_title(true) + .accept_first_mouse(true) // https://github.com/tauri-apps/tauri/issues/11605#issuecomment-2460112096 + .focusable(true) + .focused(true); + + let window = win_builder.build()?; + + /*// set background color only when building for macOS + #[cfg(target_os = "macos")] + { + use cocoa::appkit::{NSColor, NSWindow}; + use cocoa::base::{id, nil}; + + let ns_window = window.ns_window().unwrap() as id; + unsafe { + let bg_color = NSColor::colorWithRed_green_blue_alpha_( + nil, + 50.0 / 255.0, + 158.0 / 255.0, + 163.5 / 255.0, + 0.0, + ); + ns_window.setBackgroundColor_(bg_color); + } + }*/ + + Ok(()) +} \ No newline at end of file diff --git a/crates/desktop/artcraft/src/lib.rs b/crates/desktop/artcraft/src/lib.rs index 3ea90f483f..1e68139d71 100644 --- a/crates/desktop/artcraft/src/lib.rs +++ b/crates/desktop/artcraft/src/lib.rs @@ -18,6 +18,7 @@ use crate::core::commands::platform_info_command::platform_info_command; use crate::core::commands::providers::get_provider_order_command::get_provider_order_command; use crate::core::commands::providers::set_provider_order_command::set_provider_order_command; use crate::core::lifecycle::startup::handle_tauri_startup::handle_tauri_startup; +use crate::core::lifecycle::startup::setup_main_window::setup_main_window; use crate::core::state::app_env_configs::app_env_configs::AppEnvConfigs; use crate::core::state::app_preferences::app_preferences_manager::load_app_preferences_or_default; use crate::core::state::data_dir::app_data_root::AppDataRoot; @@ -121,6 +122,8 @@ pub fn run() { let fal_tasks = fal_task_queue_2.clone(); tauri::async_runtime::block_on(async move { + let result = setup_main_window(&app).await; + let result = handle_tauri_startup( handle, root, diff --git a/crates/desktop/artcraft/tauri.artcraft_3d.no_dev.conf.json b/crates/desktop/artcraft/tauri.artcraft_3d.no_dev.conf.json index fd9005e6bd..07dbef7f3c 100644 --- a/crates/desktop/artcraft/tauri.artcraft_3d.no_dev.conf.json +++ b/crates/desktop/artcraft/tauri.artcraft_3d.no_dev.conf.json @@ -7,13 +7,6 @@ }, "app": { "windows": [ - { - "title": "ArtCraft", - "resizable": true, - "fullscreen": false, - "dragDropEnabled": false, - "decorations": true - } ] } } diff --git a/frontend/apps/editor3d/app/src/components/signaled/TopBar/TopBar.tsx b/frontend/apps/editor3d/app/src/components/signaled/TopBar/TopBar.tsx index ea520acbba..2ab2ca2ba6 100644 --- a/frontend/apps/editor3d/app/src/components/signaled/TopBar/TopBar.tsx +++ b/frontend/apps/editor3d/app/src/components/signaled/TopBar/TopBar.tsx @@ -167,14 +167,16 @@ export const TopBar = ({ pageName, loginSignUpPressed }: Props) => {