Skip to content

Commit 7e790e2

Browse files
committed
WinUIBackend: Fix window sizing (default size and getting size didn't account for scale)
1 parent 4e21dfd commit 7e790e2

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

Sources/WinUIBackend/WinUIBackend.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,19 @@ public final class WinUIBackend: AppBackend {
159159
// print(GetDpiForWindow(nil))
160160

161161
if let size {
162-
try! window.appWindow.resizeClient(
163-
SizeInt32(
164-
width: Int32(size.x),
165-
height: Int32(size.y)
166-
)
167-
)
162+
setSize(ofWindow: window, to: size)
168163
}
169164
return window
170165
}
171166

172167
public func size(ofWindow window: Window) -> SIMD2<Int> {
173168
let size = window.appWindow.clientSize
169+
let scaleFactor = window.scaleFactor
170+
let width = Double(size.width) / scaleFactor
171+
let height = Double(size.height) / scaleFactor
174172
let out = SIMD2(
175-
Int(size.width),
176-
Int(size.height) - CustomWindow.menuBarHeight
173+
Int(width.rounded(.towardZero)),
174+
Int(height.rounded(.towardZero)) - CustomWindow.menuBarHeight
177175
)
178176
return out
179177
}

0 commit comments

Comments
 (0)