Skip to content

Commit b8a066e

Browse files
committed
fix: use Tauri outerSize API for correct new window dimensions
innerWidth/innerHeight in Tauri don't account for title bar height and are affected by webview zoom. Add brackets.app.getWindowSize() that uses Tauri's outerSize()/scaleFactor() to get the true logical window size, and brackets.app.getZoomFactor() using PhStore.
1 parent ba0a011 commit b8a066e

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

src/document/DocumentCommandHandlers.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,11 +1756,8 @@ define(function (require, exports, module) {
17561756
);
17571757
}
17581758

1759-
function newPhoenixWindow(cliArgsArray = null, cwd=null) {
1760-
// Both Electron and Tauri need outerWidth/outerHeight (includes window chrome)
1761-
// so the new window matches the current window's total size.
1762-
let width = (window.__ELECTRON__ || window.__TAURI__) ? window.outerWidth : window.innerWidth;
1763-
let height = (window.__ELECTRON__ || window.__TAURI__) ? window.outerHeight : window.innerHeight;
1759+
async function newPhoenixWindow(cliArgsArray = null, cwd=null) {
1760+
const {width, height} = await brackets.app.getWindowSize();
17641761
Phoenix.app.openNewPhoenixEditorWindow(width, height, cliArgsArray, cwd);
17651762
}
17661763

@@ -1864,7 +1861,7 @@ define(function (require, exports, module) {
18641861
return;
18651862
}
18661863
}
1867-
newPhoenixWindow(args, cwd);
1864+
await newPhoenixWindow(args, cwd);
18681865
}
18691866

18701867
function handleFileNewWindow() {

src/phoenix/shell.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,34 @@ Phoenix.app = {
881881
return window.electronAPI.zoomWindow(scaleFactor);
882882
}
883883
},
884+
getZoomFactor: function () {
885+
return (window.PhStore && window.PhStore.getItem("desktopZoomScale")) || 1;
886+
},
887+
/**
888+
* Returns the logical outer size of the current window (includes title bar and window chrome).
889+
* @return {Promise<{width: number, height: number}>}
890+
*/
891+
getWindowSize: async function () {
892+
if(window.__TAURI__) {
893+
const currentWindow = window.__TAURI__.window.getCurrent();
894+
const outerSize = await currentWindow.outerSize();
895+
const scaleFactor = await currentWindow.scaleFactor();
896+
return {
897+
width: Math.round(outerSize.width / scaleFactor),
898+
height: Math.round(outerSize.height / scaleFactor)
899+
};
900+
}
901+
if(window.__ELECTRON__) {
902+
return {
903+
width: window.outerWidth,
904+
height: window.outerHeight
905+
};
906+
}
907+
return {
908+
width: window.innerWidth,
909+
height: window.innerHeight
910+
};
911+
},
884912
_openUrlInBrowserWin: function (url, browser) {
885913
// private API for internal use only. May be removed at any time.
886914
// Please use NodeUtils.openUrlInBrowser for a platform independent equivalent of this.

0 commit comments

Comments
 (0)