Files
secure-editor-go/screen_darwin.go
T

33 lines
929 B
Go

//go:build darwin
package main
import (
"os/exec"
"strconv"
"strings"
)
// desktopSize returns the visible desktop size in points (device-independent
// pixels), matching Fyne's coordinate system. It uses osascript instead of
// cgo so the binary stays a plain Go build. Returns (0, 0) if it can't be
// determined, in which case the caller skips clamping.
func desktopSize() (float32, float32) {
// "bounds of window of desktop" -> "0, 0, W, H" in points.
out, err := exec.Command("osascript", "-e",
`tell application "Finder" to get bounds of window of desktop`).Output()
if err != nil {
return 0, 0
}
parts := strings.Split(strings.TrimSpace(string(out)), ", ")
if len(parts) < 4 {
return 0, 0
}
w, errW := strconv.ParseFloat(strings.TrimSpace(parts[2]), 32)
h, errH := strconv.ParseFloat(strings.TrimSpace(parts[3]), 32)
if errW != nil || errH != nil {
return 0, 0
}
return float32(w), float32(h)
}