Added preferGtk3 to GTK loading. Fail loading GTK if GTK2 is forced, and
GTK2 cannot load. Code polish.
This commit is contained in:
parent
1abe7b60ab
commit
8d7d35182a
@ -33,6 +33,7 @@ import dorkbox.util.Swt;
|
|||||||
public
|
public
|
||||||
class GtkEventDispatch {
|
class GtkEventDispatch {
|
||||||
static boolean FORCE_GTK2 = false;
|
static boolean FORCE_GTK2 = false;
|
||||||
|
static boolean PREFER_GTK3 = false;
|
||||||
static boolean DEBUG = false;
|
static boolean DEBUG = false;
|
||||||
|
|
||||||
// have to save these in a field to prevent GC on the objects (since they go out-of-scope from java)
|
// have to save these in a field to prevent GC on the objects (since they go out-of-scope from java)
|
||||||
@ -47,7 +48,7 @@ class GtkEventDispatch {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private static volatile boolean started = false;
|
private static boolean started = false;
|
||||||
|
|
||||||
@SuppressWarnings("FieldCanBeLocal")
|
@SuppressWarnings("FieldCanBeLocal")
|
||||||
private static Thread gtkUpdateThread = null;
|
private static Thread gtkUpdateThread = null;
|
||||||
@ -60,14 +61,15 @@ class GtkEventDispatch {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static
|
public static synchronized
|
||||||
void startGui(final boolean FORCE_GTK2, final boolean DEBUG) {
|
void startGui(final boolean forceGtk2, final boolean preferGkt3, final boolean debug) {
|
||||||
// only permit one startup per JVM instance
|
// only permit one startup per JVM instance
|
||||||
if (!started) {
|
if (!started) {
|
||||||
started = true;
|
started = true;
|
||||||
|
|
||||||
GtkEventDispatch.FORCE_GTK2 = FORCE_GTK2;
|
GtkEventDispatch.FORCE_GTK2 = forceGtk2;
|
||||||
GtkEventDispatch.DEBUG = DEBUG;
|
GtkEventDispatch.PREFER_GTK3 = preferGkt3;
|
||||||
|
GtkEventDispatch.DEBUG = debug;
|
||||||
|
|
||||||
// startup the GTK GUI event loop. There can be multiple/nested loops.
|
// startup the GTK GUI event loop. There can be multiple/nested loops.
|
||||||
|
|
||||||
@ -80,7 +82,7 @@ class GtkEventDispatch {
|
|||||||
public
|
public
|
||||||
void run() {
|
void run() {
|
||||||
Glib.GLogFunc orig = null;
|
Glib.GLogFunc orig = null;
|
||||||
if (DEBUG) {
|
if (debug) {
|
||||||
// don't suppress GTK warnings in debug mode
|
// don't suppress GTK warnings in debug mode
|
||||||
LoggerFactory.getLogger(GtkEventDispatch.class).debug("Running GTK Native Event Loop");
|
LoggerFactory.getLogger(GtkEventDispatch.class).debug("Running GTK Native Event Loop");
|
||||||
} else {
|
} else {
|
||||||
@ -120,7 +122,7 @@ class GtkEventDispatch {
|
|||||||
* Waits for the all posted events to GTK to finish loading
|
* Waits for the all posted events to GTK to finish loading
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("Duplicates")
|
@SuppressWarnings("Duplicates")
|
||||||
public static
|
public static synchronized
|
||||||
void waitForEventsToComplete() {
|
void waitForEventsToComplete() {
|
||||||
final CountDownLatch blockUntilStarted = new CountDownLatch(1);
|
final CountDownLatch blockUntilStarted = new CountDownLatch(1);
|
||||||
|
|
||||||
@ -275,22 +277,6 @@ class GtkEventDispatch {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static
|
|
||||||
void shutdownGui() {
|
|
||||||
dispatchAndWait(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public
|
|
||||||
void run() {
|
|
||||||
// If JavaFX/SWT is used, this is UNNECESSARY (and will break SWT/JavaFX shutdown)
|
|
||||||
if (!GtkLoader.alreadyRunningGTK) {
|
|
||||||
Gtk2.gtk_main_quit();
|
|
||||||
}
|
|
||||||
|
|
||||||
started = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static
|
public static
|
||||||
void dispatchAndWait(final Runnable runnable) {
|
void dispatchAndWait(final Runnable runnable) {
|
||||||
if (isDispatch.get()) {
|
if (isDispatch.get()) {
|
||||||
@ -356,4 +342,20 @@ class GtkEventDispatch {
|
|||||||
isDispatch.set(false);
|
isDispatch.set(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static synchronized
|
||||||
|
void shutdownGui() {
|
||||||
|
dispatchAndWait(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public
|
||||||
|
void run() {
|
||||||
|
// If JavaFX/SWT is used, this is UNNECESSARY (and will break SWT/JavaFX shutdown)
|
||||||
|
if (!GtkLoader.alreadyRunningGTK) {
|
||||||
|
Gtk2.gtk_main_quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
started = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,10 @@ class GtkLoader {
|
|||||||
* SWT uses GTK2 or GTK3. We do not work with the GTK3 version of SWT.
|
* SWT uses GTK2 or GTK3. We do not work with the GTK3 version of SWT.
|
||||||
*/
|
*/
|
||||||
static {
|
static {
|
||||||
boolean shouldUseGtk2 = GtkEventDispatch.FORCE_GTK2;
|
boolean forceGtk2 = GtkEventDispatch.FORCE_GTK2;
|
||||||
|
// prefer GTK3 and force GTK2 are mutually exclusive
|
||||||
|
boolean preferGtk3 = !forceGtk2 && GtkEventDispatch.PREFER_GTK3;
|
||||||
|
|
||||||
boolean _isGtk2 = false;
|
boolean _isGtk2 = false;
|
||||||
boolean _isLoaded = false;
|
boolean _isLoaded = false;
|
||||||
boolean _alreadyRunningGTK = false;
|
boolean _alreadyRunningGTK = false;
|
||||||
@ -76,11 +79,6 @@ class GtkLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (OSUtil.Linux.isKali()) {
|
|
||||||
// Kali linux has some WEIRD graphical oddities via GTK3. GTK2 looks just fine.
|
|
||||||
shouldUseGtk2 = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// we can force the system to use the swing indicator, which WORKS, but doesn't support transparency in the icon. However, there
|
// we can force the system to use the swing indicator, which WORKS, but doesn't support transparency in the icon. However, there
|
||||||
// are certain GTK functions we might want to use (even if we are Swing or AWT), so we load GTK anyways...
|
// are certain GTK functions we might want to use (even if we are Swing or AWT), so we load GTK anyways...
|
||||||
|
|
||||||
@ -88,7 +86,7 @@ class GtkLoader {
|
|||||||
String gtk2LibName = "gtk-x11-2.0";
|
String gtk2LibName = "gtk-x11-2.0";
|
||||||
String gtk3LibName = "libgtk-3.so.0";
|
String gtk3LibName = "libgtk-3.so.0";
|
||||||
|
|
||||||
if (!_isLoaded && shouldUseGtk2) {
|
if (!_isLoaded && (forceGtk2 || !preferGtk3)) {
|
||||||
try {
|
try {
|
||||||
NativeLibrary library = JnaHelper.register(gtk2LibName, Gtk2.class);
|
NativeLibrary library = JnaHelper.register(gtk2LibName, Gtk2.class);
|
||||||
|
|
||||||
@ -113,6 +111,11 @@ class GtkLoader {
|
|||||||
LoggerFactory.getLogger(GtkLoader.class).error("Error loading library", e);
|
LoggerFactory.getLogger(GtkLoader.class).error("Error loading library", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (forceGtk2) {
|
||||||
|
// don't try anything else if we forced GTK2
|
||||||
|
_isLoaded = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// now for the defaults...
|
// now for the defaults...
|
||||||
|
Loading…
Reference in New Issue
Block a user