feat(app): implement basic function
General - 配置界面支持配置对象存储桶 - 快捷键进入截图 - 一键上传截图 & 复制截图链接 MacOS - 状态栏指示器和应用图标
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
// Package display exposes platform-specific helpers for reading the
|
||||
// geometry of the primary display, in both CSS (logical) and PHYSICAL
|
||||
// pixels. The overlay flow needs both: CSS pixels to size the Wails window
|
||||
// to "fullscreen" (since Wails uses CSS-px-equivalent units), and the
|
||||
// backing scale factor to translate the user's CSS-px selection rectangle
|
||||
// into the physical-pixel rectangle of the captured PNG.
|
||||
package display
|
||||
|
||||
// Info describes the primary display.
|
||||
//
|
||||
// The struct is deliberately minimal: only the few fields the overlay flow
|
||||
// actually needs. We can grow it later without affecting callers because
|
||||
// it is returned by value.
|
||||
type Info struct {
|
||||
// CSSWidth / CSSHeight are the logical dimensions of the primary
|
||||
// display in points (i.e. what CSS / Wails uses).
|
||||
CSSWidth int
|
||||
CSSHeight int
|
||||
|
||||
// Scale is backing factor (CSS-px → device-px). 2 on Retina, 1 on
|
||||
// non-Retina. We model it as float64 to leave room for fractional
|
||||
// scales (e.g. Linux 1.25×) even though macOS effectively only ever
|
||||
// reports 1 or 2.
|
||||
Scale float64
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
//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,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
//go:build !darwin
|
||||
|
||||
package display
|
||||
|
||||
import "github.com/kbinani/screenshot"
|
||||
|
||||
// Primary returns the dimensions of display 0. We currently assume a 1× DPR
|
||||
// because Wails on Windows / Linux already paints in physical pixels, so
|
||||
// CSS coordinates and capture coordinates coincide. If a user ever runs at
|
||||
// non-1× we will add a platform-specific scale lookup.
|
||||
func Primary() Info {
|
||||
if screenshot.NumActiveDisplays() == 0 {
|
||||
return Info{CSSWidth: 1440, CSSHeight: 900, Scale: 1}
|
||||
}
|
||||
b := screenshot.GetDisplayBounds(0)
|
||||
return Info{
|
||||
CSSWidth: b.Dx(),
|
||||
CSSHeight: b.Dy(),
|
||||
Scale: 1,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user