From ec87d27b28e03a383b0a1a1e81026b03aad39240 Mon Sep 17 00:00:00 2001 From: artdeell Date: Mon, 12 Sep 2022 20:48:32 +0300 Subject: [PATCH] Add the ability to move all windows in Mod Installer --- .../net/kdt/pojavlaunch/AWTInputBridge.java | 1 + .../pojavlaunch/JavaGUILauncherActivity.java | 18 ++++++++ app_pojavlauncher/src/main/jni/awt_bridge.c | 42 +++++++++++++++++++ .../res/layout/activity_java_gui_launcher.xml | 42 +++++++++++++++++++ 4 files changed, 103 insertions(+) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/AWTInputBridge.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/AWTInputBridge.java index 7d5aa6a65..89bd5da4d 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/AWTInputBridge.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/AWTInputBridge.java @@ -39,4 +39,5 @@ public class AWTInputBridge { public static native void nativeSendData(int type, int i1, int i2, int i3, int i4); public static native void nativePutClipboard(String data); + public static native void nativeMoveWindow(int xoff, int yoff); } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/JavaGUILauncherActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/JavaGUILauncherActivity.java index 6955e1856..c7e137379 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/JavaGUILauncherActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/JavaGUILauncherActivity.java @@ -51,6 +51,10 @@ public class JavaGUILauncherActivity extends BaseActivity implements View.OnTouc findViewById(R.id.installmod_mouse_pri).setOnTouchListener(this); findViewById(R.id.installmod_mouse_sec).setOnTouchListener(this); + findViewById(R.id.installmod_window_moveup).setOnTouchListener(this); + findViewById(R.id.installmod_window_movedown).setOnTouchListener(this); + findViewById(R.id.installmod_window_moveleft).setOnTouchListener(this); + findViewById(R.id.installmod_window_moveright).setOnTouchListener(this); mMousePointerImageView.post(() -> { ViewGroup.LayoutParams params = mMousePointerImageView.getLayoutParams(); @@ -187,6 +191,20 @@ public class JavaGUILauncherActivity extends BaseActivity implements View.OnTouc AWTInputBridge.sendMousePress(AWTInputEvent.BUTTON3_DOWN_MASK, isDown); break; } + if(isDown) switch(v.getId()) { + case R.id.installmod_window_moveup: + AWTInputBridge.nativeMoveWindow(0, -10); + break; + case R.id.installmod_window_movedown: + AWTInputBridge.nativeMoveWindow(0, 10); + break; + case R.id.installmod_window_moveleft: + AWTInputBridge.nativeMoveWindow(-10, 0); + break; + case R.id.installmod_window_moveright: + AWTInputBridge.nativeMoveWindow(10, 0); + break; + } return true; } diff --git a/app_pojavlauncher/src/main/jni/awt_bridge.c b/app_pojavlauncher/src/main/jni/awt_bridge.c index da62f03fd..ff1330dff 100644 --- a/app_pojavlauncher/src/main/jni/awt_bridge.c +++ b/app_pojavlauncher/src/main/jni/awt_bridge.c @@ -13,6 +13,15 @@ jmethodID method_GetRGB; jclass class_CTCAndroidInput; jmethodID method_ReceiveInput; +jclass class_Frame; +jclass class_Rectangle; +jmethodID constructor_Rectangle; +jmethodID method_GetFrames; +jmethodID method_GetBounds; +jmethodID method_SetBounds; +jfieldID field_x; +jfieldID field_y; + jint JNI_OnLoad(JavaVM* vm, void* reserved) { if (dalvikJavaVMPtr == NULL) { //Save dalvik global JavaVM pointer @@ -126,3 +135,36 @@ Java_net_kdt_pojavlaunch_AWTInputBridge_nativePutClipboard(JNIEnv *env, jclass c (*runtimeJNIEnvPtr_CLIPBOARD)->DeleteLocalRef(runtimeJNIEnvPtr_CLIPBOARD,stringSelection); (*runtimeJNIEnvPtr_CLIPBOARD)->DeleteLocalRef(runtimeJNIEnvPtr_CLIPBOARD,o_stringSelection); } + +JNIEXPORT void JNICALL +Java_net_kdt_pojavlaunch_AWTInputBridge_nativeMoveWindow(JNIEnv *env, jclass clazz, jint xoff, jint yoff) { + if (runtimeJNIEnvPtr_INPUT == NULL) { + if (runtimeJavaVMPtr == NULL) { + return; + } else { + (*runtimeJavaVMPtr)->AttachCurrentThread(runtimeJavaVMPtr, &runtimeJNIEnvPtr_INPUT, NULL); + } + } + if(field_y == NULL) { + class_Frame = (*runtimeJNIEnvPtr_INPUT)->FindClass(runtimeJNIEnvPtr_INPUT, "java/awt/Frame"); + method_GetFrames = (*runtimeJNIEnvPtr_INPUT)->GetStaticMethodID(runtimeJNIEnvPtr_INPUT, class_Frame, "getFrames", "()[Ljava/awt/Frame;"); + method_GetBounds = (*runtimeJNIEnvPtr_INPUT)->GetMethodID(runtimeJNIEnvPtr_INPUT, class_Frame, "getBounds", "(Ljava/awt/Rectangle;)Ljava/awt/Rectangle;"); + method_SetBounds = (*runtimeJNIEnvPtr_INPUT)->GetMethodID(runtimeJNIEnvPtr_INPUT, class_Frame, "setBounds", "(Ljava/awt/Rectangle;)V"); + class_Rectangle = (*runtimeJNIEnvPtr_INPUT)->FindClass(runtimeJNIEnvPtr_INPUT, "java/awt/Rectangle"); + constructor_Rectangle = (*runtimeJNIEnvPtr_INPUT)->GetMethodID(runtimeJNIEnvPtr_INPUT, class_Rectangle, "", "()V"); + field_x = (*runtimeJNIEnvPtr_INPUT)->GetFieldID(runtimeJNIEnvPtr_INPUT, class_Rectangle, "x", "I"); + field_y = (*runtimeJNIEnvPtr_INPUT)->GetFieldID(runtimeJNIEnvPtr_INPUT, class_Rectangle, "y", "I"); + } + jobject rectangle = (*runtimeJNIEnvPtr_INPUT)->NewObject(runtimeJNIEnvPtr_INPUT, class_Rectangle, constructor_Rectangle); + jobjectArray frames = (*runtimeJNIEnvPtr_INPUT)->CallStaticObjectMethod(runtimeJNIEnvPtr_INPUT, class_Frame, method_GetFrames); + for(jsize i = 0; i < (*runtimeJNIEnvPtr_INPUT)->GetArrayLength(runtimeJNIEnvPtr_INPUT, frames); i++) { + jobject frame = (*runtimeJNIEnvPtr_INPUT)->GetObjectArrayElement(runtimeJNIEnvPtr_INPUT, frames, i); + (*runtimeJNIEnvPtr_INPUT)->CallObjectMethod(runtimeJNIEnvPtr_INPUT, frame, method_GetBounds, rectangle); + (*runtimeJNIEnvPtr_INPUT)->SetIntField(runtimeJNIEnvPtr_INPUT, rectangle, field_x, (*runtimeJNIEnvPtr_INPUT)->GetIntField(runtimeJNIEnvPtr_INPUT, rectangle, field_x) + xoff); + (*runtimeJNIEnvPtr_INPUT)->SetIntField(runtimeJNIEnvPtr_INPUT, rectangle, field_y, (*runtimeJNIEnvPtr_INPUT)->GetIntField(runtimeJNIEnvPtr_INPUT, rectangle, field_y) + yoff); + (*runtimeJNIEnvPtr_INPUT)->CallVoidMethod(runtimeJNIEnvPtr_INPUT, frame, method_SetBounds, rectangle); + (*runtimeJNIEnvPtr_INPUT)->DeleteLocalRef(runtimeJNIEnvPtr_INPUT, frame); + } + (*runtimeJNIEnvPtr_INPUT)->DeleteLocalRef(runtimeJNIEnvPtr_INPUT, rectangle); + (*runtimeJNIEnvPtr_INPUT)->DeleteLocalRef(runtimeJNIEnvPtr_INPUT, frames); +} diff --git a/app_pojavlauncher/src/main/res/layout/activity_java_gui_launcher.xml b/app_pojavlauncher/src/main/res/layout/activity_java_gui_launcher.xml index 90b1cb971..3863b1469 100644 --- a/app_pojavlauncher/src/main/res/layout/activity_java_gui_launcher.xml +++ b/app_pojavlauncher/src/main/res/layout/activity_java_gui_launcher.xml @@ -116,6 +116,48 @@ app:layout_constraintLeft_toRightOf="@id/installmod_mouse_pri" app:layout_constraintStart_toStartOf="parent" /> +