Added back threads. They now happen ONLY in GtkSupport
This commit is contained in:
parent
b81995ab2b
commit
ebc849f9d0
@ -83,6 +83,8 @@ public interface Gtk extends Library {
|
|||||||
void gtk_main_quit();
|
void gtk_main_quit();
|
||||||
|
|
||||||
void gdk_threads_init();
|
void gdk_threads_init();
|
||||||
|
void gdk_threads_enter();
|
||||||
|
void gdk_threads_leave();
|
||||||
|
|
||||||
Pointer gtk_menu_new();
|
Pointer gtk_menu_new();
|
||||||
Pointer gtk_menu_item_new();
|
Pointer gtk_menu_item_new();
|
||||||
|
@ -34,8 +34,8 @@ class GtkSupport {
|
|||||||
private static volatile Thread gtkDispatchThread;
|
private static volatile Thread gtkDispatchThread;
|
||||||
|
|
||||||
@Property
|
@Property
|
||||||
/** Disables the GTK event loop, if you are already creating one in SWT/etc. */
|
/** Enables/Disables the creation of a native GTK event loop. Useful if you are already creating one via SWT/etc. */
|
||||||
public static boolean DISABLE_EVENT_LOOP = false;
|
public static boolean CREATE_EVENT_LOOP = true;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
boolean hasSupport = false;
|
boolean hasSupport = false;
|
||||||
@ -59,10 +59,15 @@ class GtkSupport {
|
|||||||
@Override
|
@Override
|
||||||
public
|
public
|
||||||
void run() {
|
void run() {
|
||||||
|
final Gtk gtk = Gtk.INSTANCE;
|
||||||
while (started) {
|
while (started) {
|
||||||
try {
|
try {
|
||||||
final Runnable take = dispatchEvents.take();
|
final Runnable take = dispatchEvents.take();
|
||||||
|
|
||||||
|
gtk.gdk_threads_enter();
|
||||||
take.run();
|
take.run();
|
||||||
|
gtk.gdk_threads_leave();
|
||||||
|
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -73,7 +78,7 @@ class GtkSupport {
|
|||||||
gtkDispatchThread.start();
|
gtkDispatchThread.start();
|
||||||
|
|
||||||
|
|
||||||
if (!DISABLE_EVENT_LOOP) {
|
if (CREATE_EVENT_LOOP) {
|
||||||
// startup the GTK GUI event loop. There can be multiple/nested loops.
|
// startup the GTK GUI event loop. There can be multiple/nested loops.
|
||||||
final CountDownLatch blockUntilStarted = new CountDownLatch(1);
|
final CountDownLatch blockUntilStarted = new CountDownLatch(1);
|
||||||
Thread gtkUpdateThread = new Thread() {
|
Thread gtkUpdateThread = new Thread() {
|
||||||
@ -82,15 +87,15 @@ class GtkSupport {
|
|||||||
void run() {
|
void run() {
|
||||||
Gtk instance = Gtk.INSTANCE;
|
Gtk instance = Gtk.INSTANCE;
|
||||||
|
|
||||||
// notify our main thread to continue
|
|
||||||
blockUntilStarted.countDown();
|
|
||||||
|
|
||||||
|
|
||||||
// prep for the event loop.
|
// prep for the event loop.
|
||||||
instance.gdk_threads_init();
|
instance.gdk_threads_init();
|
||||||
instance.gtk_init(0, null);
|
instance.gtk_init(0, null);
|
||||||
GThread.INSTANCE.g_thread_init(null);
|
GThread.INSTANCE.g_thread_init(null);
|
||||||
|
|
||||||
|
// notify our main thread to continue
|
||||||
|
blockUntilStarted.countDown();
|
||||||
|
|
||||||
|
// blocks unit quit
|
||||||
instance.gtk_main();
|
instance.gtk_main();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -121,7 +126,7 @@ class GtkSupport {
|
|||||||
|
|
||||||
public static
|
public static
|
||||||
void shutdownGui() {
|
void shutdownGui() {
|
||||||
if (!DISABLE_EVENT_LOOP) {
|
if (CREATE_EVENT_LOOP) {
|
||||||
Gtk.INSTANCE.gtk_main_quit();
|
Gtk.INSTANCE.gtk_main_quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user