Fixed issue with GTK enter/leave thread and the main loop. Main loop is now handled by GtkSupport
This commit is contained in:
parent
8a142c27d7
commit
886ab2ca98
@ -1,10 +1,10 @@
|
|||||||
package dorkbox.util.jna.linux;
|
package dorkbox.util.jna.linux;
|
||||||
|
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
|
|
||||||
public class GtkSupport {
|
public class GtkSupport {
|
||||||
public static final boolean isSupported;
|
public static final boolean isSupported;
|
||||||
public static final boolean usesSwtMainLoop;
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
if (Gtk.INSTANCE != null && AppIndicator.INSTANCE != null && Gobject.INSTANCE != null && GThread.INSTANCE != null) {
|
if (Gtk.INSTANCE != null && AppIndicator.INSTANCE != null && Gobject.INSTANCE != null && GThread.INSTANCE != null) {
|
||||||
@ -18,20 +18,40 @@ public class GtkSupport {
|
|||||||
}
|
}
|
||||||
} catch (Exception ignore) {}
|
} 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) {
|
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();
|
||||||
|
|
||||||
usesSwtMainLoop = false;
|
final CountDownLatch blockUntilStarted = new CountDownLatch(1);
|
||||||
} else {
|
|
||||||
usesSwtMainLoop = true;
|
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 {
|
} else {
|
||||||
isSupported = false;
|
isSupported = false;
|
||||||
usesSwtMainLoop = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user