Fixed issue with GTK enter/leave thread and the main loop. Main loop is now handled by GtkSupport

This commit is contained in:
nathan 2015-01-22 03:25:11 +01:00
parent 8a142c27d7
commit 886ab2ca98

View File

@ -1,10 +1,10 @@
package dorkbox.util.jna.linux;
import java.util.concurrent.CountDownLatch;
public class GtkSupport {
public static final boolean isSupported;
public static final boolean usesSwtMainLoop;
static {
if (Gtk.INSTANCE != null && AppIndicator.INSTANCE != null && Gobject.INSTANCE != null && GThread.INSTANCE != null) {
@ -18,20 +18,40 @@ public class GtkSupport {
}
} catch (Exception ignore) {}
// swt already init's gtk. Maybe this is the wrong way to go about this?
// swt already init's gtk. If we are using GTK, we need to make sure the event loop is runnign
if (!hasSwt) {
Gtk instance = Gtk.INSTANCE;
instance.gtk_init(0, null);
GThread.INSTANCE.g_thread_init(null);
instance.gdk_threads_init();
usesSwtMainLoop = false;
} else {
usesSwtMainLoop = true;
final CountDownLatch blockUntilStarted = new CountDownLatch(1);
Thread gtkUpdateThread = new Thread() {
@Override
public void run() {
Gtk instance = Gtk.INSTANCE;
// notify our main thread to continue
blockUntilStarted.countDown();
instance.gdk_threads_enter();
instance.gtk_main();
// MUST leave as well!
instance.gdk_threads_leave();
}
};
gtkUpdateThread.setName("GTK Event Loop");
gtkUpdateThread.start();
try {
// we CANNOT continue until the GTK thread has started! (ignored if SWT is used)
blockUntilStarted.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} else {
isSupported = false;
usesSwtMainLoop = false;
}
}