Backend - Per-VM CPU affinity (vmstart/affinity.go, affinity_flow.go): modes auto / all / P-cores / non-LP-E / custom, saved in the VM folder, applied to the QEMU process on start (GUI and CLI) and live via SetVMAffinity; copied on clone. Start summary logs the resolved mapping. Host report gains CPU topology helpers (mask <-> CPU list). - Offline qcow2 restore points via qemu-img (driver/reims/snapshot.go, snapshot_flow.go): list / create / restore / delete. - SSH helpers (ssh_flow.go): remembered user, open a terminal, write an ~/.ssh/config entry, open VS Code Remote-SSH. - FocusVMWindow brings the QEMU window forward (restoring it if minimized); CopyVMScreenshot copies a full-resolution frame to the clipboard. - DeliverPathsToGuest copies dropped host files into the shared folder; main.go enables Wails file drop on elements marked --wails-drop-target. - VM note (.reims-go-note) and a storage breakdown (extras_flow.go). Frontend - VM page: running state's "Show Window" and the screen preview use FocusVMWindow; camera button and More-menu item copy a screenshot; editable note under the name; SSH row shows the saved user with Terminal / config / VS Code actions; restore-point list; install guide steps can be ticked off; drop files onto the page to send them. - Sidebar right-click menu per VM (start, show window, screenshot, stop, restart, settings, folders, clone, delete); double-click and Ctrl+Enter still run the main action. - AffinityDialog opened from the VM menu and VM settings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
91 lines
2.4 KiB
Go
91 lines
2.4 KiB
Go
//go:build windows
|
|
|
|
package host
|
|
|
|
import (
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
var (
|
|
procEnumWindows = user32.NewProc("EnumWindows")
|
|
procIsWindowVisible = user32.NewProc("IsWindowVisible")
|
|
procIsIconic = user32.NewProc("IsIconic")
|
|
procShowWindow = user32.NewProc("ShowWindow")
|
|
procSetForegroundWin = user32.NewProc("SetForegroundWindow")
|
|
procBringWindowToTop = user32.NewProc("BringWindowToTop")
|
|
procAttachThreadInput = user32.NewProc("AttachThreadInput")
|
|
)
|
|
|
|
const swRestore = 9
|
|
|
|
// ForegroundPID returns the process that owns the foreground window, or 0
|
|
// when there is none (locked screen, desktop focused).
|
|
func ForegroundPID() uint32 {
|
|
hwnd, _, _ := procGetForegroundWindow.Call()
|
|
if hwnd == 0 {
|
|
return 0
|
|
}
|
|
var pid uint32
|
|
_, _, _ = procGetWindowThreadProcessId.Call(hwnd, uintptr(unsafe.Pointer(&pid)))
|
|
return pid
|
|
}
|
|
|
|
// FocusProcessWindow finds the primary visible top-level window belonging to
|
|
// pid, restores it if minimized, and brings it to the foreground.
|
|
func FocusProcessWindow(pid uint32) bool {
|
|
if pid == 0 {
|
|
return false
|
|
}
|
|
var found uintptr
|
|
cb := syscall.NewCallback(func(hwnd uintptr, _ uintptr) uintptr {
|
|
vis, _, _ := procIsWindowVisible.Call(hwnd)
|
|
if vis == 0 {
|
|
return 1
|
|
}
|
|
var winPID uint32
|
|
_, _, _ = procGetWindowThreadProcessId.Call(hwnd, uintptr(unsafe.Pointer(&winPID)))
|
|
if winPID == pid {
|
|
found = hwnd
|
|
return 0
|
|
}
|
|
return 1
|
|
})
|
|
_, _, _ = procEnumWindows.Call(cb, 0)
|
|
if found == 0 {
|
|
return false
|
|
}
|
|
iconic, _, _ := procIsIconic.Call(found)
|
|
if iconic != 0 {
|
|
_, _, _ = procShowWindow.Call(found, swRestore)
|
|
}
|
|
fgHwnd, _, _ := procGetForegroundWindow.Call()
|
|
curTid, _, _ := procGetCurrentThreadId.Call()
|
|
var fgTid uintptr
|
|
if fgHwnd != 0 {
|
|
fgTid, _, _ = procGetWindowThreadProcessId.Call(fgHwnd, 0)
|
|
}
|
|
targetTid, _, _ := procGetWindowThreadProcessId.Call(found, 0)
|
|
attachedFg := false
|
|
attachedTarget := false
|
|
if fgTid != 0 && fgTid != curTid {
|
|
if r, _, _ := procAttachThreadInput.Call(curTid, fgTid, 1); r != 0 {
|
|
attachedFg = true
|
|
}
|
|
}
|
|
if targetTid != 0 && targetTid != curTid && targetTid != fgTid {
|
|
if r, _, _ := procAttachThreadInput.Call(curTid, targetTid, 1); r != 0 {
|
|
attachedTarget = true
|
|
}
|
|
}
|
|
_, _, _ = procBringWindowToTop.Call(found)
|
|
_, _, _ = procSetForegroundWin.Call(found)
|
|
if attachedTarget {
|
|
_, _, _ = procAttachThreadInput.Call(curTid, targetTid, 0)
|
|
}
|
|
if attachedFg {
|
|
_, _, _ = procAttachThreadInput.Call(curTid, fgTid, 0)
|
|
}
|
|
return true
|
|
}
|