# Upstream niri Feature Request

## Summary

Add `--no-clipboard` flag to `screenshot-window` action to allow screenshots without clipboard pollution.

## Use Case

When automating window captures (e.g., AI agents, monitoring tools, testing), the current behavior has drawbacks:

1. **Clipboard pollution**: Every screenshot overwrites clipboard, disrupting user workflow
2. **Privacy concerns**: Clipboard history tools log all screenshots
3. **Automation friction**: Scripts need workarounds to preserve/restore clipboard

## Current Behavior

```bash
# This ALWAYS copies to clipboard, no way to disable
niri msg action screenshot-window --id 12 --write-to-disk true
```

Code location: `src/niri.rs` in `save_screenshot()`:
```rust
set_data_device_selection(
    &state.niri.display_handle,
    &state.niri.seat,
    vec![String::from("image/png")],
    buf.clone(),
);
```

## Proposed Solution

Add optional `--no-clipboard` flag:

```bash
# Don't copy to clipboard
niri msg action screenshot-window --id 12 --write-to-disk true --no-clipboard true

# Current behavior (default)
niri msg action screenshot-window --id 12 --write-to-disk true --no-clipboard false
```

**Implementation approach:**

1. Add `no_clipboard: bool` field to `Action::ScreenshotWindow` in `niri-ipc`
2. Pass flag through to `save_screenshot()`
3. Conditionally skip `set_data_device_selection()` call

## Backward Compatibility

- Default behavior unchanged (`--no-clipboard false`)
- Existing scripts continue to work
- Opt-in for users who need it

## Alternative Workarounds (Current)

**Save/restore clipboard** (fragile, doesn't preserve mime types):
```bash
OLD_CLIP=$(wl-paste)
niri msg action screenshot-window --id 12 --write-to-disk true
echo "$OLD_CLIP" | wl-copy
```

**Clear clipboard after** (destroys user's clipboard):
```bash
niri msg action screenshot-window --id 12 --write-to-disk true
echo "" | wl-copy
```

Neither is ideal for automation.

## Related

Similar flags exist in other screenshot tools:
- `grim` doesn't auto-copy to clipboard (only saves to file)
- `spectacle --nonotify` (KDE, suppresses notifications)
- `gnome-screenshot --file` (saves without clipboard)

## Benefits

- ✅ Better automation support
- ✅ Less clipboard pollution
- ✅ Privacy improvement (no clipboard history logging)
- ✅ Backward compatible
- ✅ Simple implementation (~10 lines)

## Impact

**Who benefits:**
- Automation scripts
- AI agent tools (this use case)
- Testing frameworks
- Monitoring tools
- Users with clipboard history enabled

**Who's affected:**
- No one (opt-in via flag)

## References

- Skill implementation: https://github.com/[user]/skills/tree/main/skills/niri-window-capture
- Security analysis: [SECURITY.md](./SECURITY.md)
- Discussion: [to be created]

---

**Would you accept a PR for this feature?**
