gui/pkg/screen/platform.go
Claude a9b795f223
Some checks failed
Security Scan / security (push) Failing after 29s
Test / test (push) Successful in 2m9s
feat: Wails v3 stub bridge + feature expansion + display bridge + MCP events
Stubs (15 files, 479 exports):
- All managers: Dialog, Event, Browser, Clipboard, ContextMenu, Environment, Screen, KeyBinding
- Window interface (~50 methods), BrowserWindow, platform options (iOS/Android)
- MenuItem (42 roles), WebviewWindowOptions (full platform types)
- Wails v3 submodule pinned at alpha 74

New events package (17th package):
- Custom event system bridged to Core IPC
- TaskEmit, TaskOn, TaskOff, QueryListeners, ActionEventFired

Feature expansions:
- Window: zoom, content (SetURL/SetHTML/ExecJS), bounds, print, flash
- Screen: QueryCurrent, ScreenPlacement, Rect geometry
- Dialog: typed tasks, file options, Info/Question/Warning/Error
- Keybinding: TaskProcess, ErrorNotRegistered
- Notification: RevokePermission, RegisterCategory, action broadcasts
- Dock: SetProgressBar, Bounce/StopBounce
- Environment: HasFocusFollowsMouse
- ContextMenu: QueryGetAll, TaskUpdate, TaskDestroy

Display bridge: 5 new event types wired to WebSocket
MCP: 4 event tools (emit, on, off, list)

17 packages build and test clean (1 flaky test ordering issue in window).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-31 17:42:09 +01:00

87 lines
2.3 KiB
Go

// pkg/screen/platform.go
package screen
// Platform abstracts the screen/display backend.
type Platform interface {
GetAll() []Screen
GetPrimary() *Screen
GetCurrent() *Screen
}
// Screen describes a display/monitor.
type Screen struct {
ID string `json:"id"`
Name string `json:"name"`
ScaleFactor float64 `json:"scaleFactor"`
Size Size `json:"size"`
Bounds Rect `json:"bounds"`
WorkArea Rect `json:"workArea"`
IsPrimary bool `json:"isPrimary"`
Rotation float64 `json:"rotation"`
}
// Rect represents a rectangle with position and dimensions.
type Rect struct {
X int `json:"x"`
Y int `json:"y"`
Width int `json:"width"`
Height int `json:"height"`
}
// Contains reports whether the point (x, y) lies within the rectangle.
//
// if rect.Contains(mouseX, mouseY) { handleClick() }
func (r Rect) Contains(x, y int) bool {
return x >= r.X && x < r.X+r.Width && y >= r.Y && y < r.Y+r.Height
}
// Overlaps reports whether the rectangle r overlaps with other.
//
// if bounds.Overlaps(workArea) { show() }
func (r Rect) Overlaps(other Rect) bool {
return r.X < other.X+other.Width &&
r.X+r.Width > other.X &&
r.Y < other.Y+other.Height &&
r.Y+r.Height > other.Y
}
// Center returns the centre point of the rectangle.
//
// cx, cy := rect.Center()
func (r Rect) Center() (x, y int) {
return r.X + r.Width/2, r.Y + r.Height/2
}
// Size represents dimensions.
type Size struct {
Width int `json:"width"`
Height int `json:"height"`
}
// ScreenPlacement describes a desired window position relative to a screen.
//
// p := screen.ScreenPlacement{ScreenID: "1", X: 100, Y: 200, Width: 800, Height: 600}
// p.Apply(platformWindow)
type ScreenPlacement struct {
ScreenID string `json:"screenId"`
X int `json:"x"`
Y int `json:"y"`
Width int `json:"width"`
Height int `json:"height"`
}
// Placer is implemented by platform windows that can be repositioned.
type Placer interface {
SetPosition(x, y int)
SetSize(width, height int)
}
// Apply positions and sizes the given Placer according to the placement.
//
// placement.Apply(pw)
func (p ScreenPlacement) Apply(target Placer) {
if p.Width > 0 && p.Height > 0 {
target.SetSize(p.Width, p.Height)
}
target.SetPosition(p.X, p.Y)
}