1
1
package flutter
2
2
3
3
import (
4
- "encoding/json"
5
4
"fmt"
6
- "sync"
7
5
"unsafe"
8
6
9
7
"github.com/go-flutter-desktop/go-flutter/embedder"
@@ -21,9 +19,6 @@ type windowManager struct {
21
19
// forcedPixelRatio forces the pixelRatio to given value, when value is not zero.
22
20
forcedPixelRatio float64
23
21
24
- // sync.Once to limit pixelRatio warning messages.
25
- oncePrintPixelRatioLimit sync.Once
26
-
27
22
// current pointer state
28
23
pointerPhase embedder.PointerPhase
29
24
pointerButton embedder.PointerButtonMouse
@@ -207,70 +202,10 @@ func (m *windowManager) glfwRefreshCallback(window *glfw.Window) {
207
202
if m .forcedPixelRatio != 0 {
208
203
pixelRatio = m .forcedPixelRatio
209
204
} else {
210
- var selectedMonitor * glfw.Monitor
211
- winX , winY := window .GetPos ()
212
- winCenterX , winCenterY := winX + widthPx / 2 , winY + heightPx / 2
213
-
214
- monitors := glfw .GetMonitors ()
215
- for _ , monitor := range monitors {
216
- monX1 , monY1 := monitor .GetPos ()
217
- monMode := monitor .GetVideoMode ()
218
- if monMode == nil {
219
- continue
220
- }
221
- monX2 , monY2 := monX1 + monMode .Width , monY1 + monMode .Height
222
- if (monX1 <= winCenterX && winCenterX <= monX2 ) &&
223
- (monY1 <= winCenterY && winCenterY <= monY2 ) {
224
- selectedMonitor = monitor
225
- break
226
- }
227
- }
228
-
229
- if selectedMonitor == nil {
230
- // when no monitor was selected, try fallback to primary monitor
231
- // TODO: ? perhaps select monitor that is "closest" to the window ?
232
- selectedMonitor = glfw .GetPrimaryMonitor ()
233
- }
234
- if selectedMonitor == nil {
235
- pixelRatio = 1.0
236
- goto SendWindowMetricsEvent
237
- }
238
- selectedMonitorMode := selectedMonitor .GetVideoMode ()
239
- if selectedMonitorMode == nil {
240
- pixelRatio = 1.0
241
- goto SendWindowMetricsEvent
242
- }
243
- selectedMonitorWidthMM , _ := selectedMonitor .GetPhysicalSize ()
244
- if selectedMonitorWidthMM == 0 {
245
- pixelRatio = 1.0
246
- goto SendWindowMetricsEvent
247
- }
248
- monitorScreenCoordinatesPerInch := float64 (selectedMonitorMode .Width ) / (float64 (selectedMonitorWidthMM ) / 25.4 )
249
-
250
- dpi := m .pixelsPerScreenCoordinate * monitorScreenCoordinatesPerInch
251
- pixelRatio = dpi / dpPerInch
252
-
253
- // Limit the ratio to 1 to avoid rendering a smaller UI in standard resolution monitors.
254
- if pixelRatio < 1.0 {
255
- m .oncePrintPixelRatioLimit .Do (func () {
256
- metrics := map [string ]interface {}{
257
- "ppsc" : m .pixelsPerScreenCoordinate ,
258
- "windowWidthPx" : widthPx ,
259
- "windowWidthSc" : width ,
260
- "mscpi" : monitorScreenCoordinatesPerInch ,
261
- "dpi" : dpi ,
262
- "pixelRatio" : pixelRatio ,
263
- "monitorWidthMm" : selectedMonitorWidthMM ,
264
- "monitorWidthSc" : selectedMonitorMode .Width ,
265
- }
266
- metricsBytes , _ := json .Marshal (metrics )
267
- fmt .Println ("go-flutter: calculated pixelRatio limited to a minimum of 1.0. metrics: " + string (metricsBytes ))
268
- })
269
- pixelRatio = 1.0
270
- }
205
+ xscale , _ := window .GetContentScale ()
206
+ pixelRatio = float64 (xscale )
271
207
}
272
208
273
- SendWindowMetricsEvent:
274
209
event := embedder.WindowMetricsEvent {
275
210
Width : widthPx ,
276
211
Height : heightPx ,
0 commit comments