Skip to content

Commit 62d4f91

Browse files
committed
[Winforms] Fix scaling
1 parent 007ee42 commit 62d4f91

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

webview/platforms/winforms.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,23 +143,27 @@ def __init__(self, window, cache_dir):
143143
self.Size = Size(window.initial_width, window.initial_height)
144144
self.MinimumSize = Size(window.min_size[0], window.min_size[1])
145145

146+
self.AutoScaleDimensions = SizeF(96.0, 96.0)
147+
self.AutoScaleMode = WinForms.AutoScaleMode.Dpi
148+
# for chromium edge, need this factor to modify the coordinates
149+
self.scale_factor = windll.shcore.GetScaleFactorForDevice(0) / 100 if is_chromium else 1
150+
146151
if window.initial_x is not None and window.initial_y is not None:
147152
self.StartPosition = WinForms.FormStartPosition.Manual
148153
self.Location = Point(window.initial_x, window.initial_y)
149154
elif window.screen:
150155
self.StartPosition = WinForms.FormStartPosition.Manual
151-
x = (
152-
window.screen.frame.X + (window.screen.width / 2) + window.initial_width / 2
153-
if window.screen.frame.X >= 0
154-
else window.screen.frame.X - window.screen.width / 2
156+
x = int(
157+
window.screen.frame.X * self.scale_factor + (window.screen.width - window.initial_width) * self.scale_factor / 2
158+
if window.screen.frame.X >= 0
159+
else window.screen.frame.X * self.scale_factor - window.screen.width * self.scale_factor / 2
155160
)
156-
self.Location = Point(int(x), int(window.screen.frame.Y + window.screen.height / 2))
161+
162+
y = int(window.screen.frame.Y * self.scale_factor + (window.screen.height - window.initial_height) * self.scale_factor / 2)
163+
self.Location = Point(x, y)
157164
else:
158165
self.StartPosition = WinForms.FormStartPosition.CenterScreen
159166

160-
self.AutoScaleDimensions = SizeF(96.0, 96.0)
161-
self.AutoScaleMode = WinForms.AutoScaleMode.Dpi
162-
163167
if not window.resizable:
164168
self.FormBorderStyle = WinForms.FormBorderStyle.FixedSingle
165169
self.MaximizeBox = False
@@ -186,7 +190,6 @@ def __init__(self, window, cache_dir):
186190
self.url = window.real_url
187191
self.text_select = window.text_select
188192
self.TopMost = window.on_top
189-
self.scale_factor = 1
190193

191194
self.is_fullscreen = False
192195
if window.fullscreen:
@@ -204,8 +207,6 @@ def __init__(self, window, cache_dir):
204207
CEF.create_browser(window, self.Handle.ToInt32(), BrowserView.alert, self)
205208
elif is_chromium:
206209
self.browser = Chromium.EdgeChrome(self, window, cache_dir)
207-
# for chromium edge, need this factor to modify the coordinates
208-
self.scale_factor = windll.shcore.GetScaleFactorForDevice(0) / 100
209210
else:
210211
self.browser = IE.MSHTML(self, window, BrowserView.alert)
211212

@@ -785,7 +786,7 @@ def get_size(uid):
785786

786787

787788
def get_screens():
788-
screens = [Screen(s.Bounds.Width, s.Bounds.Height, s.WorkingArea.Location) for s in WinForms.Screen.AllScreens]
789+
screens = [Screen(s.Bounds.Width, s.Bounds.Height, s.WorkingArea) for s in WinForms.Screen.AllScreens]
789790
return screens
790791

791792

0 commit comments

Comments
 (0)