Skip to content

[GTK4] Implement Clipboard supporting copy and pasting to other applications#2588

Merged
jonahgraham merged 1 commit into
eclipse-platform:masterfrom
jonahgraham:clipboard
Oct 24, 2025
Merged

[GTK4] Implement Clipboard supporting copy and pasting to other applications#2588
jonahgraham merged 1 commit into
eclipse-platform:masterfrom
jonahgraham:clipboard

Conversation

@jonahgraham
Copy link
Copy Markdown
Contributor

The pre-existing implementation of Clipboard for GTK4 only allowed copying and pasting within the application.

Fixes #2126

@jonahgraham jonahgraham added the gtk4 GTK4 issues label Oct 3, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Oct 3, 2025

Test Results

   81 files   - 27     81 suites   - 27   8m 28s ⏱️ - 3m 0s
4 502 tests  -  8  4 487 ✅  - 10  15 💤 +2  0 ❌ ±0 
  205 runs   - 50    205 ✅  - 50   0 💤 ±0  0 ❌ ±0 

Results for commit b4a8a24. ± Comparison against base commit 4a6ab2a.

This pull request removes 8 tests.
org.eclipse.swt.tests.junit.Test_org_eclipse_swt_dnd_Clipboard ‑ test_LocalClipboard(int)[2]
org.eclipse.swt.tests.junit.Test_org_eclipse_swt_dnd_Clipboard ‑ test_Remote(int)[2]
org.eclipse.swt.tests.junit.Test_org_eclipse_swt_dnd_Clipboard ‑ test_getAvailableTypeNames(int)[2]
org.eclipse.swt.tests.junit.Test_org_eclipse_swt_dnd_Clipboard ‑ test_getAvailableTypes(int)[2]
org.eclipse.swt.tests.junit.Test_org_eclipse_swt_dnd_Clipboard ‑ test_getContents(int)[2]
org.eclipse.swt.tests.junit.Test_org_eclipse_swt_dnd_Clipboard ‑ test_getContentsAsync(int)[2]
org.eclipse.swt.tests.junit.Test_org_eclipse_swt_dnd_Clipboard ‑ test_setContents(int)[2]
org.eclipse.swt.tests.junit.Test_org_eclipse_swt_graphics_GC ‑ test_drawImageLorg_eclipse_swt_graphics_ImageIIII_ImageDataAtSizeProvider(int)
This pull request skips 3 tests.
org.eclipse.swt.tests.junit.Test_org_eclipse_swt_dnd_Clipboard ‑ test_getContentsBothClipboards
org.eclipse.swt.tests.junit.Test_org_eclipse_swt_dnd_Clipboard ‑ test_setContentsBothClipboards
org.eclipse.swt.tests.junit.Test_org_eclipse_swt_widgets_Shell ‑ test_activateEventSend

♻️ This comment has been updated with latest results.

@jonahgraham jonahgraham self-assigned this Oct 6, 2025
@jonahgraham jonahgraham force-pushed the clipboard branch 5 times, most recently from aac1268 to 28f4799 Compare October 22, 2025 00:50
@jonahgraham
Copy link
Copy Markdown
Contributor Author

jonahgraham commented Oct 22, 2025

In addition the automated tests contained within this change the other ways to test this change involves manually running:

  • multiple instances of ClipboardExample (in SWT examples), in both GTK3 and GTK4 and ensuring that all types can be copied between instances. Using gtk4-demo is also useful.
  • the snippets for the Clipboard
  • the manual test for the Clipboard Bug567826_CrashClipboardExit

Testing has been done in GNOME (mutter wayland compositor), KDE (Kwin wayland compositor) and Xfce, both with clipboard managers disabled and enabled, with both Wayland and X11 as backend (X11 running in Xtigervnc for Xfce cases and Xwayland for wayland cases). Testing all completed on Ubuntu 25.10.

@jonahgraham jonahgraham marked this pull request as ready for review October 22, 2025 16:32
@jonahgraham
Copy link
Copy Markdown
Contributor Author

Ready for review (but there are a bunch of parent PRs to merge first, so really only review the last commit in this PR).

