Refactored checking for which GTK version is loaded. The logic has been
simplified.
This commit is contained in:
parent
b2635cfa8c
commit
96724bb0e9
@ -25,6 +25,7 @@ import java.net.URI;
|
|||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
import dorkbox.util.jna.linux.Gtk2;
|
import dorkbox.util.jna.linux.Gtk2;
|
||||||
|
import dorkbox.util.jna.linux.GtkCheck;
|
||||||
import dorkbox.util.jna.linux.GtkEventDispatch;
|
import dorkbox.util.jna.linux.GtkEventDispatch;
|
||||||
import dorkbox.util.process.ShellExecutor;
|
import dorkbox.util.process.ShellExecutor;
|
||||||
|
|
||||||
@ -73,7 +74,7 @@ class Desktop {
|
|||||||
// Prefer JNA method over AWT, since there are fewer chances for JNA to fail (even though they call the same method)
|
// Prefer JNA method over AWT, since there are fewer chances for JNA to fail (even though they call the same method)
|
||||||
// Additionally, xdg-open can cause problems in Linux with Chrome installed but not the default browser. It will crash Chrome
|
// Additionally, xdg-open can cause problems in Linux with Chrome installed but not the default browser. It will crash Chrome
|
||||||
// if Chrome was open before this app opened a URL
|
// if Chrome was open before this app opened a URL
|
||||||
if ((OS.isUnix() || OS.isLinux()) && OSUtil.DesktopEnv.isGtkLoaded) {
|
if ((OS.isUnix() || OS.isLinux()) && GtkCheck.isGtkLoaded) {
|
||||||
GtkEventDispatch.dispatch(new Runnable() {
|
GtkEventDispatch.dispatch(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public
|
public
|
||||||
@ -132,7 +133,7 @@ class Desktop {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prevent GTK2/3 conflict caused by Desktop.getDesktop(), which is GTK2 only (via AWT)
|
// Prevent GTK2/3 conflict caused by Desktop.getDesktop(), which is GTK2 only (via AWT)
|
||||||
if ((OS.isUnix() || OS.isLinux()) && OSUtil.DesktopEnv.isGtkLoaded) {
|
if ((OS.isUnix() || OS.isLinux()) && GtkCheck.isGtkLoaded) {
|
||||||
GtkEventDispatch.dispatch(new Runnable() {
|
GtkEventDispatch.dispatch(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public
|
public
|
||||||
@ -181,7 +182,7 @@ class Desktop {
|
|||||||
}
|
}
|
||||||
// Prevent GTK2/3 conflict caused by Desktop.getDesktop(), which is GTK2 only (via AWT)
|
// Prevent GTK2/3 conflict caused by Desktop.getDesktop(), which is GTK2 only (via AWT)
|
||||||
// Prefer JNA method over AWT, since there are fewer chances for JNA to fail (even though they call the same method)
|
// Prefer JNA method over AWT, since there are fewer chances for JNA to fail (even though they call the same method)
|
||||||
else if ((OS.isUnix() || OS.isLinux()) && OSUtil.DesktopEnv.isGtkLoaded) {
|
else if ((OS.isUnix() || OS.isLinux()) && GtkCheck.isGtkLoaded) {
|
||||||
// it can actually be MORE that just "file://" (ie, "ftp://" is legit as well)
|
// it can actually be MORE that just "file://" (ie, "ftp://" is legit as well)
|
||||||
if (!path.contains("://")) {
|
if (!path.contains("://")) {
|
||||||
path = "file://" + path;
|
path = "file://" + path;
|
||||||
|
@ -402,21 +402,6 @@ class OSUtil {
|
|||||||
|
|
||||||
public static
|
public static
|
||||||
class DesktopEnv {
|
class DesktopEnv {
|
||||||
/**
|
|
||||||
* Determine if the application is running via GTK2. This does not cause GTK to load, where calls to Gtk.isGtk2 will
|
|
||||||
*/
|
|
||||||
public static volatile boolean isGtk2 = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine if the application is running via GTK3. This does not cause GTK to load, where calls to Gtk.isGtk3 will
|
|
||||||
*/
|
|
||||||
public static volatile boolean isGtk3 = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determine if the application has loaded GTK yet or not. This does not cause GTK to load, where calls to Gtk.isLoaded will
|
|
||||||
*/
|
|
||||||
public static volatile boolean isGtkLoaded = false;
|
|
||||||
|
|
||||||
public enum Env {
|
public enum Env {
|
||||||
Gnome,
|
Gnome,
|
||||||
KDE,
|
KDE,
|
||||||
|
@ -168,6 +168,9 @@ class SwingUtil {
|
|||||||
/**
|
/**
|
||||||
* Checks to see if GTK is loaded by Swing, and if so - which version is loaded.
|
* Checks to see if GTK is loaded by Swing, and if so - which version is loaded.
|
||||||
*
|
*
|
||||||
|
* NOTE: if the UI uses the 'getSystemLookAndFeelClassName' and is on Linux and it's the GtkLookAndFeel, this will cause GTK2
|
||||||
|
* to get loaded first, which will cause conflicts if one tries to use GTK3
|
||||||
|
*
|
||||||
* @return the version of GTK loaded (if any) otherwise 0 for no version of GTK is loaded
|
* @return the version of GTK loaded (if any) otherwise 0 for no version of GTK is loaded
|
||||||
*/
|
*/
|
||||||
public static
|
public static
|
||||||
|
83
src/dorkbox/util/jna/linux/GtkCheck.java
Normal file
83
src/dorkbox/util/jna/linux/GtkCheck.java
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017 dorkbox, llc
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package dorkbox.util.jna.linux;
|
||||||
|
|
||||||
|
import dorkbox.util.JavaFX;
|
||||||
|
import dorkbox.util.SwingUtil;
|
||||||
|
import dorkbox.util.Swt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accessor methods/logic for determining if GTK is already loaded by the Swing/JavaFX/SWT, or if GTK has been manually loaded via
|
||||||
|
* GtkEventDispatch.startGui().
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("WeakerAccess")
|
||||||
|
public
|
||||||
|
class GtkCheck {
|
||||||
|
/**
|
||||||
|
* Only valid if `isGtkLoaded=true`. Determine if the application is running via GTK2.
|
||||||
|
* <p>
|
||||||
|
* This does not cause GTK to load, where calls to Gtk.isGtk2 will
|
||||||
|
*/
|
||||||
|
public static volatile boolean isGtk2 = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only valid if `isGtkLoaded=true`. Determine if the application is running via GTK3.
|
||||||
|
* <p>
|
||||||
|
* This does not cause GTK to load, where calls to Gtk.isGtk2 will
|
||||||
|
*/
|
||||||
|
public static volatile boolean isGtk3 = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if the application has *MANUALLY* loaded GTK yet or not. This does not cause GTK to load, where calls to Gtk.isLoaded will
|
||||||
|
*/
|
||||||
|
public static volatile boolean isGtkLoaded = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is agnostic w.r.t. how GTK is loaded, which can be manually loaded or loaded via JavaFX/SWT/Swing.
|
||||||
|
*
|
||||||
|
* @return the version of GTK loaded. 0=no GTK loaded, 2=GTK2, 3=GTK3
|
||||||
|
*/
|
||||||
|
public static
|
||||||
|
int getLoadedGtkVersion() {
|
||||||
|
// if we have ALREADY loaded GTK, then return that information.
|
||||||
|
if (isGtkLoaded) {
|
||||||
|
if (isGtk3) {
|
||||||
|
return 3;
|
||||||
|
} else {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Swt.isLoaded) {
|
||||||
|
if (Swt.isGtk3) {
|
||||||
|
return 3;
|
||||||
|
} else {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (JavaFX.isLoaded) {
|
||||||
|
if (JavaFX.isGtk3) {
|
||||||
|
return 3;
|
||||||
|
} else {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// now check if swing has loaded GTK from the Look and Feel
|
||||||
|
return SwingUtil.getLoadedGtkVersion();
|
||||||
|
}
|
||||||
|
}
|
@ -21,7 +21,6 @@ import com.sun.jna.Function;
|
|||||||
import com.sun.jna.NativeLibrary;
|
import com.sun.jna.NativeLibrary;
|
||||||
|
|
||||||
import dorkbox.util.OS;
|
import dorkbox.util.OS;
|
||||||
import dorkbox.util.OSUtil;
|
|
||||||
import dorkbox.util.Swt;
|
import dorkbox.util.Swt;
|
||||||
import dorkbox.util.jna.JnaHelper;
|
import dorkbox.util.jna.JnaHelper;
|
||||||
|
|
||||||
@ -211,9 +210,9 @@ class GtkLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This is so that queries for the GTK version DO NOT try to load GTK
|
// This is so that queries for the GTK version DO NOT try to load GTK
|
||||||
OSUtil.DesktopEnv.isGtk2 = isGtk2;
|
GtkCheck.isGtk2 = isGtk2;
|
||||||
OSUtil.DesktopEnv.isGtk3 = isGtk3;
|
GtkCheck.isGtk3 = isGtk3;
|
||||||
OSUtil.DesktopEnv.isGtkLoaded = isLoaded;
|
GtkCheck.isGtkLoaded = isLoaded;
|
||||||
|
|
||||||
if (shouldLoadGtk) {
|
if (shouldLoadGtk) {
|
||||||
if (!_isLoaded) {
|
if (!_isLoaded) {
|
||||||
|
Loading…
Reference in New Issue
Block a user