44 import java.security.PrivilegedAction;
45 import java.util.Map;
46 import java.util.concurrent.CountDownLatch;
47
48 final class GtkApplication extends Application implements InvokeLaterDispatcher.InvokeLaterSubmitter {
49
50 static {
51 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
52 Application.loadNativeLibrary();
53 return null;
54 });
55 }
56
57 public static int screen = -1;
58 public static long display = 0;
59 public static long visualID = 0;
60
61 private final InvokeLaterDispatcher invokeLaterDispatcher;
62
63 GtkApplication() {
64 // Check whether the Display is valid and throw an exception if not.
65 // We use UnsupportedOperationException rather than HeadlessException
66 // so as not to introduce a dependency on AWT.
67 if (!isDisplayValid()) {
68 throw new UnsupportedOperationException("Unable to open DISPLAY");
69 }
70
71 // Embedded in SWT, with shared event thread
72 boolean isEventThread = AccessController
73 .doPrivileged((PrivilegedAction<Boolean>) () -> Boolean.getBoolean("javafx.embed.isEventThread"));
74 if (!isEventThread) {
75 invokeLaterDispatcher = new InvokeLaterDispatcher(this);
76 invokeLaterDispatcher.start();
77 } else {
78 invokeLaterDispatcher = null;
79 }
80 }
81
82 private static boolean isDisplayValid() {
83 return _isDisplayValid();
84 }
85
86 private void initDisplay() {
87 Map ds = getDeviceDetails();
88 if (ds != null) {
89 Object value;
90 value = ds.get("XDisplay");
91 if (value != null) {
92 display = (Long)value;
93 }
94 value = ds.get("XVisualID");
95 if (value != null) {
96 visualID = (Long)value;
97 }
98 value = ds.get("XScreenID");
99 if (value != null) {
100 screen = (Integer)value;
|
44 import java.security.PrivilegedAction;
45 import java.util.Map;
46 import java.util.concurrent.CountDownLatch;
47
48 final class GtkApplication extends Application implements InvokeLaterDispatcher.InvokeLaterSubmitter {
49
50 static {
51 AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
52 Application.loadNativeLibrary();
53 return null;
54 });
55 }
56
57 public static int screen = -1;
58 public static long display = 0;
59 public static long visualID = 0;
60
61 private final InvokeLaterDispatcher invokeLaterDispatcher;
62
63 GtkApplication() {
64
65 int gtkVersion =
66 AccessController.doPrivileged((PrivilegedAction<Integer>) () -> {
67 String v = System.getProperty("jdk.gtk.version","2");
68 int ret = 0;
69 if ("3".equals(v)) {
70 System.out.println("jdk.gtk.version is 3");
71 ret = 3;
72 } else if ("2".equals(v) || v.startsWith("2.")) {
73 System.out.println("jdk.gtk.version is 2");
74 ret = 2;
75 }
76 return ret;
77 });
78 boolean gtkVersionVerbose =
79 AccessController.doPrivileged((PrivilegedAction<Boolean>) () -> {
80 return Boolean.getBoolean("jdk.gtk.verbose");
81 });
82 _setGTKversion(gtkVersion, gtkVersionVerbose);
83
84 // Check whether the Display is valid and throw an exception if not.
85 // We use UnsupportedOperationException rather than HeadlessException
86 // so as not to introduce a dependency on AWT.
87 if (!isDisplayValid()) {
88 throw new UnsupportedOperationException("Unable to open DISPLAY");
89 }
90
91 // Embedded in SWT, with shared event thread
92 boolean isEventThread = AccessController
93 .doPrivileged((PrivilegedAction<Boolean>) () -> Boolean.getBoolean("javafx.embed.isEventThread"));
94 if (!isEventThread) {
95 invokeLaterDispatcher = new InvokeLaterDispatcher(this);
96 invokeLaterDispatcher.start();
97 } else {
98 invokeLaterDispatcher = null;
99 }
100 }
101
102 private static native int _setGTKversion(int version, boolean verbose);
103
104 private static boolean isDisplayValid() {
105 return _isDisplayValid();
106 }
107
108 private void initDisplay() {
109 Map ds = getDeviceDetails();
110 if (ds != null) {
111 Object value;
112 value = ds.get("XDisplay");
113 if (value != null) {
114 display = (Long)value;
115 }
116 value = ds.get("XVisualID");
117 if (value != null) {
118 visualID = (Long)value;
119 }
120 value = ds.get("XScreenID");
121 if (value != null) {
122 screen = (Integer)value;
|