@@ -77,6 +77,7 @@ function makeFakeBrowserWindow() {
7777 isDestroyed : vi . fn ( ( ) => false ) ,
7878 getURL : vi . fn ( ( ) => "t3code-dev://app/" ) ,
7979 getZoomLevel : vi . fn ( ( ) => zoomLevel ) ,
80+ getZoomFactor : vi . fn ( ( ) => 1.2 ** zoomLevel ) ,
8081 setZoomLevel : vi . fn ( ( level : number ) => {
8182 zoomLevel = level ;
8283 } ) ,
@@ -118,6 +119,7 @@ function makeFakeBrowserWindow() {
118119 setOpacity : vi . fn ( ) ,
119120 setTitle : vi . fn ( ) ,
120121 setTitleBarOverlay : vi . fn ( ) ,
122+ setWindowButtonPosition : vi . fn ( ) ,
121123 show : vi . fn ( ) ,
122124 webContents,
123125 } ;
@@ -136,6 +138,7 @@ function makeFakeBrowserWindow() {
136138 reload : webContents . reload ,
137139 send : webContents . send ,
138140 setZoomLevel : webContents . setZoomLevel ,
141+ setWindowButtonPosition : window . setWindowButtonPosition ,
139142 setBackgroundThrottling : webContents . setBackgroundThrottling ,
140143 setAutoHideCursor : window . setAutoHideCursor ,
141144 setFullScreen : window . setFullScreen ,
@@ -742,6 +745,39 @@ describe("DesktopWindow", () => {
742745 } ) ,
743746 ) ;
744747
748+ it . effect ( "keeps macOS window buttons centered when zooming and leaving fullscreen" , ( ) =>
749+ Effect . gen ( function * ( ) {
750+ const fakeWindow = makeFakeBrowserWindow ( ) ;
751+ const createCount = yield * Ref . make ( 0 ) ;
752+ const mainWindow = yield * Ref . make < Option . Option < Electron . BrowserWindow > > ( Option . none ( ) ) ;
753+ const layer = makeTestLayer ( { window : fakeWindow . window , createCount, mainWindow } ) ;
754+
755+ yield * Effect . gen ( function * ( ) {
756+ const desktopWindow = yield * DesktopWindow . DesktopWindow ;
757+ yield * desktopWindow . handleBackendReady ( new URL ( "http://127.0.0.1:3773" ) ) ;
758+
759+ for ( const direction of [ "in" , "in" , "out" , "reset" , "out" ] as const ) {
760+ yield * desktopWindow . zoomMain ( direction ) ;
761+ const position = fakeWindow . setWindowButtonPosition . mock . lastCall ?. [ 0 ] ;
762+ assert . isDefined ( position ) ;
763+ // The 14-point native buttons should share the zoomed 52px header's center.
764+ const headerCenter = 26 * fakeWindow . window . webContents . getZoomFactor ( ) ;
765+ assert . isAtMost ( Math . abs ( position . y + 7 - headerCenter ) , 0.5 ) ;
766+ assert . equal ( position . x , 16 ) ;
767+ }
768+
769+ fakeWindow . isFullScreen . mockReturnValue ( true ) ;
770+ fakeWindow . setWindowButtonPosition . mockClear ( ) ;
771+ yield * desktopWindow . zoomMain ( "reset" ) ;
772+ assert . equal ( fakeWindow . setWindowButtonPosition . mock . calls . length , 0 ) ;
773+
774+ fakeWindow . isFullScreen . mockReturnValue ( false ) ;
775+ fakeWindow . windowListeners . get ( "leave-full-screen" ) ?.( ) ;
776+ assert . deepEqual ( fakeWindow . setWindowButtonPosition . mock . lastCall , [ { x : 16 , y : 19 } ] ) ;
777+ } ) . pipe ( Effect . provide ( layer ) ) ;
778+ } ) ,
779+ ) ;
780+
745781 it . effect ( "uses the persisted main window bounds when opening the window" , ( ) =>
746782 Effect . gen ( function * ( ) {
747783 const fakeWindow = makeFakeBrowserWindow ( ) ;
0 commit comments