Fixed issues with GTK event loop start/stop.

This commit is contained in:
nathan 2015-01-23 02:53:33 +01:00
parent 4f0f8bae64
commit 893e6ac82e
2 changed files with 11 additions and 3 deletions

View File

@ -54,7 +54,8 @@ public interface Gtk extends Library {
*/
public void gtk_main();
/**
* Makes the innermost invocation of the main loop return when it regains control.
* Makes the innermost invocation of the main loop return when it regains control. ONLY CALL FROM THE GtkSupport class, UNLESS
* you know what you're doing!
*/
public void gtk_main_quit();

View File

@ -5,12 +5,12 @@ import java.util.concurrent.CountDownLatch;
public class GtkSupport {
public static final boolean isSupported;
private static boolean hasSwt = false;
static {
if (Gtk.INSTANCE != null && AppIndicator.INSTANCE != null && Gobject.INSTANCE != null && GThread.INSTANCE != null) {
isSupported = true;
boolean hasSwt = false;
try {
Class<?> swtClass = Class.forName("org.eclipse.swt.widgets.Display");
if (swtClass != null) {
@ -18,7 +18,8 @@ public class GtkSupport {
}
} catch (Exception ignore) {}
// swt already init's gtk. If we are using GTK, we need to make sure the event loop is runnign
// If we are using GTK, we need to make sure the event loop is running. There can be multiple/nested loops.
// since SWT uses one already, it's not necessary to have two.
if (!hasSwt) {
Gtk instance = Gtk.INSTANCE;
instance.gtk_init(0, null);
@ -58,4 +59,10 @@ public class GtkSupport {
public static void init() {
// placeholder to init GTK
}
public static void shutdownGTK() {
if (!hasSwt) {
Gtk.INSTANCE.gtk_main_quit();
}
}
}