Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
"core:window:allow-set-ignore-cursor-events",
"core:window:allow-set-position",
"core:window:allow-set-size",
"core:window:allow-set-always-on-top",
"core:window:allow-current-monitor",
"core:window:allow-show",
"core:window:allow-hide",
"global-shortcut:allow-register",
"global-shortcut:allow-unregister",
"global-shortcut:allow-is-registered"
Expand Down
63 changes: 41 additions & 22 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use tauri::{
tray::TrayIconBuilder,
Emitter, Manager,
};
// global shortcut disabled during dev
use tauri_plugin_global_shortcut::{GlobalShortcutExt, Shortcut, ShortcutState};

// ---------------------------------------------------------------------------
// Data structures
Expand Down Expand Up @@ -64,10 +64,10 @@ fn apply_click_through(app: &tauri::AppHandle, ignore: bool) {
}
}

/// Show the overlay window and capture mouse events.
/// Show the overlay window, cover the screen, and capture mouse events.
fn show_overlay(app: &tauri::AppHandle) {
if let Some(window) = app.get_webview_window("overlay") {
// Force window to cover the primary screen (fixes maximized/center conflict on macOS)
// Force window to cover the primary screen
if let Ok(Some(monitor)) = window.current_monitor() {
let size = monitor.size();
let pos = monitor.position();
Expand All @@ -76,18 +76,25 @@ fn show_overlay(app: &tauri::AppHandle) {
}
let _ = window.show();
let _ = window.set_focus();
// Re-assert always-on-top so the overlay sits above every app
let _ = window.set_always_on_top(true);
let r = window.set_ignore_cursor_events(false);
println!(
"[DrawOver] show_overlay — focus+ignore_cursor result: {:?}",
r
);
let _ = window.set_ignore_cursor_events(false);
println!("[DrawOver] show_overlay — overlay visible + capturing");
} else {
eprintln!("[DrawOver] show_overlay — overlay window not found!");
}
}

/// Hide the overlay window so the user can interact with apps behind it.
/// Strokes are preserved — they'll reappear when draw mode is toggled back on.
fn hide_overlay(app: &tauri::AppHandle) {
if let Some(window) = app.get_webview_window("overlay") {
// Make click-through first so mouse events don't get swallowed
let _ = window.set_ignore_cursor_events(true);
let _ = window.hide();
println!("[DrawOver] hide_overlay — overlay hidden, strokes preserved");
}
}

// ---------------------------------------------------------------------------
// Core draw-mode toggle logic (shared between command, tray, and shortcut)
// ---------------------------------------------------------------------------
Expand All @@ -104,15 +111,14 @@ fn do_toggle_draw_mode(state: &Mutex<AppState>, app: &tauri::AppHandle) -> bool
println!("[DrawOver] do_toggle_draw_mode -> {}", mode);

if mode {
// Become a regular app so the overlay can take focus & capture mouse
// Draw mode ON: show overlay and capture mouse for drawing
#[cfg(target_os = "macos")]
let _ = app.set_activation_policy(tauri::ActivationPolicy::Regular);
show_overlay(app);
} else {
// Keep clickable so FAB/tray can re-enter draw mode
apply_click_through(app, false);
#[cfg(target_os = "macos")]
let _ = app.set_activation_policy(tauri::ActivationPolicy::Regular);
// Draw mode OFF: hide overlay so user can interact with apps behind it.
// Strokes are preserved in AppState — re-shown when toggled back.
hide_overlay(app);
}

let _ = app.emit("draw-mode-toggled", mode);
Expand Down Expand Up @@ -300,15 +306,28 @@ pub fn run() {
// ----- Tray icon -----
setup_tray(handle)?;

// ----- Global shortcut: DISABLED (phantom toggle) -----
// let shortcut: Shortcut = "Alt+Shift+D".parse()?;
// handle.global_shortcut().on_shortcut(shortcut, ...)?;

// ----- Initial state: overlay clickable -----
// ----- Global shortcut: Alt+Shift+D (Option+Shift+D on macOS) -----
let shortcut: Shortcut = "Alt+Shift+D".parse()?;
println!("[DrawOver] registering global shortcut: Alt+Shift+D");
handle
.global_shortcut()
.on_shortcut(shortcut, move |app, _shortcut, event| {
if event.state == ShortcutState::Pressed {
println!("[DrawOver] global shortcut triggered");
let state = app.state::<Mutex<AppState>>();
do_toggle_draw_mode(state.inner(), app);
}
})
.map_err(|e| {
eprintln!("[DrawOver] FAILED to register global shortcut: {}", e);
e
})?;

// ----- Initial state: overlay hidden (not drawing) -----
#[cfg(target_os = "macos")]
app.set_activation_policy(tauri::ActivationPolicy::Regular);
apply_click_through(app.handle(), false);
println!("[DrawOver] startup complete — overlay clickable");
app.set_activation_policy(tauri::ActivationPolicy::Accessory);
hide_overlay(app.handle());
println!("[DrawOver] startup complete — overlay hidden, press Alt+Shift+D to draw");

Ok(())
})
Expand Down
3 changes: 2 additions & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
"alwaysOnTop": true,
"decorations": false,
"transparent": true,
"skipTaskbar": false,
"skipTaskbar": true,
"resizable": false,
"visible": false,
"width": 1920,
"height": 1080,
"center": true
Expand Down
53 changes: 41 additions & 12 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
let isDrawing = $state(false);
let currentPoints: Point[] = [];
let dpr = 1;
let pdown = $state(0);

