Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.graphics.Bitmap;
import android.util.Log;
import android.view.KeyCharacterMap;
import android.view.Surface;

import java.lang.ref.WeakReference;
Expand All @@ -16,6 +17,7 @@

public class GLFW {
private static final Set<GrabListener> grabListeners = Collections.newSetFromMap(new WeakHashMap<>());
private static final KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
private static WeakReference<CursorImplementor> cursorImpl;
private static WeakReference<ClipboardProvider> clipboardImpl;
private static WeakReference<GamepadEnableHandler> gamepadEnable;
Expand Down Expand Up @@ -115,6 +117,11 @@ private static String getClipboardString() {
return clipboardProvider.getClipboardString();
}

@SuppressWarnings("unused") // Used from native
public static char getScancodeLabel(int keycode){
return kcm.getDisplayLabel(keycode);
}

@SuppressWarnings("unused") // Used from native
private static void setClipboardString(String str) {
ClipboardProvider clipboardProvider = Utils.getWeakReference(clipboardImpl);
Expand Down
1 change: 1 addition & 0 deletions src/android_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ typedef struct _GLFWlibraryAndroid
_GLFWwindow* focusedWindow;
void* pojavexec_handle;
const pojavexec_renderspec_t* renderspec;
char keynames[GLFW_KEY_LAST][sizeof(jchar)];
} _GLFWlibraryAndroid;

typedef struct _GLFWcursorAndroid
Expand Down
16 changes: 12 additions & 4 deletions src/android_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ static struct {
jmethodID method_getClipboardString;
jmethodID method_setClipboardString;
jmethodID method_enableDirectGamepad;
jmethodID method_getScancodeLabel;
} jni;

static _Thread_local struct {
Expand Down Expand Up @@ -1108,10 +1109,16 @@ const char* _glfwGetScancodeNameAndroid(int scancode)
_glfwInputError(GLFW_INVALID_VALUE, "Invalid scancode %i", scancode);
return NULL;
}

// TODO: query KeyCharacterMap for the keycode display labels

return NULL;
if(_glfw.android.keynames[scancode][0]) return _glfw.android.keynames[scancode];
jchar label = (*jni_tl.env)->CallStaticCharMethod(jni_tl.env, jni.glfw_class, jni.method_getScancodeLabel, scancode);
// jchar is 16-bit
if(label < 128){
_glfw.android.keynames[scancode][0] = (char) label;
_glfw.android.keynames[scancode][1] = '\0';
} else {
_glfwEncodeUTF8(_glfw.android.keynames[scancode], label);
}
return _glfw.android.keynames[scancode];
}

int _glfwGetKeyScancodeAndroid(int key)
Expand Down Expand Up @@ -1360,6 +1367,7 @@ Java_git_artdeell_dnbootstrap_glfw_GLFW_initialize(JNIEnv *env, jclass clazz) {
jni.method_getClipboardString = (*env)->GetStaticMethodID(env, clazz, "getClipboardString", "()Ljava/lang/String;");
jni.method_setClipboardString = (*env)->GetStaticMethodID(env, clazz, "setClipboardString", "(Ljava/lang/String;)V");
jni.method_enableDirectGamepad = (*env)->GetStaticMethodID(env, clazz, "enableDirectGamepad", "(Ljava/nio/ByteBuffer;Ljava/nio/ByteBuffer;)V");
jni.method_getScancodeLabel = (*env)->GetStaticMethodID(env, clazz, "getScancodeLabel", "(I)C");
}

JNIEXPORT void JNICALL
Expand Down
Loading