Fix Option key not working in macOS

Alt key is used to invoke the Option key in macOS. But instead of XK_Alt,
the server expects XK_Meta keysym.

Re: #163
This commit is contained in:
Gaurav Ujjwal 2023-05-17 09:56:05 +05:30
parent 8b0e4f845c
commit f2b994774f
3 changed files with 17 additions and 1 deletions

View file

@ -320,6 +320,12 @@ Java_com_gaurav_avnc_vnc_VncClient_nativeInit(JNIEnv *env, jobject thiz, jlong c
return JNI_FALSE;
}
extern "C"
JNIEXPORT jboolean JNICALL
Java_com_gaurav_avnc_vnc_VncClient_nativeIsServerMacOS(JNIEnv *env, jobject thiz, jlong client_ptr) {
auto client = (rfbClient *) client_ptr;
return client->serverMajor == 3 && client->serverMinor == 889;
}
extern "C"
JNIEXPORT void JNICALL

View file

@ -1,5 +1,6 @@
package com.gaurav.avnc.vnc
import android.view.KeyEvent
import androidx.annotation.Keep
import java.io.IOException
import java.nio.ByteBuffer
@ -124,6 +125,7 @@ class VncClient(private val observer: Observer) {
fun connect(host: String, port: Int) {
connected = nativeInit(nativePtr, host, port)
if (!connected) throw IOException(nativeGetLastErrorStr())
applyCompatQuirks()
}
/**
@ -252,6 +254,13 @@ class VncClient(private val observer: Observer) {
block()
}
private fun applyCompatQuirks() {
if (nativeIsServerMacOS(nativePtr)) {
XKeySymAndroid.updateKeyMap(KeyEvent.KEYCODE_ALT_LEFT, XKeySym.XK_Meta_L)
XKeySymAndroid.updateKeyMap(KeyEvent.KEYCODE_ALT_RIGHT, XKeySym.XK_Meta_R)
}
}
private external fun nativeClientCreate(): Long
private external fun nativeConfigure(clientPtr: Long, securityType: Int, useLocalCursor: Boolean, imageQuality: Int, useRawEncoding: Boolean)
private external fun nativeInit(clientPtr: Long, host: String, port: Int): Boolean
@ -270,6 +279,7 @@ class VncClient(private val observer: Observer) {
private external fun nativeUploadFrameTexture(clientPtr: Long)
private external fun nativeUploadCursor(clientPtr: Long, px: Int, py: Int)
private external fun nativeGetLastErrorStr(): String
private external fun nativeIsServerMacOS(clientPtr: Long): Boolean
private external fun nativeCleanup(clientPtr: Long)
@Keep

2
extern/libvncserver vendored

@ -1 +1 @@
Subproject commit ea809211332c435877fd1a3a2de1d8c4fefb4d5b
Subproject commit 62a7f9316f6f01c7c9ca0d920737b75e9972012c