// Store subscription values for template reactivity
let drawModeOn = $state(false);
Expand Down Expand Up @@ -53,7 +52,6 @@
}

function onPointerDown(e: PointerEvent): void {
pdown++;
console.log('[DrawOver] pointerdown', { drawModeOn, button: e.button, type: e.pointerType });
if (!drawModeOn) return;
if (e.button !== 0 && e.pointerType === 'mouse') return;
Expand Down Expand Up @@ -294,16 +292,16 @@
<svelte:window onresize={onResize} />

<main class:draw-mode={drawModeOn}>
<div class="debug" style="position:fixed;top:50px;left:8px;z-index:99999;font:12px monospace;background:rgba(0,0,0,0.7);color:#0f0;padding:4px 8px;border-radius:4px;pointer-events:none;">
mode:{drawModeOn} tool:{tool} cls:{drawModeOn ? 'CAPTURE' : 'pass'} pdown:{pdown} strokes:{strokes.length}
</div>

<button
onclick={toggleDrawMode}
style="position:fixed;bottom:24px;left:24px;z-index:99999;padding:8px 14px;background:#3b82f6;color:white;border:none;border-radius:8px;font:14px sans-serif;cursor:pointer;"
>
{drawModeOn ? '🔴 STOP Draw' : '✏️ Start Draw'}
</button>
{#if drawModeOn}
<button
onclick={toggleDrawMode}
class="fab-stop"
title="Stop drawing (Alt+Shift+D)"
aria-label="Stop drawing"
>
</button>
{/if}

<canvas
bind:this={canvas}
Expand Down Expand Up @@ -344,4 +342,35 @@
pointer-events: auto;
cursor: crosshair;
}

.fab-stop {
position: fixed;
bottom: 24px;
left: 24px;
z-index: 99999;
width: 48px;
height: 48px;
border-radius: 50%;
border: none;
background: rgba(239, 68, 68, 0.9);
color: white;
font-size: 20px;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
transition: transform 0.15s ease, background 0.15s ease;
-webkit-user-select: none;
user-select: none;
}

.fab-stop:hover {
background: rgba(220, 38, 38, 0.95);
transform: scale(1.08);
}

.fab-stop:active {
transform: scale(0.95);
}
</style>
Loading