visual window picker with marching ants overlay

This commit is contained in:
2026-05-12 02:22:02 +03:00
parent 2904a7ad29
commit 509017d56b
8 changed files with 364 additions and 140 deletions
+111
View File
@@ -0,0 +1,111 @@
<script lang="ts">
import { onMount } from "svelte"
import { listen } from "@tauri-apps/api/event"
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow"
type Rect = {
x: number
y: number
width: number
height: number
}
let hover: Rect | null = $state(null)
let scale: number = $state(1)
let originX: number = $state(0)
let originY: number = $state(0)
onMount(() => {
const win = getCurrentWebviewWindow()
let unlistenHover: (() => void) | null = null
void (async () => {
scale = await win.scaleFactor()
const pos = await win.outerPosition()
originX = pos.x
originY = pos.y
unlistenHover = await listen<Rect>("picker-hover", (e) => {
hover = e.payload
})
})()
return () => {
unlistenHover?.()
}
})
let style = $derived.by(() => {
if (!hover) return ""
const left = (hover.x - originX) / scale
const top = (hover.y - originY) / scale
const width = hover.width / scale
const height = hover.height / scale
return `left: ${left}px; top: ${top}px; width: ${width}px; height: ${height}px;`
})
</script>
<main>
<div class="dim"></div>
{#if hover}
<div class="frame" style={style}>
<div class="dims">{hover.width} x {hover.height}</div>
</div>
{/if}
<div class="hint">click a window to snap. Esc to cancel.</div>
</main>
<style>
:global(html), :global(body), :global(#picker) {
margin: 0;
padding: 0;
background: transparent;
height: 100vh;
width: 100vw;
overflow: hidden;
cursor: crosshair;
}
main {
position: relative;
width: 100vw;
height: 100vh;
}
.dim {
position: absolute;
inset: 0;
background: rgba(10, 14, 12, 0.18);
}
.frame {
position: absolute;
box-sizing: border-box;
border: 2px dashed #4a8;
background: rgba(74, 170, 136, 0.08);
animation: march 0.6s linear infinite;
pointer-events: none;
}
@keyframes march {
to { background-position: 16px 0; }
}
.dims {
position: absolute;
top: -22px;
left: 0;
padding: 1px 6px;
background: #4a8;
color: #0e1a16;
font: 11px ui-monospace, monospace;
border-radius: 3px;
}
.hint {
position: absolute;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
padding: 6px 14px;
background: rgba(0, 0, 0, 0.7);
color: #fff;
border-radius: 999px;
font: 13px ui-monospace, monospace;
pointer-events: none;
}
</style>