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
|
public
|
||||||
class GtkSupport {
|
class GtkSupport {
|
||||||
public static final boolean isSupported;
|
public static final boolean isSupported;
|
||||||
private static boolean hasSwt = false;
|
private static final boolean hasSwt;
|
||||||
|
|
||||||
|
private static volatile boolean started = false;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
boolean hasSupport = false;
|
boolean hasSupport = false;
|
||||||
|
boolean hasSWT_ = false;
|
||||||
try {
|
try {
|
||||||
if (Gtk.INSTANCE != null && Gobject.INSTANCE != null && GThread.INSTANCE != null) {
|
if (Gtk.INSTANCE != null && Gobject.INSTANCE != null && GThread.INSTANCE != null) {
|
||||||
hasSupport = true;
|
hasSupport = true;
|
||||||
@ -31,21 +34,38 @@ class GtkSupport {
|
|||||||
try {
|
try {
|
||||||
Class<?> swtClass = Class.forName("org.eclipse.swt.widgets.Display");
|
Class<?> swtClass = Class.forName("org.eclipse.swt.widgets.Display");
|
||||||
if (swtClass != null) {
|
if (swtClass != null) {
|
||||||
hasSwt = true;
|
hasSWT_ = true;
|
||||||
}
|
}
|
||||||
} catch (Throwable ignore) {
|
} 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.
|
// since SWT uses one already, it's not necessary to have two.
|
||||||
if (!hasSwt) {
|
if (!hasSWT_) {
|
||||||
Gtk instance = Gtk.INSTANCE;
|
Gtk instance = Gtk.INSTANCE;
|
||||||
instance.gtk_init(0, null);
|
instance.gtk_init(0, null);
|
||||||
GThread.INSTANCE.g_thread_init(null);
|
GThread.INSTANCE.g_thread_init(null);
|
||||||
instance.gdk_threads_init();
|
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);
|
final CountDownLatch blockUntilStarted = new CountDownLatch(1);
|
||||||
|
|
||||||
Thread gtkUpdateThread = new Thread() {
|
Thread gtkUpdateThread = new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public
|
public
|
||||||
@ -71,21 +91,13 @@ class GtkSupport {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Throwable ignored) {
|
|
||||||
}
|
|
||||||
|
|
||||||
isSupported = hasSupport;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static
|
public static
|
||||||
void init() {
|
void shutdownGui() {
|
||||||
// placeholder to init GTK
|
|
||||||
}
|
|
||||||
|
|
||||||
public static
|
|
||||||
void shutdownGTK() {
|
|
||||||
if (isSupported && !hasSwt) {
|
if (isSupported && !hasSwt) {
|
||||||
Gtk.INSTANCE.gtk_main_quit();
|
Gtk.INSTANCE.gtk_main_quit();
|
||||||
|
started = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user