Closed mdpe-ir closed 2 years ago
Very likely related to https://github.com/go-flutter-desktop/go-flutter/pull/458, @pchampio.
Very likely related to #458
I also changed my DPI Scaling but doesn't fix it.
package main
import (
"runtime"
"fmt"
"github.com/go-gl/glfw/v3.3/glfw"
)
// dpPerInch defines the amount of display pixels per inch as defined for Flutter.
const dpPerInch = 160.0
func getPixelRatioLinux(window *glfw.Window) float64 {
widthPx, heightPx := window.GetFramebufferSize()
var selectedMonitor *glfw.Monitor
winX, winY := window.GetPos()
winCenterX, winCenterY := winX+widthPx/2, winY+heightPx/2
monitors := glfw.GetMonitors()
for _, monitor := range monitors {
monX1, monY1 := monitor.GetPos()
monMode := monitor.GetVideoMode()
if monMode == nil {
continue
}
monX2, monY2 := monX1+monMode.Width, monY1+monMode.Height
if (monX1 <= winCenterX && winCenterX <= monX2) &&
(monY1 <= winCenterY && winCenterY <= monY2) {
selectedMonitor = monitor
break
}
}
if selectedMonitor == nil {
// when no monitor was selected, try fallback to primary monitor
// TODO: ? perhaps select monitor that is "closest" to the window ?
selectedMonitor = glfw.GetPrimaryMonitor()
}
if selectedMonitor == nil {
fmt.Printf("selectedMonitor == nil")
return getPixelRatioOther(window)
}
selectedMonitorMode := selectedMonitor.GetVideoMode()
if selectedMonitorMode == nil {
fmt.Printf("selectedMonitorMode == nil")
return getPixelRatioOther(window)
}
selectedMonitorWidthMM, _ := selectedMonitor.GetPhysicalSize()
if selectedMonitorWidthMM == 0 {
fmt.Printf("selectedMonitorWidthMM == 0")
return getPixelRatioOther(window)
}
monitorScreenCoordinatesPerInch := float64(selectedMonitorMode.Width) / (float64(selectedMonitorWidthMM) / 25.4)
/// from another function
widthPx, heightPx = window.GetFramebufferSize()
width, _ := window.GetSize()
if width == 0 {
panic("go-flutter: Cannot calculate pixelsPerScreenCoordinate for zero-width window.")
}
pixelsPerScreenCoordinate := float64(widthPx) / float64(width)
/// end
dpi := pixelsPerScreenCoordinate * monitorScreenCoordinatesPerInch
pixelRatio := dpi / dpPerInch
// If the pixelRatio is lower than 1 use this pixelRatio factor to downscale the ContentScale
fmt.Printf("\npixel ration : %v", pixelRatio)
if pixelRatio < 1.0 {
pixelRatio *= getPixelRatioOther(window)
if pixelRatio < 1.0 {
fmt.Printf("\npixel ration lower than 1 after rescaling : %v", pixelRatio)
}
}
return pixelRatio
}
func getPixelRatioOther(window *glfw.Window) float64 {
xscale, _ := window.GetContentScale()
return float64(xscale)
}
func init() {
// This is needed to arrange that main() runs on main thread.
// See documentation for functions that are only allowed to be called from the main thread.
runtime.LockOSThread()
}
func main() {
err := glfw.Init()
if err != nil {
panic(err)
}
defer glfw.Terminate()
window, err := glfw.CreateWindow(640, 480, "Testing", nil, nil)
if err != nil {
panic(err)
}
window.MakeContextCurrent()
window.SetPosCallback(func(window *glfw.Window, xpos int, ypos int) {
xscale := getPixelRatioOther(window)
xscaleLinux := getPixelRatioLinux(window)
fmt.Printf("\n%v content scale other.\n", xscale)
fmt.Printf("%v content scale linux.\n", xscaleLinux)
})
for !window.ShouldClose() {
// Do OpenGL stuff.
window.SwapBuffers()
glfw.PollEvents()
}
}
Can you try to run this code (go run main.go
), It should help me understand where this down-scaling issue comes.
pixel ration : 0.5289085365853659
pixel ration lower than 1 after rescaling : 0.5289085365853659
1 content scale other.
0.5289085365853659 content scale linux.
@pchampio
Awesome, I know how to fix this ;)
fixed in v0.52.1
fixed in
v0.52.1
The problem is completely solved. 💯 thank you ❤️
Hover doctor
Error output
The last time I used this project was about 2 months ago and everything was working fine. But now the rendering is not done properly and the screen scale is very small.
Neofetch