-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitors.go
More file actions
64 lines (54 loc) · 1.38 KB
/
monitors.go
File metadata and controls
64 lines (54 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"log"
"github.com/go-gl/glfw/v3.3/glfw"
)
// MonitorInfo holds position and size information for a monitor
type MonitorInfo struct {
Name string
X int
Y int
Width int
Height int
}
// detectMonitors queries GLFW for all connected monitors
// Returns empty slice if detection fails (graceful degradation)
func detectMonitors() []MonitorInfo {
// Initialize GLFW if not already done
err := glfw.Init()
if err != nil {
log.Printf("GLFW init failed: %v (falling back to single-monitor mode)", err)
return []MonitorInfo{}
}
// Get all monitors
monitors := glfw.GetMonitors()
if len(monitors) == 0 {
log.Println("No monitors detected (falling back to single-monitor mode)")
return []MonitorInfo{}
}
// Extract monitor information
result := make([]MonitorInfo, 0, len(monitors))
for i, mon := range monitors {
if mon == nil {
log.Printf("Monitor %d is nil, skipping", i)
continue
}
// Get monitor position and video mode
x, y := mon.GetPos()
mode := mon.GetVideoMode()
if mode == nil {
log.Printf("Monitor %d has no video mode, skipping", i)
continue
}
name := mon.GetName()
result = append(result, MonitorInfo{
Name: name,
X: x,
Y: y,
Width: mode.Width,
Height: mode.Height,
})
log.Printf("Detected monitor: %s (%dx%d at %d,%d)", name, mode.Width, mode.Height, x, y)
}
return result
}