Files
hermes-agent/apps/desktop/electron/hud-drag.ts
T
Brooklyn Nicholson e60983a697 fix(desktop): let the HUD drag onto another monitor
Composer drag added renderer CSS-pixel deltas onto a window AppKit
clamps to the current display, so the bar could not follow the cursor
onto a second monitor (and drifted on mixed-DPI Windows). Track the OS
cursor in main and lift that clamp.

Co-authored-by: Biotrioo <biotrioo@protonmail.com>
2026-08-28 15:33:19 -05:00

38 lines
990 B
TypeScript

/**
* HUD composer-drag geometry — where to park the window so it stays under the
* OS cursor, including across monitors.
*
* Renderer PointerEvent screen coordinates are CSS pixels. Electron's
* `screen.getCursorScreenPoint()` and `BrowserWindow` bounds are DIP. An
* absolute grab offset sampled in main stays 1:1 across mixed-DPI displays,
* even if the last setBounds was clamped to the previous monitor.
*/
export interface HudDragPoint {
x: number
y: number
}
export function createHudDragSession() {
let offset: HudDragPoint | null = null
return {
begin(cursor: HudDragPoint, windowOrigin: HudDragPoint) {
offset = { x: cursor.x - windowOrigin.x, y: cursor.y - windowOrigin.y }
},
origin(cursor: HudDragPoint): HudDragPoint | null {
if (!offset) {
return null
}
return {
x: Math.round(cursor.x - offset.x),
y: Math.round(cursor.y - offset.y)
}
},
end() {
offset = null
}
}
}