Skip to content

Commit 977dcab

Browse files
committed
enhancement(LorieView.java): improve input handling
1 parent 989d08a commit 977dcab

File tree

10 files changed

+629
-99
lines changed

10 files changed

+629
-99
lines changed

app/src/main/cpp/lorie/activity.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extern volatile int conn_fd; // The only variable from shared with X server code
2626

2727
static struct {
2828
jclass self;
29-
jmethodID getInstance, clientConnectedStateChanged;
29+
jmethodID getInstance, clientConnectedStateChanged, resetIme;
3030
} MainActivity = {0};
3131

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

120121
(*env)->GetJavaVM(env, &vm);
@@ -205,6 +206,9 @@ static int xcallback(int fd, int events, __unused void* data) {
205206
#endif
206207
LorieBuffer_release(buffer);
207208
}
209+
case EVENT_WINDOW_FOCUS_CHANGED: {
210+
(*env)->CallVoidMethod(env, thiz, MainActivity.resetIme);
211+
}
208212
}
209213
}
210214

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

291295
static void sendMouseEvent(__unused JNIEnv* env, __unused jobject cls, jfloat x, jfloat y, jint which_button, jboolean button_down, jboolean relative) {
292296
if (conn_fd != -1) {
297+
if (which_button > 0)
298+
(*env)->CallVoidMethod(env, globalThiz, MainActivity.resetIme);
293299
lorieEvent e = { .mouse = { .t = EVENT_MOUSE, .x = x, .y = y, .detail = which_button, .down = button_down, .relative = relative } };
294300
write(conn_fd, &e, sizeof(e));
295301
}
@@ -306,6 +312,7 @@ static void sendStylusEvent(__unused JNIEnv *env, __unused jobject thiz, jfloat
306312
jint pressure, jint tilt_x, jint tilt_y,
307313
jint orientation, jint buttons, jboolean eraser, jboolean mouse) {
308314
if (conn_fd != -1) {
315+
(*env)->CallVoidMethod(env, globalThiz, MainActivity.resetIme);
309316
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 } };
310317
write(conn_fd, &e, sizeof(e));
311318
}
@@ -358,7 +365,7 @@ static void sendTextEvent(JNIEnv *env, __unused jobject thiz, jbyteArray text) {
358365
p += len;
359366
if (p - (char*) str >= length)
360367
break;
361-
usleep(30000);
368+
usleep(2500);
362369
}
363370

364371
(*env)->ReleaseByteArrayElements(env, text, str, JNI_ABORT);
@@ -396,7 +403,7 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
396403
{"sendTouchEvent", "(IIII)V", (void *)&sendTouchEvent},
397404
{"sendStylusEvent", "(FFIIIIIZZ)V", (void *)&sendStylusEvent},
398405
{"requestStylusEnabled", "(Z)V", (void *)&requestStylusEnabled},
399-
{"sendKeyEvent", "(IIZ)Z", (void *)&sendKeyEvent},
406+
{"sendKeyEvent", "(IIZI)Z", (void *)&sendKeyEvent},
400407
{"sendTextEvent", "([B)V", (void *)&sendTextEvent},
401408
{"requestConnection", "()V", (void *)&requestConnection},
402409
};

app/src/main/cpp/lorie/cmdentrypoint.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,13 @@ void lorieSendRootWindowBuffer(LorieBuffer* buffer) {
437437
}
438438
}
439439

440+
void DDXNotifyFocusChanged(void) {
441+
if (conn_fd != -1) {
442+
lorieEvent e = { .type = EVENT_WINDOW_FOCUS_CHANGED };
443+
write(conn_fd, &e, sizeof(e));
444+
}
445+
}
446+
440447
JNIEXPORT jobject JNICALL
441448
Java_com_termux_x11_CmdEntryPoint_getXConnection(JNIEnv *env, __unused jobject cls) {
442449
int client[2];

app/src/main/cpp/lorie/lorie.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ typedef enum {
104104
EVENT_CLIPBOARD_ANNOUNCE,
105105
EVENT_CLIPBOARD_REQUEST,
106106
EVENT_CLIPBOARD_SEND,
107+
EVENT_WINDOW_FOCUS_CHANGED,
107108
} eventType;
108109

109110
typedef union {

app/src/main/cpp/patches/xserver.patch

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,3 +299,23 @@ index f9b7b06d9..f4b2aeddc 100644
299299

300300
/* display is initialized to "0" by main(). It is then set to the display
301301
* number if specified on the command line. */
302+
+++ b/dix/enterleave.c
303+
@@ -1540,6 +1540,8 @@ DeviceFocusEvents(DeviceIntPtr dev, WindowPtr from, WindowPtr to, int mode)
304+
}
305+
}
306+
307+
+extern void DDXNotifyFocusChanged(void);
308+
+
309+
/**
310+
* Figure out if focus events are necessary and send them to the
311+
* appropriate windows.
312+
@@ -1550,6 +1552,9 @@ DeviceFocusEvents(DeviceIntPtr dev, WindowPtr from, WindowPtr to, int mode)
313+
void
314+
DoFocusEvents(DeviceIntPtr pDev, WindowPtr from, WindowPtr to, int mode)
315+
{
316+
+ if (from != to)
317+
+ DDXNotifyFocusChanged();
318+
+
319+
if (!IsKeyboardDevice(pDev))
320+
return;
321+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.termux.x11;
2+
3+
import android.content.Context;
4+
import android.util.AttributeSet;
5+
import android.view.inputmethod.EditorInfo;
6+
import android.view.inputmethod.InputConnection;
7+
8+
public class EditText extends androidx.appcompat.widget.AppCompatEditText {
9+
public EditText(Context context, AttributeSet attrs) {
10+
super(context, attrs);
11+
}
12+
13+
@Override
14+
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
15+
return new InputConnectionWrapper(super.onCreateInputConnection(outAttrs));
16+
}
17+
}

0 commit comments

Comments
 (0)