Repository: fyne-io/fyne
File: internal/driver/glfw/window_desktop.go (Go)

Code before:
	}
	if w.fixedSize {
		if w.shouldWidth > w.requestedWidth {
			w.requestedWidth = w.shouldWidth
		}
		if w.shouldHeight > w.requestedHeight {
			w.requestedHeight = w.shouldHeight
		}
		view.SetSizeLimits(w.requestedWidth, w.requestedHeight, w.requestedWidth, w.requestedHeight)
	} else {
		view.SetSizeLimits(minWidth, minHeight, glfw.DontCare, glfw.DontCare)
	}
}

// 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) (int, int) {
	videoMode := monitor.GetVideoMode()
	scale := getMonitorScale(monitor)

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

func (w *window) getMonitorForWindow() *glfw.Monitor {
	if !build.IsWayland {
		x, y := w.xpos, w.ypos
		if w.fullScreen {
			x, y = w.viewport.GetPos()
		}
		xOff := x + (w.width / 2)
		yOff := y + (w.height / 2)

		for _, monitor := range glfw.GetMonitors() {
			x, y := monitor.GetPos()

			if x > xOff || y > yOff {
				continue
			}

			scaledWidth, scaledHeight := getScaledMonitorSize(monitor)

Review comment (suggestion):
Thanks this is cleaner now, but I do think that the return from this should be `fyne.Size` because (if I understand it correctly) that is the coordinate system being used for the return.

Code after:
	}
	if w.fixedSize {
		if w.shouldWidth > w.requestedWidth {
			w.requestedWidth = w.shouldWidth
		}
		if w.shouldHeight > w.requestedHeight {
			w.requestedHeight = w.shouldHeight
		}
		view.SetSizeLimits(w.requestedWidth, w.requestedHeight, w.requestedWidth, w.requestedHeight)
	} else {
		view.SetSizeLimits(minWidth, minHeight, glfw.DontCare, glfw.DontCare)
	}
}

// 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
		if w.fullScreen {
			x, y = w.viewport.GetPos()
		}
		xOff := x + (w.width / 2)
		yOff := y + (w.height / 2)

		for _, monitor := range glfw.GetMonitors() {
			x, y := monitor.GetPos()

			if x > xOff || y > yOff {
				continue
			}

			scaledSize := getScaledMonitorSize(monitor)