Skip to content

fix(eww): background capture cmd to beat 200ms onclick timeout#91

Merged
VictorGSchneider merged 1 commit into
mainfrom
claude/fix-screenshot-widget-Wiz6D
May 11, 2026
Merged

fix(eww): background capture cmd to beat 200ms onclick timeout#91
VictorGSchneider merged 1 commit into
mainfrom
claude/fix-screenshot-widget-Wiz6D

Conversation

@VictorGSchneider
Copy link
Copy Markdown
Owner

@VictorGSchneider VictorGSchneider commented May 11, 2026

Causa raiz (finalmente)

Olhando o source do eww (crates/eww/src/widgets/mod.rs):

prop(timeout: as_duration = Duration::from_millis(200), onclick: as_string) ...
Command::new("/bin/sh").arg("-c").arg(&cmd).spawn();
match child.wait_timeout(timeout) {
    Ok(None) => { let _ = child.kill(); }
}

O onclick tem timeout de 200ms e o eww SIGKILLa o processo se ele passar disso. E como sh -c "single-command" faz exec direto na command (sem manter um sh intermediário), o kill atinge a própria stoa-capture.

Por que gravação funcionava: _record chama wf-recorder ... & imediatamente após o eww close, então o background fork acontece dentro dos 200ms e o wf-recorder vira órfão (sobrevive ao kill do pai).

Por que screenshot falhava: O script faz sleep 0.5 (500ms) ANTES de chamar grim. O eww mata o script aos 200ms, o _screenshot nunca executa. Bate exato com o log:

DEBUG: Case selection/screen/window triggered with args: screen screenshot
(nada depois)

Por que setsid -f não funcionou: Provavelmente não está no PATH do /bin/sh que o eww usa, ou foi morto pelo timeout antes de conseguir forkar.

Fix

Envolver o invocação em ( cmd </dev/null >/dev/null 2>&1 & ):

:onclick "(stoa-capture ${capture-mode} ${capture-type} ${capture-delay} </dev/null >/dev/null 2>&1 &)"
  • Subshell forka, backgrounda stoa-capture, sai imediatamente
  • /bin/sh retorna em microssegundos — muito antes dos 200ms
  • stoa-capture continua como processo órfão, faz seu sleep 0.5 e roda o grim em paz
  • Sintaxe POSIX pura, não depende de setsid/nohup

Test plan

  • git pull && eww reload
  • 📷 + Screen + disparo → arquivo em ~/Pictures/screenshots/
  • 📷 + Selection → slurp abre e arquivo é salvo
  • 📷 + Window → janela ativa capturada
  • Delay 3s/5s aplicam atraso
  • 🎥 ainda funciona (start/stop)
  • /tmp/stoa-capture-debug.log agora mostra _screenshot called, Running grim ..., File exists? yes

Generated by Claude Code

The eww source confirms run_command has a hardcoded 200ms timeout
(crates/eww/src/widgets/mod.rs) — after which it SIGKILLs the onclick
child. Because /bin/sh -c "single-command" execs directly into the
command without an intermediate sh, the kill lands on the stoa-capture
script itself. Recording survived only because wf-recorder is forked
with `&` well within the 200ms window. Screenshot died mid-sleep
before _screenshot ever ran (the debug log shows no entries after the
"Case selection/screen/window triggered" line).

`setsid -f` failed silently (likely not on PATH for the /bin/sh eww
spawns, or itself killed by the timeout before forking), so no entries
appeared at all on the latest attempt.

Wrap the invocation in `( ... </dev/null >/dev/null 2>&1 &)` so /bin/sh
forks a subshell that immediately backgrounds stoa-capture and exits.
The whole sh invocation returns in microseconds, eww's timeout never
fires, and stoa-capture continues as an orphaned process — sleep 0.5
and grim now complete normally.
@VictorGSchneider VictorGSchneider self-assigned this May 11, 2026
@VictorGSchneider VictorGSchneider merged commit 8292799 into main May 11, 2026
1 check passed
@VictorGSchneider VictorGSchneider deleted the claude/fix-screenshot-widget-Wiz6D branch May 11, 2026 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants