diff --git a/Dorkbox-Util/src/dorkbox/util/jna/linux/Gtk.java b/Dorkbox-Util/src/dorkbox/util/jna/linux/Gtk.java index 9bea38c..1ab2eec 100644 --- a/Dorkbox-Util/src/dorkbox/util/jna/linux/Gtk.java +++ b/Dorkbox-Util/src/dorkbox/util/jna/linux/Gtk.java @@ -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(); diff --git a/Dorkbox-Util/src/dorkbox/util/jna/linux/GtkSupport.java b/Dorkbox-Util/src/dorkbox/util/jna/linux/GtkSupport.java index 4aa140c..263fda3 100644 --- a/Dorkbox-Util/src/dorkbox/util/jna/linux/GtkSupport.java +++ b/Dorkbox-Util/src/dorkbox/util/jna/linux/GtkSupport.java @@ -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(); + } + } }