Changed init order, and how the main loop gets started
This commit is contained in:
parent
6ba920355e
commit
71d15443fc
|
@ -20,10 +20,13 @@ import java.util.concurrent.CountDownLatch;
|
|||
public
|
||||
class GtkSupport {
|
||||
public static final boolean isSupported;
|
||||
private static boolean hasSwt = false;
|
||||
private static final boolean hasSwt;
|
||||
|
||||
private static volatile boolean started = false;
|
||||
|
||||
static {
|
||||
boolean hasSupport = false;
|
||||
boolean hasSWT_ = false;
|
||||
try {
|
||||
if (Gtk.INSTANCE != null && Gobject.INSTANCE != null && GThread.INSTANCE != null) {
|
||||
hasSupport = true;
|
||||
|
@ -31,21 +34,38 @@ class GtkSupport {
|
|||
try {
|
||||
Class<?> swtClass = Class.forName("org.eclipse.swt.widgets.Display");
|
||||
if (swtClass != null) {
|
||||
hasSwt = true;
|
||||
hasSWT_ = true;
|
||||
}
|
||||
} catch (Throwable ignore) {
|
||||
}
|
||||
|
||||
// If we are using GTK, we need to make sure the event loop is running. There can be multiple/nested loops.
|
||||
|
||||
// prep for the event loop.
|
||||
// since SWT uses one already, it's not necessary to have two.
|
||||
if (!hasSwt) {
|
||||
if (!hasSWT_) {
|
||||
Gtk instance = Gtk.INSTANCE;
|
||||
instance.gtk_init(0, null);
|
||||
GThread.INSTANCE.g_thread_init(null);
|
||||
instance.gdk_threads_init();
|
||||
}
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
|
||||
isSupported = hasSupport;
|
||||
hasSwt = hasSWT_;
|
||||
}
|
||||
|
||||
public static
|
||||
void startGui() {
|
||||
// only permit one startup per JVM instance
|
||||
if (!started) {
|
||||
started = true;
|
||||
|
||||
// startup the GTK GUI event loop. There can be multiple/nested loops.
|
||||
// since SWT uses one already, it's not necessary to have two.
|
||||
if (!hasSwt) {
|
||||
final CountDownLatch blockUntilStarted = new CountDownLatch(1);
|
||||
|
||||
Thread gtkUpdateThread = new Thread() {
|
||||
@Override
|
||||
public
|
||||
|
@ -71,21 +91,13 @@ class GtkSupport {
|
|||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
|
||||
isSupported = hasSupport;
|
||||
}
|
||||
|
||||
public static
|
||||
void init() {
|
||||
// placeholder to init GTK
|
||||
}
|
||||
|
||||
public static
|
||||
void shutdownGTK() {
|
||||
void shutdownGui() {
|
||||
if (isSupported && !hasSwt) {
|
||||
Gtk.INSTANCE.gtk_main_quit();
|
||||
started = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user