@jonahgraham jonahgraham force-pushed the clipboard branch 2 times, most recently from 3ac5dc8 to 30bba21 Compare October 23, 2025 15:04
@jonahgraham
Copy link
Copy Markdown
Contributor Author

Ready for review

This PR is ready for review, it needs running on a few more machines to give me some confidence that it works properly.

Thank you @akurtakov @fedejeanne @Theo-Dann-Muirhead-Renesas for volunteering to run through this on your machine. I would appreciate if you can run the JUnit testing section below, if you want to try additional hands-on testing see the section lower down.

JUnit testing

To test this, please do the following on a machine with GTK4 (e.g. Ubuntu 25.10 or Fedora 42 or one of their derivitives)

  1. Checkout this PR
  2. Rebuild the binaries (see readme if you are new to this)
  3. Run JUnit Test_org_eclipse_swt_dnd_Clipboard on either wayland or x11
    3a. Wayland: Set environment variables SWT_GTK4=1 and GDK_BACKEND=wayland in launch configuration. Be ready to press the "Press me!" button a few times when prompted
    3b. x11: Set environment variables SWT_GTK4=1 and GDK_BACKEND=x11 in launch configuration.

The setting you have configured on any clipboard manager may interfere with test results, especially if you have selection clipboard disabled or selection clipboard synchronized with main clipboard.

