-
Notifications
You must be signed in to change notification settings - Fork 191
[mac]SWT_AWT: synchronize the main thread and the awt thread #2901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Not yet working flawlessly, there is still an NPE: Exception in thread "main" org.eclipse.swt.SWTException: Failed to execute runnable (org.eclipse.swt.SWTException: Widget is disposed) |
|
Snippet for reproduction. Execute the Snippet and click in the left awt TextArea. The focus does not work. At 1000 FOCUS_CHANGES, also my fix can't prevent the focus bug. By the way my system: |
5ba12c5 to
2076c3a
Compare
|
Potential NPEs are fixed. |
2076c3a to
b126d65
Compare
|
@Phillipus It would be nice if you can take a look at this PR. |
|
Probably the actual bug is caused by the simultaneous activation and deactivation of awt embeddings. |
I tested on Mac. I get the same FocusIn and FocusOut messages before the PR and after the PR, but with the PR the caret is visible in c2 when it has the focus. |
But without the PR, if you set the focus to the second embedding, it does not work. Can you confirm? |
|
One more point. If both AWT embeddings still work, set the variable
to 10 private static final int FOCUS_CHANGES = 10; or to 100 or 1000. Then it should definitely break and one side doesn't work anymore. |
With the PR the caret is visible when the second composite gets the focus. Is that the aim? |
Yes, I can confirm the PR allows you to write in both text fields. |


On Mac.
My system:
Apple M3
16 GB
macOS Tahoe 26.1
With SWT: 3.133.0
In SWT is a bug, which harms the focus handling of embedded awt features.
The scenario is the following:
If we have two SWT_AWT-frames running with our AWT code, then if we switch the perspective, the focus handling of the AWT feature fails. Sometimes one of the two AWT applications no longer can get focus at all.
The reason for this behavior seems to be that the AWT activation will be executed a queue (see class SWT_AWT) and not in the SWT main thread, which means that there is a delay at the execution.
If the parent composite of SWT_AWT already lost the focus, then the AWT frame still can get focus, while the second AWT frame could request the focus at almost the same time. It seems this can break the focus handling of the AWT frame.
Since at a perspective change the focus changes happen very fast in a very short time, this can cause this bug.
As a solution we can synchronize the SWT main thread with the AWT thread.
This means:
I will check whether I can provide a standalone snippet, which reproduces this bug.