Skip to content

Make signature positioning native SWT for Wayland - #183

Open
mkurz wants to merge 1 commit into
a-sit:mainfrom
mkurz:wayland-native-positioning
Open

mkurz wants to merge 1 commit into
a-sit:mainfrom
mkurz:wayland-native-positioning

Conversation

@mkurz

@mkurz mkurz commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Summary

This removes the SWT/AWT embedding used by the visual signature positioning step and replaces the preview with a native SWT Canvas.

The change is intended to fix the Wayland-specific positioning failure tracked in:

Background

PDF-Over's main Linux UI already uses SWT/GTK, which can run as a native Wayland client. The positioning step was different: it created an SWT.EMBEDDED composite, called SWT_AWT.new_Frame(...), and embedded a Swing JPanel for the PDF preview/signature placement UI.

That mixed SWT/AWT path depends on X11/XEmbed-style embedding and does not work correctly when the surrounding SWT/GTK shell is running natively on Wayland. The visible result is that step 2 (Positionierung / Positioning) can stay grey and visual signature placement is not possible.

The same embedding is also related to the existing fallback path in PositioningState, which logs "Failed to create composite (probably a mac...)" and shows error.PositioningNotPossible ("Manual positioning currently not possible due to a Java Bug. Using automatic positioning."). This change removes the SWT_AWT dependency from positioning, so that specific failure mode should no longer apply. I have not tested macOS, so the fallback path is left in place.

Changes

Positioning Preview

  • Rewrite SignaturePanel from Swing JPanel to SWT Canvas.
  • Keep PDF rendering based on PDFBox PDFRenderer.
  • Convert rendered BufferedImages to SWT ImageData using the existing ImageUtil.convertToSWT(...) helper.
  • Pass SWT placeholder image data into the positioning preview instead of AWT image data.
  • Remove the SWT.EMBEDDED / SWT_AWT.new_Frame(...) dependency from the positioning screen.
  • Port mouse dragging, keyboard movement, page navigation, and mouse-wheel page switching to SWT events.
  • Keep asynchronous PDF page rendering and discard stale render results via a generation counter.

Behaviour Changes Worth Reviewing

  • Mouse-wheel page switching now accumulates the SWT wheel delta and switches pages once it reaches MOUSE_WHEEL_PAGE_THRESHOLD (3), which is one notch at the default "lines per scroll" setting. This replaces the old AWT workaround that de-duplicated wheel events by timestamp because they fired twice on Linux. Shift-wheel still jumps 5 pages.
  • The sign button is now enabled once a signature position exists, rather than once the document has merely been handed to the viewer. This matters because the initial position is only known after the first page render completes.
  • Render resolution is now derived from the monitor the shell is on (getShell().getMonitor()) instead of AWT's Toolkit.getScreenSize().

Lifecycle and Correctness Fixes

  • Fix a crash when signing and exporting one PDF and then opening another: stale render and placeholder callbacks could touch already-disposed SWT widgets. These paths are now guarded, and PositioningComposite caches the Display instead of calling Widget.getDisplay() from worker-thread callbacks.
  • PositioningState.closePDFDocument() now clears the viewer's document, synchronising with the render lock before closing the PDDocument, so a background render does not run against a closed document.
  • Restoring a previously chosen position now waits until page geometry is known. Otherwise the restored coordinates could be clamped against a page size of zero and collapse to the page corner.
  • Re-clamp the current signature position after page geometry changes, so the placeholder stays inside the page in PDFs whose pages have different sizes.
  • Discard stale renders before doing PDFBox work rather than after, so paging quickly through a document no longer runs a full render for each skipped page.

Notes

The implementation still uses AWT classes for off-screen image processing and geometry where appropriate, such as BufferedImage and Point2D. It no longer creates or embeds AWT/Swing UI components for the positioning view.

Validation

Tested manually on Linux aarch64 in a native Wayland session using GDK_BACKEND=wayland:

  • PDF rendered in step 2.
  • Visual signature placement worked.
  • Mouse-wheel page navigation worked.
  • Signing and exporting a signed PDF worked.
  • Opening another PDF after signing did not reproduce the disposed-widget crash seen during testing.
  • Restoring a previous position worked.
  • Switching between pages of different sizes kept the signature placeholder inside the page.

Not manually tested: X11, Windows, and macOS. The change uses portable SWT APIs and removes X11-specific SWT/AWT embedding from the positioning view, but I have not verified those platforms locally.

Also verified locally:

mvn -q -pl pdf-over-gui -am compile
mvn -q test
git diff --check upstream/main...HEAD

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.

"Positioning" does not work under pure Wayland Linux: Missing Wayland support

1 participant