Please report back pass/fail and what version you have used:

  • OS version/distro name
  • GTK4 version: pkg-config --modversion gtk4 on Ubuntu - maybe dnf info gtk4 on Fedora?
  • X Server used (e.g. Xwayland, Xorg, Xtigervnc, Xvfb, other, unknown)
  • Wayland implementation used (e.g. GNOME's mutter, KDE's Kwin, other, unknown)
  • What clipboard manager you have installed (e.g. GNOME's Clipboard History, GNOME's Clipboard Indicator, KDE's Klipper, other, none, unknown)

Additional manual testing

(This is an expanded version of what I briefly mentioned in #2588 (comment))

Additional tests that can be done involve manually driving the clipboard, especially useful to make sure SWT on GTK4 is compatible with other apps on your machine:

Setup

  1. Launch ClipboardExample with SWT_GTK4=1
  2. Launch ClipboardExample with SWT_GTK4=0
  3. Launch gtk4-demo (sudo apt install gtk-4-examples on Ubuntu), select Clipboard and press Run
  4. Launch pinta or your favourite image editor
  5. Launch file explorer (Nautilus, Dolphin, etc)
  6. Launch Eclipse and open a source file
  7. Launch text editor

Now try and copy between each of these items for each type. For example:

  • In file explorer, choose 3 files, and then paste into FileTransfer box of ClipboardExample (GTK4).
  • In ClipboardExample (GTK4) open an image in ImageTransfer, press Copy and then paste into image editor
  • In ClipboardExample (GTK4) fill in a value in each "Copy from:" field and then press "Copy all non-empty types". Then check that all those types paste in other places

Obviously the combinations of what can be copied/pasted is very big, but it would be useful to know if something that you expect should copy/paste does not work in GTK4. If something doesn't work, it may mean that we are missing some mime types or decoding contents of mime types incorrectly.

Screenshots

Launch Configuration Example for Step 3a:

Screenshot_20251023_133358

Wayland "Press me!" button

On Wayland some tests will be skipped if there is no user interaction with the test window. Press the "Press me!" button while tests are running to actually run those tests.

image

ClipboardExample

image

Test results

Running on my machine

Results of running the tests on my machine:

Ubuntu 25.10 and GTK4.20.1 Tested with following managers:

Tested on the following windowing implementations:

  • Kwin (KDE)
  • mutter (GNOME)
  • Xwayland (under both Kwin and mutter)
  • Xtigervnc (using xfce4 as window manager)

Here are the results from one of those runs:

image

Running on GitHub actions

The tests passed on GTK4.14.5 x11 Xvfb on GitHub actions here is build link (key line quoted):

[INFO] Tests run: 16, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 17.95 s -- in org.eclipse.swt.tests.junit.Test_org_eclipse_swt_dnd_Clipboard

@fedejeanne
Copy link
Copy Markdown
Member

@jonahgraham I'll run the tests in my private laptop so outside office hours (probably this weekend) and report back :-)

@Theo-Dann-Muirhead-Renesas
Copy link
Copy Markdown
Contributor

@jonahgraham I have run the tests and done some manual testing. I could not find a difference between how ClipboardExample running GTK4, and gtk4-demo Clipboard handled my actions.

Operating System | Ubuntu 25.10
GTK Version | 4.20.1
GDK Backend | Wayland
GSK Renderer | Vulkan

image

@akurtakov
Copy link
Copy Markdown
Member

Run the automatic tests on:

  • OS version: Fedora 43
  • GTK4 version: 4.20.2-1.fc43
  • X Server: XWayland on mutter
  • Wayland implementation: Mutter
  • Clipboard manager : none (whatever is part of gnome session by default)

All the tests succeeded just fine with both GDK_BACKENDs - x11 and wayland.

Manually tested and works:

  • Text from ClipboardExample(Gtk4) components to Eclipse(Gtk3)
  • Text from Eclipse(Gtk3) to ClipboardExample (Gtk4)
  • File from Nautilus to ClipboardExample(Gtk4)
  • File from ClipboardExample(Gtk4) to Eclipse(Gtk3)

Overall, looks pretty solid.

@akurtakov
Copy link
Copy Markdown
Member

I have went through the code - it's quite a lot of work for sure! As the Gtk 3 code is clearly separated - Jonah, please merge when you feel it's ready to go and it can be further enhanced if needed later.

…cations

The pre-existing implementation of Clipboard for GTK4 only allowed
copying and pasting within the application.

Fixes eclipse-platform#2126
@jonahgraham
Copy link
Copy Markdown
Contributor Author

My last push changed the commit message to use full URL for #2126 instead of just #2126. I had missed/forgotten that part of commit message recommendations

Unfortunately there are a bunch of merged PRs of mine that have this same issue.

@jonahgraham
Copy link
Copy Markdown
Contributor Author

@jonahgraham I'll run the tests in my private laptop so outside office hours (probably this weekend) and report back :-)

Thanks @fedejeanne - I am going to merge now because I have a bunch of other PRs that are waiting on top of this one to proceed. If you have time to test this I would be grateful, especially if you are running something other than Ubuntu 25.10 (that @Theo-Dann-Muirhead-Renesas and I tested on) or Fedora 43 (that @akurtakov tested on)

Once its merged it will also be easier to test because you won't need to rebuild natives 🥳

@jonahgraham
Copy link
Copy Markdown
Contributor Author

The failing windows run is unrelated (documented in #2670)

The failing Linux run is because that is testing GTK4 so there are lots of unrelated test failures, I have confirmed that the clipboard tests pass:

[INFO] Tests run: 16, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 12.13 s -- in org.eclipse.swt.tests.junit.Test_org_eclipse_swt_dnd_Clipboard

Anyway, everything was checked before I force pushed again to fix commit message #2588 (comment) so I am going to merge this now.

@jonahgraham jonahgraham merged commit b942c4c into eclipse-platform:master Oct 24, 2025
6 of 9 checks passed
@jonahgraham jonahgraham deleted the clipboard branch October 24, 2025 17:13
@fedejeanne
Copy link
Copy Markdown
Member

All automatic tests run green on my machine:

  • Ubuntu 24.04.2 LTS
  • Gnome Version 46
  • Windowing System X11

I also opened all the applications you mentioned for the manual testing and copied things back and forth and couldn't find any issues with it 👍

@jonahgraham
Copy link
Copy Markdown
Contributor Author

Thank you @fedejeanne @Theo-Dann-Muirhead-Renesas and @akurtakov for the extra testing.

Ubuntu 24.04.2 LTS

I am very happy about this. It great to know that the implementation works on a relatively wide range of versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gtk4 GTK4 issues

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[GTK4] Implement Full Clipboard support for GTK4

4 participants