Skip to content

All your computers and your phone/iPhone, working as one desk. Screens, apps, files, clipboard, calls, texts, notifications, mouse and keyboard, shared between Mac, Windows, Linux , Android, Web and ios / ipados . Free and open source. No account, no cloud, and no shared network needed.

3.2 KB
Raw Blame
// TwinDesk — Copyright (C) 2026 inukaasith. GPL-3.0, see LICENSE.
// edgeflash.html: as Windows' Flash.cs, a soft accent glow along the crossing edge (fades in 0.14 s,
// out by 0.7 s) and a ring at the pointer that closes in when leaving (0.4 s) and spreads out when
// arriving (0.55 s). window.play({px, py, side, leaving, color}) from edgeflash.js.
'use strict';

(() => {
  const c = document.getElementById('c');
  const g = c.getContext('2d');
  let raf = 0;
  const rgba = (hex, a) => {
    const n = parseInt(hex.slice(1), 16);
    return `rgba(${(n >> 16) & 255}, ${(n >> 8) & 255}, ${n & 255}, ${Math.max(0, Math.min(1, a)).toFixed(3)})`;
  };
  const ease = (t) => 1 - Math.pow(1 - t, 3);

  window.play = (o) => {
    const W = window.innerWidth;
    const H = window.innerHeight;
    const dpr = window.devicePixelRatio || 1;
    c.width = W * dpr; c.height = H * dpr; c.style.width = W + 'px'; c.style.height = H + 'px';
    g.setTransform(dpr, 0, 0, dpr, 0, 0);
    cancelAnimationFrame(raf);
    const start = performance.now();
    const ringMs = o.leaving ? 400 : 550;
    const frame = (now) => {
      const ms = now - start;
      g.clearRect(0, 0, W, H);
      // The glow: a band along the side, strongest at the edge and at the pointer.
      if (o.side) {
        const a = ms < 140 ? ms / 140 : Math.max(0, 1 - (ms - 140) / 560);
        const depth = 46;
        const along = o.side === 'left' || o.side === 'right' ? o.py : o.px;
        const lin = o.side === 'left' ? g.createLinearGradient(0, 0, depth, 0)
          : o.side === 'right' ? g.createLinearGradient(W, 0, W - depth, 0)
            : o.side === 'top' ? g.createLinearGradient(0, 0, 0, depth) : g.createLinearGradient(0, H, 0, H - depth);
        lin.addColorStop(0, rgba(o.color, 0.55 * a));
        lin.addColorStop(1, rgba(o.color, 0));
        g.save();
        // Faded towards the ends of the band (about 360 px long around the pointer).
        const mask = o.side === 'left' || o.side === 'right' ? g.createLinearGradient(0, along - 180, 0, along + 180) : g.createLinearGradient(along - 180, 0, along + 180, 0);
        mask.addColorStop(0, 'rgba(0,0,0,0)'); mask.addColorStop(0.5, 'rgba(0,0,0,1)'); mask.addColorStop(1, 'rgba(0,0,0,0)');
        g.fillStyle = lin;
        if (o.side === 'left') g.fillRect(0, along - 180, depth, 360);
        else if (o.side === 'right') g.fillRect(W - depth, along - 180, depth, 360);
        else if (o.side === 'top') g.fillRect(along - 180, 0, 360, depth);
        else g.fillRect(along - 180, H - depth, 360, depth);
        g.globalCompositeOperation = 'destination-in';
        g.fillStyle = mask;
        g.fillRect(0, 0, W, H);
        g.restore();
      }
      // The ring: closing in on the pointer when leaving, spreading from it when arriving.
      if (ms < ringMs) {
        const t = ease(ms / ringMs);
        const r = o.leaving ? 64 - 56 * t : 10 + 70 * t;
        g.beginPath();
        g.arc(o.px, o.py, r, 0, Math.PI * 2);
        g.lineWidth = 3;
        g.strokeStyle = rgba(o.color, (o.leaving ? 0.3 + 0.6 * t : 0.9 * (1 - t)));
        g.stroke();
      }
      if (ms < 720) raf = requestAnimationFrame(frame);
      else g.clearRect(0, 0, W, H);
    };
    raf = requestAnimationFrame(frame);
  };
})();