Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

(temp fix) corrected inner size for undecorated windows with shadows on Windows

Ilya046bff582f71
diff --git a/Cargo.lock b/Cargo.lock
index 2d6730eb2..e3e0ad2ee 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1787,6 +1787,7 @@ dependencies = [
"tauri-plugin-notification",
"tauri-plugin-oauth",
"tauri-plugin-os",
+ "tauri-plugin-positioner",
"tauri-plugin-process",
"tauri-plugin-shell",
"tauri-plugin-single-instance",
@@ -6877,6 +6878,21 @@ dependencies = [
"thiserror 2.0.6",
]
+[[package]]
+name = "tauri-plugin-positioner"
+version = "2.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8c95b371d489bee3d1be5e5bd1538080ad408317fcc2d8546d24b290249f7bb5"
+dependencies = [
+ "log",
+ "serde",
+ "serde_json",
+ "serde_repr",
+ "tauri",
+ "tauri-plugin",
+ "thiserror 2.0.6",
+]
+
[[package]]
name = "tauri-plugin-process"
version = "2.0.1"
diff --git a/apps/desktop/src-tauri/Cargo.toml b/apps/desktop/src-tauri/Cargo.toml
index 70a6aa8c9..8806b9586 100644
--- a/apps/desktop/src-tauri/Cargo.toml
+++ b/apps/desktop/src-tauri/Cargo.toml
@@ -38,6 +38,7 @@ tauri-plugin-store = "2.2.0"
tauri-plugin-updater = "2.2.0"
tauri-plugin-oauth = { git = "https://github.com/FabianLars/tauri-plugin-oauth", branch = "v2" }
tauri-plugin-window-state = "2.2.0"
+tauri-plugin-positioner = "2.2.0"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
diff --git a/apps/desktop/src-tauri/src/lib.rs b/apps/desktop/src-tauri/src/lib.rs
index 751eecc22..ccbbeaff2 100644
--- a/apps/desktop/src-tauri/src/lib.rs
+++ b/apps/desktop/src-tauri/src/lib.rs
@@ -1895,20 +1895,8 @@ pub async fn run() {
#[cfg(target_os = "macos")]
{
- builder = builder.plugin(tauri_nspanel::init());
- }
-
- builder
- .plugin(tauri_plugin_shell::init())
- .plugin(tauri_plugin_dialog::init())
- .plugin(tauri_plugin_store::Builder::new().build())
- .plugin(tauri_plugin_os::init())
- .plugin(tauri_plugin_process::init())
- .plugin(tauri_plugin_oauth::init())
- .plugin(tauri_plugin_http::init())
- .plugin(tauri_plugin_updater::Builder::new().build())
- .plugin(tauri_plugin_notification::init())
- .plugin(
+ builder = builder.plugin(tauri_nspanel::init()).plugin(
+ // TODO(Ilya): Also enable for Windows when Tao is updated to `0.31.0`
tauri_plugin_window_state::Builder::new()
.with_state_flags({
use tauri_plugin_window_state::StateFlags;
@@ -1928,7 +1916,19 @@ pub async fn run() {
_ => label,
})
.build(),
- )
+ );
+ }
+
+ builder
+ .plugin(tauri_plugin_shell::init())
+ .plugin(tauri_plugin_dialog::init())
+ .plugin(tauri_plugin_store::Builder::new().build())
+ .plugin(tauri_plugin_os::init())
+ .plugin(tauri_plugin_process::init())
+ .plugin(tauri_plugin_oauth::init())
+ .plugin(tauri_plugin_http::init())
+ .plugin(tauri_plugin_updater::Builder::new().build())
+ .plugin(tauri_plugin_notification::init())
.plugin(flags::plugin::init())
.invoke_handler({
let handler = specta_builder.invoke_handler();
@@ -2082,25 +2082,27 @@ pub async fn run() {
match event {
WindowEvent::Destroyed => {
- match CapWindowId::from_str(label).unwrap() {
- CapWindowId::Main => {
- if let Some(w) = CapWindowId::Camera.get(app) {
- w.close().ok();
+ if let Ok(window_id) = CapWindowId::from_str(label) {
+ match window_id {
+ CapWindowId::Main => {
+ if let Some(w) = CapWindowId::Camera.get(app) {
+ w.close().ok();
+ }
}
- }
- CapWindowId::Editor { project_id } => {
- let app_handle = app.clone();
- tokio::spawn(async move {
- let _ = remove_editor_instance(&app_handle, project_id).await;
- tokio::task::yield_now().await;
- });
- }
- CapWindowId::Settings | CapWindowId::Upgrade => {
- // Don't quit the app when settings or upgrade window is closed
- return;
- }
- _ => {}
- };
+ CapWindowId::Editor { project_id } => {
+ let app_handle = app.clone();
+ tokio::spawn(async move {
+ let _ = remove_editor_instance(&app_handle, project_id).await;
+ tokio::task::yield_now().await;
+ });
+ }
+ CapWindowId::Settings | CapWindowId::Upgrade => {
+ // Don't quit the app when settings or upgrade window is closed
+ return;
+ }
+ _ => {}
+ };
+ }
if let Some(settings) = GeneralSettingsStore::get(app).unwrap_or(None) {
if settings.hide_dock_icon
@@ -2114,11 +2116,13 @@ pub async fn run() {
}
}
}
+ #[cfg(target_os = "macos")]
WindowEvent::Focused(focused) if *focused => {
- if CapWindowId::from_str(label).unwrap().activates_dock() {
- #[cfg(target_os = "macos")]
- app.set_activation_policy(tauri::ActivationPolicy::Regular)
- .ok();
+ if let Ok(window_id) = CapWindowId::from_str(label) {
+ if window_id.activates_dock() {
+ app.set_activation_policy(tauri::ActivationPolicy::Regular)
+ .ok();
+ }
}
}
_ => {}
diff --git a/apps/desktop/src-tauri/src/windows.rs b/apps/desktop/src-tauri/src/windows.rs
index 42a1930a2..beebf65ad 100644
--- a/apps/desktop/src-tauri/src/windows.rs
+++ b/apps/desktop/src-tauri/src/windows.rs
@@ -9,6 +9,7 @@ use tauri::{
AppHandle, LogicalPosition, Manager, WebviewUrl, WebviewWindow, WebviewWindowBuilder, Wry,
};
+#[cfg(target_os = "macos")]
const DEFAULT_TRAFFIC_LIGHTS_INSET: LogicalPosition<f64> = LogicalPosition::new(12.0, 12.0);
#[derive(Clone)]
@@ -90,6 +91,7 @@ impl CapWindowId {
app.get_webview_window(&label)
}
+ #[cfg(target_os = "macos")]
pub fn traffic_lights_position(&self) -> Option<Option<LogicalPosition<f64>>> {
match self {
Self::Editor { .. } => Some(Some(LogicalPosition::new(20.0, 40.0))),
@@ -99,10 +101,12 @@ impl CapWindowId {
_ => Some(None),
}
}
+
pub fn min_size(&self) -> Option<(f64, f64)> {
Some(match self {
Self::Setup => (600.0, 600.0),
Self::Main => (300.0, 360.0),
+ Self::Editor { .. } => (1150.0, 800.0),
Self::Settings => (600.0, 450.0),
Self::Camera => (460.0, 920.0),
_ => return None,
@@ -164,7 +168,6 @@ impl ShowCapWindow {
.build()?,
Self::Editor { project_id } => self
.window_builder(app, format!("/editor?id={project_id}"))
- .inner_size(1150.0, 800.0)
.maximizable(true)
.center()
.build()?,
@@ -322,6 +325,16 @@ impl ShowCapWindow {
window.hide().ok();
+ // TODO(Ilya): Remove once Tao is updated to `0.31.0`
+ #[cfg(target_os = "windows")]
+ if matches!(
+ self,
+ Self::Setup | Self::Main | Self::Editor { .. } | Self::Settings { .. } | Self::Upgrade
+ ) {
+ use tauri_plugin_positioner::{Position, WindowExt};
+ let _ = window.move_window(Position::Center);
+ }
+
#[cfg(target_os = "macos")]
if let Some(position) = id.traffic_lights_position() {
add_traffic_lights(&window, position);
@@ -344,9 +357,28 @@ impl ShowCapWindow {
.shadow(true);
if let Some(min) = id.min_size() {
+ // TODO(Ilya): Remove once Tao is updated to `0.31.0`
+ // currently, undecorated windows with shadows get the invisible bounds of the titlebar and window frame added to the inner size
+ #[cfg(target_os = "windows")]
+ let size = if matches!(
+ self,
+ Self::Setup
+ | Self::Main
+ | Self::Editor { .. }
+ | Self::Settings { .. }
+ | Self::Upgrade
+ ) {
+ (min.0 - 12.0, min.1 - 35.0)
+ } else {
+ min
+ };
+
+ #[cfg(not(target_os = "windows"))]
+ let size = min;
+
builder = builder
- .inner_size(min.0, min.1)
- .min_inner_size(min.0, min.1);
+ .inner_size(size.0, size.1)
+ .min_inner_size(size.0, size.1);
}
#[cfg(target_os = "macos")]