forked from dorkbox/SystemTray
Fixed issue with GTK enter/leave thread and the main loop
This commit is contained in:
parent
bf1776ed89
commit
0065cb259a
@ -19,14 +19,12 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
|
||||
import dorkbox.util.jna.linux.AppIndicator;
|
||||
import dorkbox.util.jna.linux.Gobject;
|
||||
import dorkbox.util.jna.linux.Gtk;
|
||||
import dorkbox.util.jna.linux.GtkSupport;
|
||||
import dorkbox.util.tray.SystemTray;
|
||||
import dorkbox.util.tray.SystemTrayMenuAction;
|
||||
|
||||
@ -40,13 +38,10 @@ import dorkbox.util.tray.SystemTrayMenuAction;
|
||||
* Lantern: https://github.com/getlantern/lantern/ Apache 2.0 License Copyright 2010 Brave New Software Project, Inc.
|
||||
*/
|
||||
public class AppIndicatorTray extends SystemTray {
|
||||
private static final boolean useSWT = GtkSupport.usesSwtMainLoop;
|
||||
|
||||
private static final AppIndicator libappindicator = AppIndicator.INSTANCE;
|
||||
private static final Gobject libgobject = Gobject.INSTANCE;
|
||||
private static final Gtk libgtk = Gtk.INSTANCE;
|
||||
|
||||
private final CountDownLatch blockUntilStarted = new CountDownLatch(1);
|
||||
private final Map<String, MenuEntry> menuEntries = new HashMap<String, MenuEntry>(2);
|
||||
|
||||
private volatile AppIndicator.AppIndicatorInstanceStruct appIndicator;
|
||||
@ -101,25 +96,7 @@ public class AppIndicatorTray extends SystemTray {
|
||||
|
||||
libgtk.gdk_threads_leave();
|
||||
|
||||
if (!useSWT) {
|
||||
Thread gtkUpdateThread = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
// notify our main thread to continue
|
||||
AppIndicatorTray.this.blockUntilStarted.countDown();
|
||||
libgtk.gtk_main();
|
||||
}
|
||||
};
|
||||
gtkUpdateThread.setName("GTK event loop");
|
||||
gtkUpdateThread.start();
|
||||
}
|
||||
|
||||
// we CANNOT continue until the GTK thread has started! (ignored if SWT is used)
|
||||
try {
|
||||
this.blockUntilStarted.await();
|
||||
this.active = true;
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -22,7 +22,6 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import javax.swing.JMenuItem;
|
||||
|
||||
@ -32,7 +31,6 @@ import dorkbox.util.SwingUtil;
|
||||
import dorkbox.util.jna.linux.Gobject;
|
||||
import dorkbox.util.jna.linux.Gtk;
|
||||
import dorkbox.util.jna.linux.Gtk.GdkEventButton;
|
||||
import dorkbox.util.jna.linux.GtkSupport;
|
||||
import dorkbox.util.tray.SystemTray;
|
||||
import dorkbox.util.tray.SystemTrayMenuAction;
|
||||
import dorkbox.util.tray.SystemTrayMenuPopup;
|
||||
@ -43,11 +41,9 @@ import dorkbox.util.tray.SystemTrayMenuPopup;
|
||||
* This is the "old" way to do it, and does not work with some desktop environments.
|
||||
*/
|
||||
public class GtkSystemTray extends SystemTray {
|
||||
private static final boolean useSWT = GtkSupport.usesSwtMainLoop;
|
||||
private static final Gobject libgobject = Gobject.INSTANCE;
|
||||
private static final Gtk libgtk = Gtk.INSTANCE;
|
||||
|
||||
private final CountDownLatch blockUntilStarted = new CountDownLatch(1);
|
||||
private final Map<String, JMenuItem> menuEntries = new HashMap<String, JMenuItem>(2);
|
||||
|
||||
private volatile SystemTrayMenuPopup jmenu;
|
||||
@ -122,25 +118,7 @@ public class GtkSystemTray extends SystemTray {
|
||||
}
|
||||
});
|
||||
|
||||
if (!useSWT) {
|
||||
Thread gtkUpdateThread = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
// notify our main thread to continue
|
||||
GtkSystemTray.this.blockUntilStarted.countDown();
|
||||
libgtk.gtk_main();
|
||||
}
|
||||
};
|
||||
gtkUpdateThread.setName("GTK event loop");
|
||||
gtkUpdateThread.start();
|
||||
}
|
||||
|
||||
// we CANNOT continue until the GTK thread has started! (ignored if SWT is used)
|
||||
try {
|
||||
this.blockUntilStarted.await();
|
||||
this.active = true;
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user