Skip to content
Merged
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
17 changes: 17 additions & 0 deletions AGENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Agent Rules

## Git & PR — WAJIB

### Tidak ada atribusi AI
- **DILARANG** mencantumkan "Generated with Claude Code", "Co-authored-by", "@claude", atau atribusi AI apapun di commit message, PR body, atau kode.
- Author commit = Aji Anaz `<aji.anaz@gmail.com>`.
- Co-author trailer = **selalu kosong**.
- Tidak boleh ada footer signature agent di output.

### Commit message
- Konvensional: `fix:`, `feat:`, `chore:`, `refactor:`, `docs:`, `checkpoint:`
- Bahasa Inggris untuk commit, PR boleh Indonesia.

### Branch
- Naming: `fix/<desc>`, `feat/<desc>`, `checkpoint/<desc>`
- Base PR default: `develop`
4 changes: 3 additions & 1 deletion bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"tauri": "tauri"
},
"devDependencies": {
"@lucide/svelte": "^1.24.0",
"@sveltejs/adapter-static": "^3.0.0",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^4.0.0",
Expand Down
4 changes: 4 additions & 0 deletions src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"core:window:allow-hide",
"core:window:allow-set-focus",
"core:window:allow-start-dragging",
"core:window:allow-set-ignore-cursor-events",
"core:window:allow-set-position",
"core:window:allow-set-size",
"core:window:allow-current-monitor",
"global-shortcut:allow-register",
"global-shortcut:allow-unregister",
"global-shortcut:allow-is-registered"
Expand Down
52 changes: 34 additions & 18 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,
};
use tauri_plugin_global_shortcut::{GlobalShortcutExt, Shortcut, ShortcutState};
// global shortcut disabled during dev

// ---------------------------------------------------------------------------
// Data structures
Expand Down Expand Up @@ -67,9 +67,24 @@ fn apply_click_through(app: &tauri::AppHandle, ignore: bool) {
/// Show the overlay window 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)
if let Ok(Some(monitor)) = window.current_monitor() {
let size = monitor.size();
let pos = monitor.position();
let _ = window.set_position(tauri::PhysicalPosition::new(pos.x, pos.y));
let _ = window.set_size(tauri::PhysicalSize::new(size.width, size.height));
}
let _ = window.show();
let _ = window.set_focus();
let _ = window.set_ignore_cursor_events(false);
// 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
);
} else {
eprintln!("[DrawOver] show_overlay — overlay window not found!");
}
}

Expand All @@ -86,11 +101,18 @@ fn do_toggle_draw_mode(state: &Mutex<AppState>, app: &tauri::AppHandle) -> bool
s.is_draw_mode = !s.is_draw_mode;
s.is_draw_mode
};
println!("[DrawOver] do_toggle_draw_mode -> {}", mode);

if mode {
// Become a regular app so the overlay can take focus & capture mouse
#[cfg(target_os = "macos")]
let _ = app.set_activation_policy(tauri::ActivationPolicy::Regular);
show_overlay(app);
} else {
apply_click_through(app, true);
// 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);
}

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

// ----- Global shortcut: Option+Shift+D (Alt+Shift+D) -----
let shortcut: Shortcut = "Alt+Shift+D".parse()?;

// Register + attach handler in one call
handle
.global_shortcut()
.on_shortcut(shortcut, move |app, _shortcut, event| {
if event.state == ShortcutState::Pressed {
let state = app.state::<Mutex<AppState>>();
do_toggle_draw_mode(state.inner(), app);
}
})?;

// ----- Initial state: overlay click-through -----
apply_click_through(app.handle(), true);
// ----- Global shortcut: DISABLED (phantom toggle) -----
// let shortcut: Shortcut = "Alt+Shift+D".parse()?;
// handle.global_shortcut().on_shortcut(shortcut, ...)?;

// ----- Initial state: overlay clickable -----
#[cfg(target_os = "macos")]
app.set_activation_policy(tauri::ActivationPolicy::Regular);
apply_click_through(app.handle(), false);
println!("[DrawOver] startup complete — overlay clickable");

Ok(())
})
Expand Down
5 changes: 3 additions & 2 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
{
"label": "overlay",
"title": "DrawOver",
"fullscreen": true,
"fullscreen": false,
"maximized": false,
"alwaysOnTop": true,
"decorations": false,
"transparent": true,
"skipTaskbar": true,
"skipTaskbar": false,
"resizable": false,
"width": 1920,
"height": 1080,
Expand Down
34 changes: 33 additions & 1 deletion src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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 @@ -52,8 +53,9 @@
}

function onPointerDown(e: PointerEvent): void {
pdown++;
console.log('[DrawOver] pointerdown', { drawModeOn, button: e.button, type: e.pointerType });
if (!drawModeOn) return;
// Only respond to primary button (left click or touch)
if (e.button !== 0 && e.pointerType === 'mouse') return;
e.preventDefault();

Expand Down Expand Up @@ -211,6 +213,16 @@
}

// ─── Actions ───
async function toggleDrawMode(): Promise<void> {
try {
const result = await invoke<boolean>('toggle_draw_mode');
console.log('[DrawOver] toggle_draw_mode result:', result);
drawMode.set(result);
} catch (e) {
console.error('[DrawOver] toggle_draw_mode failed:', e);
}
}

function undo(): void {
if (strokes.length === 0) return;
strokes = strokes.slice(0, -1);
Expand Down Expand Up @@ -241,6 +253,7 @@
let unlistenDrawToggle: UnlistenFn | null = null;

listen<boolean>('draw-mode-toggled', (event) => {
console.log('[DrawOver] draw-mode-toggled event:', event.payload);
drawMode.set(event.payload);
})
.then((un) => {
Expand All @@ -250,6 +263,14 @@
// Not in Tauri context (e.g. browser dev) — ignore
});

// Sync initial state from Rust backend
invoke<boolean>('is_draw_mode')
.then((v) => {
console.log('[DrawOver] initial is_draw_mode:', v);
drawMode.set(v);
})
.catch(() => {});

// Clean up on destroy
return () => {
window.removeEventListener('resize', onResize);
Expand All @@ -273,6 +294,17 @@
<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;top:8px;right:8px;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>

<canvas
bind:this={canvas}
class:capture={drawModeOn}
Expand Down
Loading