Skip to content

Commit

Permalink
Initial support for M1 CPU (qzind#783)
Browse files Browse the repository at this point in the history
Fixes JNA crash, add experimental JavaFX support
  • Loading branch information
tresf authored Apr 3, 2021
1 parent 2aa773e commit 802d1f8
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 9 deletions.
24 changes: 23 additions & 1 deletion ant/javafx.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,33 @@
<property file="ant/project.properties"/>
<property name="javafx.version" value="11.0.2"/>
<property name="javafx.mirror" value="https://gluonhq.com/download"/>
<property name="javafx.arch" value="aarch64"/>
<property name="javafx.separator" value="_"/>
<property name="lib.dir" value="lib"/>
<property name="dist.dir" value="out/dist"/>
-->
<!-- end required properties -->

<!-- ARM64 -->
<condition property="javafx.version" value="${javafx.aarch64.version}">
<equals arg1="aarch64" arg2="${jre.arch}"/>
</condition>
<condition property="javafx.mirror" value="${javafx.aarch64.mirror}">
<equals arg1="aarch64" arg2="${jre.arch}"/>
</condition>
<condition property="javafx.arch" value="${javafx.aarch64.arch}">
<equals arg1="aarch64" arg2="${jre.arch}"/>
</condition>
<condition property="javafx.separator" value="${javafx.aarch64.separator}">
<equals arg1="aarch64" arg2="${jre.arch}"/>
</condition>

<!-- Intel (fallback) -->
<property name="javafx.version" value="${javafx.x86_64.version}" description="fallback"/>
<property name="javafx.mirror" value="${javafx.x86_64.mirror}" description="fallback"/>
<property name="javafx.arch" value="${javafx.x86_64.arch}" description="fallback"/>
<property name="javafx.separator" value="${javafx.x86_64.separator}" description="fallback"/>

<loadresource property="javafx.version-url">
<propertyresource name="javafx.version"/>
<filterchain>
Expand Down Expand Up @@ -116,7 +138,7 @@

<!-- Downloads and extracts javafx for the specified platform -->
<target name="download-javafx-platform" depends="get-javafx-version">
<get src="${javafx.mirror}/openjfx-${javafx.version-url}-${javafx.platform}-x64_bin-sdk.zip" verbose="true" dest="javafx-${javafx.platform}.zip"/>
<get src="${javafx.mirror}/openjfx-${javafx.version-url}${javafx.separator}${javafx.platform}-${javafx.arch}_bin-sdk.zip" verbose="true" dest="javafx-${javafx.platform}.zip"/>
<unzip src="javafx-${javafx.platform}.zip" dest="lib/javafx/${javafx.platform}/javafx-${javafx.version}" overwrite="true"/>
<delete file="javafx-${javafx.platform}.zip"/>
</target>
Expand Down
16 changes: 14 additions & 2 deletions ant/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,21 @@ jar.index=true
# See also qz.common.Constants.java
javac.source=1.8
javac.target=1.8
javafx.version=15.ea+3_monocle
javafx.mirror=https://download2.gluonhq.com/openjfx/15
java.download=https://adoptopenjdk.net/?variant=openjdk11

jre.arch=${os.arch}

# JavaFX x86_64
javafx.x86_64.version=15.ea+3_monocle
javafx.x86_64.mirror=https://download2.gluonhq.com/openjfx/15
javafx.x86_64.arch=x64
javafx.x86_64.separator=-

# JavaFX ARM64
javafx.aarch64.version=17-ea+6
javafx.aarch64.mirror=https://download2.gluonhq.com/openjfx/17
javafx.aarch64.arch=aarch64
javafx.aarch64.separator=_

# Workaround to delay expansion of $${foo} (e.g. shell scripts)
dollar=$
Binary file not shown.
Binary file not shown.
16 changes: 15 additions & 1 deletion src/org/dyorgio/jna/platform/mac/Foundation.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,21 @@ public interface Foundation extends Library {

boolean class_addMethod(NativeLong clazz, Pointer selector, Callback callback, String types);

NativeLong objc_msgSend(NativeLong receiver, Pointer selector, Object... args);
NativeLong objc_msgSend(NativeLong receiver, Pointer selector);

NativeLong objc_msgSend(NativeLong receiver, Pointer selector, Pointer obj);

NativeLong objc_msgSend(NativeLong receiver, Pointer selector, NativeLong objAddress);

NativeLong objc_msgSend(NativeLong receiver, Pointer selector, boolean boolArg);

NativeLong objc_msgSend(NativeLong receiver, Pointer selector, double doubleArg);

// Used by NSObject.performSelectorOnMainThread
NativeLong objc_msgSend(NativeLong receiver, Pointer selector, Pointer selectorDst, NativeLong objAddress, boolean wait);

// Used by NSString.fromJavaString
NativeLong objc_msgSend(NativeLong receiver, Pointer selector, byte[] bytes, int len, long encoding);

Pointer sel_registerName(String selectorName);
}
24 changes: 20 additions & 4 deletions src/org/dyorgio/jna/platform/mac/FoundationUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,28 @@ public static boolean isTrue(NativeLong id) {
return !NULL.equals(id);
}

public static NativeLong invoke(NativeLong id, String selector, Object... args) {
return FOUNDATION.objc_msgSend(id, Foundation.INSTANCE.sel_registerName(selector), args);
public static NativeLong invoke(NativeLong id, String selector) {
return FOUNDATION.objc_msgSend(id, Foundation.INSTANCE.sel_registerName(selector));
}

public static NativeLong invoke(NativeLong id, Pointer selectorPointer, Object... args) {
return FOUNDATION.objc_msgSend(id, selectorPointer, args);
public static NativeLong invoke(NativeLong id, String selector, boolean boolArg) {
return FOUNDATION.objc_msgSend(id, Foundation.INSTANCE.sel_registerName(selector), boolArg);
}

public static NativeLong invoke(NativeLong id, String selector, double doubleArg) {
return FOUNDATION.objc_msgSend(id, Foundation.INSTANCE.sel_registerName(selector), doubleArg);
}

public static NativeLong invoke(NativeLong id, String selector, NativeLong objAddress) {
return FOUNDATION.objc_msgSend(id, Foundation.INSTANCE.sel_registerName(selector), objAddress);
}

public static NativeLong invoke(NativeLong id, Pointer selectorPointer) {
return FOUNDATION.objc_msgSend(id, selectorPointer);
}

public static NativeLong invoke(NativeLong id, Pointer selectorPointer, NativeLong objAddress) {
return FOUNDATION.objc_msgSend(id, selectorPointer, objAddress);
}

public static void runOnMainThreadAndWait(Runnable runnable) throws InterruptedException, ExecutionException {
Expand Down
2 changes: 1 addition & 1 deletion src/qz/utils/MacUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public static void toggleTemplateIcon(TrayIcon icon) {
final NativeLong image = Foundation.INSTANCE.object_getIvar(awtView, Foundation.INSTANCE.class_getInstanceVariable(FoundationUtil.invoke(awtView, "class"), "image"));
FoundationUtil.invoke(image, "setTemplate:", true);
FoundationUtil.runOnMainThreadAndWait(() -> {
FoundationUtil.invoke(statusItem, "setView:", (Object) null);
FoundationUtil.invoke(statusItem, "setView:", FoundationUtil.NULL);
NativeLong target;
if (SystemUtilities.getOSVersion().greaterThanOrEqualTo(Version.forIntegers(10, 10))) {
target = FoundationUtil.invoke(statusItem, "button");
Expand Down

0 comments on commit 802d1f8

Please sign in to comment.