Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions internal/driver/glfw/window_desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,26 @@ func (w *window) fitContent() {
}
}

// getMonitorScale returns the scale factor for a given monitor, handling platform-specific cases
func getMonitorScale(monitor *glfw.Monitor) float32 {
widthMm, heightMm := monitor.GetPhysicalSize()
if runtime.GOOS == "linux" && widthMm == 60 && heightMm == 60 { // Steam Deck incorrectly reports 6cm square!
return 1.0
}
widthPx := monitor.GetVideoMode().Width
return calculateDetectedScale(widthMm, widthPx)
}

// getScaledMonitorSize returns the monitor dimensions adjusted for scaling
func getScaledMonitorSize(monitor *glfw.Monitor) fyne.Size {
videoMode := monitor.GetVideoMode()
scale := getMonitorScale(monitor)

scaledWidth := float32(videoMode.Width) / scale
scaledHeight := float32(videoMode.Height) / scale
return fyne.NewSize(scaledWidth, scaledHeight)
}

func (w *window) getMonitorForWindow() *glfw.Monitor {
if !build.IsWayland {
x, y := w.xpos, w.ypos
Expand All @@ -276,7 +296,9 @@ func (w *window) getMonitorForWindow() *glfw.Monitor {
if x > xOff || y > yOff {
continue
}
if videoMode := monitor.GetVideoMode(); x+videoMode.Width <= xOff || y+videoMode.Height <= yOff {

scaledSize := getScaledMonitorSize(monitor)
if x+int(scaledSize.Width) <= xOff || y+int(scaledSize.Height) <= yOff {
continue
}

Expand Down Expand Up @@ -309,13 +331,7 @@ func (w *window) detectScale() float32 {
return 1
}

widthMm, heightMm := monitor.GetPhysicalSize()
if runtime.GOOS == "linux" && widthMm == 60 && heightMm == 60 { // Steam Deck incorrectly reports 6cm square!
return 1
}
widthPx := monitor.GetVideoMode().Width

return calculateDetectedScale(widthMm, widthPx)
return getMonitorScale(monitor)
}

func (w *window) moved(_ *glfw.Window, x, y int) {
Expand Down
Loading