Skip to content

feat(wallhaven): add fit-to-monitor preview and monitor-aware filters - #163

Open
F4M1N3C wants to merge 3 commits into
noctalia-dev:mainfrom
F4M1N3C:feat/wallhaven-fit-apply
Open

F4M1N3C wants to merge 3 commits into
noctalia-dev:mainfrom
F4M1N3C:feat/wallhaven-fit-apply

Conversation

@F4M1N3C

@F4M1N3C F4M1N3C commented Nov 20, 2026

Copy link
Copy Markdown

Summary

Adds a Fit toggle to the Wallhaven preview. With Fit on, the preview shows the full image with a highlighted, draggable monitor-aspect box; Apply crops that region, scales it to the focused monitor's resolution, and applies it to that output. With Fit off, preview and Apply keep the existing full-image behavior.

Also adds monitor-aware filters: Mine resolution and aspect ratio use the focused output, At Least Mine filters for resolutions at least as large as the monitor, and random sorting gets a shuffle icon.

Motivation

Wallhaven images are often much larger than the monitor, and the existing preview only offered a full-image Apply. Picking the visible part required an external image editor. Fit keeps the choice inside the panel and guarantees the saved file matches the monitor resolution instead of relying on the compositor to crop an oversized image.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Refactoring
  • Build / packaging

Related Issue

None.

Testing

  • validate-plugins.py --profile official → Validated 14 plugin manifest(s).
  • test_validate_plugins.py → Ran 178 tests ... OK
  • noctalia plugins lint wallhaven → 0 errors, 0 warnings
  • python3 -m py_compile wallhaven/crop_stream.py → OK
  • luau-compile --null wallhaven/{panel,wallhaven,shortcut}.luau → OK
  • Pixel-stream integration test: handshake, SCM_RIGHTS descriptor, 8-bit RGBA frame size, Fit off/on/off without restarting the helper, quit removes the socket, state, and PID files.
  • SIGTERM test: helper writes its PID, exits, and removes its socket, state, and PID files.

Manual Coverage

  • Tested on Niri
  • Tested on Hyprland
  • Tested on Sway
  • Tested on another compositor:
  • Tested with different bar positions and density settings
  • Tested at different interface scaling values
  • Tested with multiple monitors

Hyprland/DP-1 (3440x1440): opened the panel, previewed a 4096x3072 image, toggled Fit on/off, dragged the box, closed the panel. No helper process, socket, state file, or cached full image remained; the current wallpaper was not changed. Fitted Apply targets the focused output, but the apply path itself was not run during automated verification to avoid changing the desktop.

Screenshots / Videos

Captured from an empty workspace at 3440x1440 and cropped to the panel.

Fit off:

Fit off

Fit on with the draggable monitor-aspect box:

Fit on

Checklist

  • This PR is ready for review, or it is marked as Draft.
  • I self-reviewed the changes.
  • I added or updated translations/en.json, or this PR adds no new user-facing strings.
  • I did not edit non-English translation files unless this PR is explicitly for translation tooling, an import/export sync, or a maintainer-requested locale change.

Additional Notes

  • Version bump: 1.4.1 → 1.5.0 (new feature).
  • New runtime dependencies: python3 (crop helper) and ImageMagick (prefers magick 7; falls back to ImageMagick 6 convert + identify); both are declared in plugin.toml and documented in the README.
  • The crop helper is prewarmed after the preview download so the Fit toggle is immediate. It exits when the preview closes or after ten minutes without a client, and removes its socket, state, and PID files. A dead PID lets the panel restart a crashed helper instead of trusting a stale socket; leftovers are swept at panel open.
  • onOpen stays cheap: sweeps are detached runAsync calls and the first fetch is deferred to onFrameTick, preserving the CPU-budget fix from fix(wallhaven): keep panel onOpen under its CPU budget on fresh script loads #150.
  • Filter changes that arrive during an in-flight request are queued and refetched instead of dropped.
  • Wallhaven IDs are validated before they reach cache paths or shell arguments; all shell commands use shellQuote or argv arrays.
  • Fitted crops are rendered to a cache temp file, then moved into place, so a failed crop does not leave a partial file at the destination.
  • Thumbnail regenerated with the official generator layout: 960×540 WebP, Wallhaven title, Wallpaper · Panel tag, Noctalia logo and the Fit crop box visible.
  • Partial downloads (.part) and crop temp files are swept at panel open, alongside orphaned previews, sockets, and state files.

Keep the crop producer's 8-bit RGBA contract for 16-bit images, correct its
dimensions after identify, clean up its socket and state, and write fit state
when the toggle is turned off. Queue filter changes that arrive during an
in-flight request instead of dropping them, and avoid sending unsupported
ratios to the Wallhaven API.

Also reject malformed wallpaper IDs before they reach cache paths, apply
fitted crops to the focused output, stop the helper on exit even during an
apply, and render crops to a cache temp file before moving them into place.
Sweep partial downloads, crop temp files, and stale helper files at panel open,
document the runtime requirements, socket policy, reads, and writes, and use
the existing mode label as the resolution select placeholder.

Prefer ImageMagick 7's `magick` and fall back to ImageMagick 6's
`convert`/`identify`. The helper writes a PID file so the panel can replace a
crashed helper instead of trusting a stale socket. Regenerate the thumbnail
with the official generator layout.
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.

1 participant