Merge pull request #167 from TARO-gh/fix/floating-toolbar-drag-drift

fix(windows): stabilize HUD drag by locking bounds size during move
This commit is contained in:
webadderall
2026-04-04 16:12:45 +11:00
committed by GitHub
2 changed files with 30 additions and 3 deletions
+23 -3
View File
@@ -244,6 +244,8 @@ ipcMain.on("hud-overlay-set-ignore-mouse", (_event, ignore: boolean) => {
});
let hudDragOffset: { x: number; y: number } | null = null;
let hudDragLastCursor: { x: number; y: number } | null = null;
let hudDragFixedSize: { width: number; height: number } | null = null;
ipcMain.on("hud-overlay-drag", (_event, phase: string, screenX: number, screenY: number) => {
if (!hudOverlayWindow || hudOverlayWindow.isDestroyed()) return;
@@ -251,13 +253,31 @@ ipcMain.on("hud-overlay-drag", (_event, phase: string, screenX: number, screenY:
if (phase === "start") {
const bounds = hudOverlayWindow.getBounds();
hudDragOffset = { x: screenX - bounds.x, y: screenY - bounds.y };
hudDragLastCursor = { x: screenX, y: screenY };
hudDragFixedSize = { width: bounds.width, height: bounds.height };
} else if (phase === "move" && hudDragOffset) {
hudOverlayWindow.setPosition(
Math.round(screenX - hudDragOffset.x),
Math.round(screenY - hudDragOffset.y),
if (hudDragLastCursor && hudDragLastCursor.x === screenX && hudDragLastCursor.y === screenY) {
return;
}
hudDragLastCursor = { x: screenX, y: screenY };
const targetX = Math.round(screenX - hudDragOffset.x);
const targetY = Math.round(screenY - hudDragOffset.y);
const fixedWidth = hudDragFixedSize?.width ?? hudOverlayWindow.getBounds().width;
const fixedHeight = hudDragFixedSize?.height ?? hudOverlayWindow.getBounds().height;
hudOverlayWindow.setBounds(
{
x: targetX,
y: targetY,
width: fixedWidth,
height: fixedHeight,
},
false,
);
} else if (phase === "end") {
hudDragOffset = null;
hudDragLastCursor = null;
hudDragFixedSize = null;
}
});
+7
View File
@@ -1178,7 +1178,14 @@ export function LaunchWindow() {
e.preventDefault();
isDraggingRef.current = true;
window.electronAPI?.hudOverlayDrag?.("start", e.screenX, e.screenY);
let lastScreenX = e.screenX;
let lastScreenY = e.screenY;
const handleMove = (ev: MouseEvent) => {
if (ev.screenX === lastScreenX && ev.screenY === lastScreenY) {
return;
}
lastScreenX = ev.screenX;
lastScreenY = ev.screenY;
window.electronAPI?.hudOverlayDrag?.("move", ev.screenX, ev.screenY);
};
const handleUp = () => {