Files
mamamiyear ceecbb6af4 feat(app): implement basic function
General
- 配置界面支持配置对象存储桶
- 快捷键进入截图
- 一键上传截图 & 复制截图链接

MacOS
- 状态栏指示器和应用图标
2026-06-01 21:17:29 +08:00

42 lines
1.3 KiB
Go

//go:build darwin
package display
/*
#cgo LDFLAGS: -framework CoreGraphics -framework Foundation
#include <CoreGraphics/CoreGraphics.h>
// readPrimaryDisplay fills the four out-params with:
// - cssW / cssH : logical (point) dimensions of the main display
// - pxW / pxH : physical (device-pixel) dimensions
// Using CGDisplayBounds for points and CGDisplayPixelsWide/High for pixels
// is the canonical way to derive the backing scale on macOS without
// bringing AppKit into the build (we do not want to link Cocoa here).
static void readPrimaryDisplay(int* cssW, int* cssH, int* pxW, int* pxH) {
CGDirectDisplayID id = CGMainDisplayID();
CGRect bounds = CGDisplayBounds(id);
*cssW = (int)bounds.size.width;
*cssH = (int)bounds.size.height;
*pxW = (int)CGDisplayPixelsWide(id);
*pxH = (int)CGDisplayPixelsHigh(id);
}
*/
import "C"
// Primary returns the geometry of the main display. The CGo call has no
// failure path — the OS always reports a main display whenever there is at
// least one attached, which is implied for any GUI process.
func Primary() Info {
var cssW, cssH, pxW, pxH C.int
C.readPrimaryDisplay(&cssW, &cssH, &pxW, &pxH)
scale := 1.0
if cssW > 0 {
scale = float64(pxW) / float64(cssW)
}
return Info{
CSSWidth: int(cssW),
CSSHeight: int(cssH),
Scale: scale,
}
}