| 1 |
//go:build windows && !go1.21 |
| 2 |
|
| 3 |
package screenshot |
| 4 |
|
| 5 |
import ( |
| 6 |
"image" |
| 7 |
"syscall" |
| 8 |
"unsafe" |
| 9 |
|
| 10 |
"github.com/lxn/win" |
| 11 |
) |
| 12 |
|
| 13 |
func NumActiveDisplays() int { |
| 14 |
var count int |
| 15 |
count = 0 |
| 16 |
ptr := unsafe.Pointer(&count) |
| 17 |
enumDisplayMonitors(win.HDC(0), nil, syscall.NewCallback(countupMonitorCallback), uintptr(ptr)) |
| 18 |
return count |
| 19 |
} |
| 20 |
|
| 21 |
func GetDisplayBounds(displayIndex int) image.Rectangle { |
| 22 |
var ctx getMonitorBoundsContext |
| 23 |
ctx.Index = displayIndex |
| 24 |
ctx.Count = 0 |
| 25 |
ptr := unsafe.Pointer(&ctx) |
| 26 |
enumDisplayMonitors(win.HDC(0), nil, syscall.NewCallback(getMonitorBoundsCallback), uintptr(ptr)) |
| 27 |
return image.Rect( |
| 28 |
int(ctx.Rect.Left), int(ctx.Rect.Top), |
| 29 |
int(ctx.Rect.Right), int(ctx.Rect.Bottom)) |
| 30 |
} |