Backend Architecture
The Rust backend operates within Tauri 2 and executes OS-level operations that the WebView environment cannot perform. This includes multi-window orchestration, high-frequency cursor polling, hardware-accelerated screen pixel capture, monitor hot-plug detection, and global shortcut registration.
Directory Structure (src-tauri/src/)
src-tauri/src/
├── main.rs # Minimal entry point (delegates to lib::run)
├── lib.rs # Core initialization, plugin registration, and background daemon loops
├── commands.rs # IPC bridge: Tauri commands exposed to Vue
├── window.rs # Window state machine, creation, and OS-level styling/positioning
├── monitor.rs # Multi-monitor topology detection and change diffing
├── cursor.rs # Cursor position utilities and global mouse hooks
├── zoom.rs # Orchestrator for screen capture (specifically DXGI streaming logic)
├── dxgi_capture.rs # Low-level Windows DXGI Desktop Duplication API implementation
├── magnifier.rs # Low-level Windows Magnification API implementation
└── types.rs # Shared struct/enum definitions (strictly typed for IPC boundaries)Core Modules
lib.rs & Background Daemons
The run function bootstraps the entire backend:
- Plugin Initialization: Sets up
plugin-store,global-shortcut,autostart, andopener. - Daemons (Tokio Async Loops):
- Cursor Poller: Reads the OS cursor position at ~60Hz (
GetCursorPos) and emits"cursor-position"to the Vue overlay windows. - Monitor Poller: Checks the monitor topology every 2 seconds. If a display is connected/disconnected, it recalculates the
window_registryand dynamically rebuilds overlay windows to span the new screen area.
- Cursor Poller: Reads the OS cursor position at ~60Hz (
- Tray Menu: Configures the system tray icon, localized context menu, and click handlers.
- Dynamic Engine Config: Loads the active Zoom backend preference (
dxgivsmagnifier) generated by the frontend.
commands.rs — The IPC Bridge
Exposes Rust functions to Vue via invoke(). Key integrations include:
- Visibility Toggles:
set_overlay_visible,open_whiteboard_modeetc. - Engine Toggles: Operations like
freeze_zoom,mag_zoom_show,set_zoom_capture_excludedwhich route to the active capture engine. - Context Queries: Resolving coordinates via
get_cursor_position_globalorget_active_monitor_context(to know which screen the user is interacting with).
window.rs — Deep OS Integration
Vynta handles windows differently than standard Tauri apps:
- Overlay Panels: Transparent, click-through (
WS_EX_TRANSPARENT) windows are created per monitor. - Native OS Hacks: For overlays to work seamlessly on Windows without glitching,
window.rsforcibly applies styles like WS_POPUP, strips shadows viaDwmSetWindowAttribute, and forces them to the top (HWND_TOPMOST). - Mode Windows: The Zoom, Spotlight, and Highlight windows are tiny transparent squares that are programmatically teleported to follow the cursor by the Vue frontend reacting to the backend's cursor IPC events.
The Screen Capture Engines (zoom.rs, dxgi_capture.rs, magnifier.rs)
Due to edge-cases in Windows screen recording, Vynta implements two separate zoom engines, dynamically switchable by the user:
DXGI Desktop Duplication (
dxgi_capture.rs):- Uses direct GPU access to capture the screen at high framerates.
- The stream loop in
zoom.rscaptures a region around the cursor, encodes it as a Base64 PNG in a background thread, and streams it to Vue via the"zoom-frame"event. - Pro: Highly performant, supports "Freeze Mode" easily.
- Con: Interacts poorly with some screen recording software (e.g., OBS) causing recursive trails.
Windows Magnification API (
magnifier.rs):- Uses the native OS magnifier lens.
- Rust directly creates a
WC_MAGNIFIERwindow that follows the cursor. Vue is bypassed entirely for the lens rendering. - Pro: Universally compatible with screen recorders (never recurses).
- Con: Lower customization, cannot be "frozen" in place, limited styling.
monitor.rs — Topology Tracking
- Computes virtual bounding boxes for all connected screens.
- Generates a "snapshot hash" to cheaply detect when cables are plugged/unplugged.
- Maintains the
window_registry, ensuring every monitor ID maps correctly to a distinct Tauri WebviewWindow label.
Plugin & Permissions
| Tauri Plugin | Role in Vynta |
|---|---|
plugin-store | Reads/writes .json preference files (like the selected Zoom Engine). |
plugin-global-shortcut | Binds OS hotkeys (e.g., Ctrl+Shift+D) to toggle drawing mode even when Vynta is minimized. |
plugin-opener | Opens URLs or the config directories natively. |
plugin-autostart | Modifies the Windows Registry/Startup folder. |
(Configured via tauri.conf.json and explicit capabilities in the src-tauri/capabilities/ folder).
