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