//go:build windows

package main

import "syscall"

// GetSystemMetrics indices for the virtual desktop — the rectangle spanning
// every attached monitor. Wails' ScreenGetAll reports each monitor's size but
// not its offset, so it cannot answer "is this coordinate on any screen?"; the
// Win32 metrics can.
const (
	smXVirtualScreen  = 76
	smYVirtualScreen  = 77
	smCXVirtualScreen = 78
	smCYVirtualScreen = 79
)

var (
	user32Dll            = syscall.NewLazyDLL("user32.dll")
	procGetSystemMetrics = user32Dll.NewProc("GetSystemMetrics")
)

func systemMetric(index int) int {
	r, _, _ := procGetSystemMetrics.Call(uintptr(index))
	return int(int32(r)) // signed: the virtual desktop origin is negative with a monitor to the left
}

// virtualScreenBounds returns the rectangle covering all monitors, and whether
// it could be determined at all.
func virtualScreenBounds() (x, y, w, h int, ok bool) {
	w, h = systemMetric(smCXVirtualScreen), systemMetric(smCYVirtualScreen)
	if w <= 0 || h <= 0 {
		return 0, 0, 0, 0, false
	}
	return systemMetric(smXVirtualScreen), systemMetric(smYVirtualScreen), w, h, true
}
