SWT behaves better on linux now. Added Swt.isEventThread method
This commit is contained in:
parent
39ddd235f6
commit
9591362580
@ -234,7 +234,6 @@ class Gtk {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
if (SystemTray.isJavaFxLoaded) {
|
if (SystemTray.isJavaFxLoaded) {
|
||||||
if (!JavaFX.isEventThread()) {
|
if (!JavaFX.isEventThread()) {
|
||||||
try {
|
try {
|
||||||
@ -255,10 +254,7 @@ class Gtk {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (SystemTray.isSwtLoaded) {
|
} else if (SystemTray.isSwtLoaded) {
|
||||||
if (SystemTray.FORCE_TRAY_TYPE != SystemTray.TrayType.GtkStatusIcon) {
|
if (!Swt.isEventThread()) {
|
||||||
// GTK system tray has threading issues if we block here (because it is likely in the event thread)
|
|
||||||
// AppIndicator version doesn't have this problem
|
|
||||||
|
|
||||||
// we have to WAIT until all events are done processing, OTHERWISE we have initialization issues
|
// we have to WAIT until all events are done processing, OTHERWISE we have initialization issues
|
||||||
try {
|
try {
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -277,7 +273,6 @@ class Gtk {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// we have to WAIT until all events are done processing, OTHERWISE we have initialization issues
|
// we have to WAIT until all events are done processing, OTHERWISE we have initialization issues
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -302,11 +297,9 @@ class Gtk {
|
|||||||
*/
|
*/
|
||||||
public static
|
public static
|
||||||
void dispatch(final Runnable runnable) {
|
void dispatch(final Runnable runnable) {
|
||||||
// FIXME: on mac, check -XstartOnFirstThread.. there are issues with javaFX (possibly SWT as well)
|
|
||||||
|
|
||||||
if (alreadyRunningGTK) {
|
if (alreadyRunningGTK) {
|
||||||
// SWT/JavaFX
|
|
||||||
if (SystemTray.isJavaFxLoaded) {
|
if (SystemTray.isJavaFxLoaded) {
|
||||||
|
// JavaFX only
|
||||||
if (JavaFX.isEventThread()) {
|
if (JavaFX.isEventThread()) {
|
||||||
// Run directly on the JavaFX event thread
|
// Run directly on the JavaFX event thread
|
||||||
runnable.run();
|
runnable.run();
|
||||||
@ -314,31 +307,22 @@ class Gtk {
|
|||||||
else {
|
else {
|
||||||
JavaFX.dispatch(runnable);
|
JavaFX.dispatch(runnable);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (SystemTray.isSwtLoaded) {
|
|
||||||
if (isDispatch) {
|
|
||||||
// Run directly on the dispatch thread
|
|
||||||
runnable.run();
|
|
||||||
} else {
|
|
||||||
Swt.dispatch(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public
|
|
||||||
void run() {
|
|
||||||
isDispatch = true;
|
|
||||||
|
|
||||||
try {
|
return;
|
||||||
runnable.run();
|
|
||||||
} finally {
|
|
||||||
isDispatch = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
if (SystemTray.isSwtLoaded) {
|
||||||
});
|
if (Swt.isEventThread()) {
|
||||||
|
// Run directly on the SWT event thread. If it's not on the dispatch thread, we can use raw GTK to put it there
|
||||||
|
runnable.run();
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
// not swt/javafx
|
// not javafx
|
||||||
|
// gtk/swt are **mostly** the same in how events are dispatched, so we can use "raw" gtk methods for SWT
|
||||||
if (isDispatch) {
|
if (isDispatch) {
|
||||||
// Run directly on the dispatch thread
|
// Run directly on the dispatch thread
|
||||||
runnable.run();
|
runnable.run();
|
||||||
@ -368,8 +352,6 @@ class Gtk {
|
|||||||
// the correct way to do it. Add with a slightly higher value
|
// the correct way to do it. Add with a slightly higher value
|
||||||
gdk_threads_add_idle_full(100, callback, null, null);
|
gdk_threads_add_idle_full(100, callback, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,10 +27,13 @@ import org.eclipse.swt.widgets.Display;
|
|||||||
public
|
public
|
||||||
class Swt {
|
class Swt {
|
||||||
private static final Display currentDisplay;
|
private static final Display currentDisplay;
|
||||||
|
private static final Thread currentDisplayThread;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// we have to save this, otherwise it is "null" when methods are run from the swing EDT.
|
// we MUST save this, otherwise it is "null" when methods are run from the swing EDT.
|
||||||
currentDisplay = Display.getCurrent();
|
currentDisplay = Display.getCurrent();
|
||||||
|
|
||||||
|
currentDisplayThread = currentDisplay.getThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -48,6 +51,11 @@ class Swt {
|
|||||||
currentDisplay.syncExec(runnable);
|
currentDisplay.syncExec(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static
|
||||||
|
boolean isEventThread() {
|
||||||
|
return Thread.currentThread() == currentDisplayThread;
|
||||||
|
}
|
||||||
|
|
||||||
public static
|
public static
|
||||||
void onShutdown(final Runnable runnable) {
|
void onShutdown(final Runnable runnable) {
|
||||||
currentDisplay.getShells()[0].addListener(org.eclipse.swt.SWT.Close, new org.eclipse.swt.widgets.Listener() {
|
currentDisplay.getShells()[0].addListener(org.eclipse.swt.SWT.Close, new org.eclipse.swt.widgets.Listener() {
|
||||||
|
Loading…
Reference in New Issue
Block a user