Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement(LorieView.java): improve input handling #768

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 10 additions & 3 deletions app/src/main/cpp/lorie/activity.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern volatile int conn_fd; // The only variable from shared with X server code

static struct {
jclass self;
jmethodID getInstance, clientConnectedStateChanged;
jmethodID getInstance, clientConnectedStateChanged, resetIme;
} MainActivity = {0};

static struct {
Expand Down Expand Up @@ -115,6 +115,7 @@ static void nativeInit(JNIEnv *env, jobject thiz) {
MainActivity.self = FindClassOrDie(env, "com/termux/x11/MainActivity");
MainActivity.getInstance = FindMethodOrDie(env, MainActivity.self, "getInstance", "()Lcom/termux/x11/MainActivity;", JNI_TRUE);
MainActivity.clientConnectedStateChanged = FindMethodOrDie(env, MainActivity.self, "clientConnectedStateChanged", "()V", JNI_FALSE);
MainActivity.resetIme = FindMethodOrDie(env, (*env)->GetObjectClass(env, thiz), "resetIme", "()V", JNI_FALSE);
}

(*env)->GetJavaVM(env, &vm);
Expand Down Expand Up @@ -205,6 +206,9 @@ static int xcallback(int fd, int events, __unused void* data) {
#endif
LorieBuffer_release(buffer);
}
case EVENT_WINDOW_FOCUS_CHANGED: {
(*env)->CallVoidMethod(env, thiz, MainActivity.resetIme);
}
}
}

Expand Down Expand Up @@ -290,6 +294,8 @@ static void sendWindowChange(__unused JNIEnv* env, __unused jobject cls, jint wi

static void sendMouseEvent(__unused JNIEnv* env, __unused jobject cls, jfloat x, jfloat y, jint which_button, jboolean button_down, jboolean relative) {
if (conn_fd != -1) {
if (which_button > 0)
(*env)->CallVoidMethod(env, globalThiz, MainActivity.resetIme);
lorieEvent e = { .mouse = { .t = EVENT_MOUSE, .x = x, .y = y, .detail = which_button, .down = button_down, .relative = relative } };
write(conn_fd, &e, sizeof(e));
}
Expand All @@ -306,6 +312,7 @@ static void sendStylusEvent(__unused JNIEnv *env, __unused jobject thiz, jfloat
jint pressure, jint tilt_x, jint tilt_y,
jint orientation, jint buttons, jboolean eraser, jboolean mouse) {
if (conn_fd != -1) {
(*env)->CallVoidMethod(env, globalThiz, MainActivity.resetIme);
lorieEvent e = { .stylus = { .t = EVENT_STYLUS, .x = x, .y = y, .pressure = pressure, .tilt_x = tilt_x, .tilt_y = tilt_y, .orientation = orientation, .buttons = buttons, .eraser = eraser, .mouse = mouse } };
write(conn_fd, &e, sizeof(e));
}
Expand Down Expand Up @@ -358,7 +365,7 @@ static void sendTextEvent(JNIEnv *env, __unused jobject thiz, jbyteArray text) {
p += len;
if (p - (char*) str >= length)
break;
usleep(30000);
usleep(2500);
}

(*env)->ReleaseByteArrayElements(env, text, str, JNI_ABORT);
Expand Down Expand Up @@ -396,7 +403,7 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
{"sendTouchEvent", "(IIII)V", (void *)&sendTouchEvent},
{"sendStylusEvent", "(FFIIIIIZZ)V", (void *)&sendStylusEvent},
{"requestStylusEnabled", "(Z)V", (void *)&requestStylusEnabled},
{"sendKeyEvent", "(IIZ)Z", (void *)&sendKeyEvent},
{"sendKeyEvent", "(IIZI)Z", (void *)&sendKeyEvent},
{"sendTextEvent", "([B)V", (void *)&sendTextEvent},
{"requestConnection", "()V", (void *)&requestConnection},
};
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/cpp/lorie/cmdentrypoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,13 @@ void lorieSendRootWindowBuffer(LorieBuffer* buffer) {
}
}

void DDXNotifyFocusChanged(void) {
if (conn_fd != -1) {
lorieEvent e = { .type = EVENT_WINDOW_FOCUS_CHANGED };
write(conn_fd, &e, sizeof(e));
}
}

JNIEXPORT jobject JNICALL
Java_com_termux_x11_CmdEntryPoint_getXConnection(JNIEnv *env, __unused jobject cls) {
int client[2];
Expand Down
1 change: 1 addition & 0 deletions app/src/main/cpp/lorie/lorie.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ typedef enum {
EVENT_CLIPBOARD_ANNOUNCE,
EVENT_CLIPBOARD_REQUEST,
EVENT_CLIPBOARD_SEND,
EVENT_WINDOW_FOCUS_CHANGED,
} eventType;

typedef union {
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/cpp/patches/xserver.patch
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,23 @@ index f9b7b06d9..f4b2aeddc 100644

/* display is initialized to "0" by main(). It is then set to the display
* number if specified on the command line. */
+++ b/dix/enterleave.c
@@ -1540,6 +1540,8 @@ DeviceFocusEvents(DeviceIntPtr dev, WindowPtr from, WindowPtr to, int mode)
}
}

+extern void DDXNotifyFocusChanged(void);
+
/**
* Figure out if focus events are necessary and send them to the
* appropriate windows.
@@ -1550,6 +1552,9 @@ DeviceFocusEvents(DeviceIntPtr dev, WindowPtr from, WindowPtr to, int mode)
void
DoFocusEvents(DeviceIntPtr pDev, WindowPtr from, WindowPtr to, int mode)
{
+ if (from != to)
+ DDXNotifyFocusChanged();
+
if (!IsKeyboardDevice(pDev))
return;

17 changes: 17 additions & 0 deletions app/src/main/java/com/termux/x11/EditText.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.termux.x11;

import android.content.Context;
import android.util.AttributeSet;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;

public class EditText extends androidx.appcompat.widget.AppCompatEditText {
public EditText(Context context, AttributeSet attrs) {
super(context, attrs);
}

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
return new InputConnectionWrapper(super.onCreateInputConnection(outAttrs));
}
}
Loading
Loading