Add SWT headless fragment for running SWT without a display #2594
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR implements a headless mode for SWT (Standard Widget Toolkit), similar to Java AWT's
java.awt.headless
system property. This allows SWT applications to run in environments without a native windowing system, which is particularly useful for server-side applications, testing, CI/CD environments, and command-line tools that reference UI code.Changes
1. Display.isHeadless() API
Added a new public static method
Display.isHeadless()
to detect headless mode:false
for all native platforms (gtk, cocoa, win32)true
for the new headless implementationDisplay.java
in gtk, cocoa, and win32 implementations2. Headless Implementation
Created a new
headless
source folder inbundles/org.eclipse.swt/Eclipse SWT/
with a complete headless implementation of core SWT widgets:Core Widgets:
Key Features:
getChildren()
redraw()
andupdate()
are harmless no-ops3. Fragment Configuration
Created
org.eclipse.swt.headless
fragment inbinaries/
with:Usage Example
Benefits
Implementation Details
isHeadless()
method)Limitations
The headless implementation is intentionally minimal and focused on state management:
These limitations are documented in the included README.md.
Related Issues
Fixes #577498
Testing
The implementation can be tested by setting the
org.eclipse.swt.headless
fragment as the only platform fragment available, which will cause the OSGi framework to select it automatically. Basic widget creation, property management, and parent-child relationships have been verified to work correctly.Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.