From 089c9f6c8cd42b34b5b67838a8ec3fda21868ed5 Mon Sep 17 00:00:00 2001 From: downthecrop Date: Tue, 7 Nov 2023 20:41:50 -0800 Subject: [PATCH 1/7] Respect autoenabled virtual mouse --- .../pojavlaunch/JavaGUILauncherActivity.java | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) 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 00408dc406..fce4051de2 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/JavaGUILauncherActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/JavaGUILauncherActivity.java @@ -91,6 +91,8 @@ protected void onCreate(Bundle savedInstanceState) { ViewGroup.LayoutParams params = mMousePointerImageView.getLayoutParams(); params.width = (int) (36 / 100f * LauncherPreferences.PREF_MOUSESCALE); params.height = (int) (54 / 100f * LauncherPreferences.PREF_MOUSESCALE); + if(LauncherPreferences.PREF_VIRTUAL_MOUSE_START) + toggleVirtualMouse(); }); mTouchPad.setOnTouchListener(new View.OnTouchListener() { @@ -120,8 +122,8 @@ public boolean onTouch(View v, MotionEvent event) { } } else { if (action == MotionEvent.ACTION_MOVE) { // 2 - mouseX = Math.max(0, Math.min(currentDisplayMetrics.widthPixels, mouseX + (x - prevX) * LauncherPreferences.PREF_MOUSESPEED)); - mouseY = Math.max(0, Math.min(currentDisplayMetrics.heightPixels, mouseY + (y - prevY) * LauncherPreferences.PREF_MOUSESPEED)); + mouseX = Math.max(0, Math.min(currentDisplayMetrics.widthPixels, mouseX + (x - prevX) * mouseSpeed)); + mouseY = Math.max(0, Math.min(currentDisplayMetrics.heightPixels, mouseY + (y - prevY) * mouseSpeed)); placeMouseAt(mouseX, mouseY); sendScaledMousePosition(mouseX, mouseY); } @@ -130,8 +132,6 @@ public boolean onTouch(View v, MotionEvent event) { if (event.getPointerCount() == 2) { // Right-click event when a second finger touches the screen // Simulating right-click by sending GLFW_MOUSE_BUTTON_RIGHT event - Log.i("downthecrop","Hi from a rightclick event!"); - //activateRC(); AWTInputBridge.sendKey((char)AWTInputEvent.VK_F11,AWTInputEvent.VK_F11); AWTInputBridge.sendMousePress(AWTInputEvent.BUTTON1_DOWN_MASK); } @@ -203,14 +203,6 @@ public boolean onTouch(View v, MotionEvent event) { } catch (Throwable th) { Tools.showError(this, th, true); } - - - getOnBackPressedDispatcher().addCallback(new OnBackPressedCallback(true) { - @Override - public void handleOnBackPressed() { - MainActivity.dialogForceClose(JavaGUILauncherActivity.this); - } - }); } @Override @@ -261,7 +253,6 @@ public boolean onTouch(View v, MotionEvent e) { // these AWTInputEvent doesn't w break; case R.id.camera: if (!cameraMode) { // Camera Mode On - Log.i("downthecrop", "Hello from the camrea Button"); AWTInputBridge.sendKey((char) AWTInputEvent.VK_F9, AWTInputEvent.VK_F9); // Send F9 cameraMode = true; findViewById(R.id.camera).setBackground(getResources().getDrawable( R.drawable.control_button_pressed )); @@ -272,7 +263,7 @@ public boolean onTouch(View v, MotionEvent e) { // these AWTInputEvent doesn't w } break; case R.id.mouseMode: - toggleVirtualMouse(this.getCurrentFocus()); + toggleVirtualMouse(); } lastPress = time; } @@ -320,7 +311,7 @@ public void openLogOutput(View v) { mLoggerView.setVisibility(View.VISIBLE); } - public void toggleVirtualMouse(View v) { + public void toggleVirtualMouse() { mIsVirtualMouseEnabled = !mIsVirtualMouseEnabled; ImageView view = findViewById(R.id.mouseModeIco); if(!mIsVirtualMouseEnabled){ From f97451fc3d6bf3fecfb4b8c329ce7691c6a4fed9 Mon Sep 17 00:00:00 2001 From: downthecrop Date: Tue, 7 Nov 2023 23:33:42 -0800 Subject: [PATCH 2/7] Swipe cam for SD + Start init of dragclick/longpress --- .../pojavlaunch/JavaGUILauncherActivity.java | 60 ++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) 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 fce4051de2..3572605f73 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/JavaGUILauncherActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/JavaGUILauncherActivity.java @@ -3,6 +3,8 @@ import static net.kdt.pojavlaunch.MainActivity.fullyExit; import static net.kdt.pojavlaunch.Tools.currentDisplayMetrics; +import static java.security.AccessController.getContext; + import android.annotation.SuppressLint; import android.content.ClipboardManager; import android.graphics.Color; @@ -46,9 +48,13 @@ public class JavaGUILauncherActivity extends BaseActivity implements View.OnTouc private TouchCharInput mTouchCharInput; private LinearLayout mTouchPad; + boolean isDragClicking = false; private ImageView mMousePointerImageView; private GestureDetector mGestureDetector; + + private GestureDetector longPressDetector; private boolean cameraMode = false; + float prevX = 0, prevY = 0; private long lastPress = 0; private ScaleGestureDetector scaleGestureDetector; private boolean rcState = false; @@ -96,7 +102,6 @@ protected void onCreate(Bundle savedInstanceState) { }); mTouchPad.setOnTouchListener(new View.OnTouchListener() { - float prevX = 0, prevY = 0; @Override public boolean onTouch(View v, MotionEvent event) { // MotionEvent reports input details from the touch screen @@ -137,6 +142,7 @@ public boolean onTouch(View v, MotionEvent event) { } } } + longPressDetector.onTouchEvent(event); prevY = y; prevX = x; @@ -146,6 +152,7 @@ public boolean onTouch(View v, MotionEvent event) { mTextureView.setOnTouchListener((v, event) -> { scaleGestureDetector.onTouchEvent(event); + longPressDetector.onTouchEvent(event); float x = event.getX(); float y = event.getY(); if (mGestureDetector.onTouchEvent(event)) { @@ -164,11 +171,40 @@ public boolean onTouch(View v, MotionEvent event) { break; case MotionEvent.ACTION_MOVE: // 2 sendScaledMousePosition(x + mTextureView.getX(), y); + try { + panCamera(prevX-x, prevY-y); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } break; } + + prevY = y; + prevX = x; return true; }); + longPressDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() { + @Override + public void onLongPress(MotionEvent e) { + super.onLongPress(e); + Log.i("downthecrop","Hi from a long press!"); + if(!isDragClicking) { + isDragClicking = true; + //AWTInputBridge.sendKey((char) AWTInputEvent.VK_F5, AWTInputEvent.VK_F5); + } + } + + @Override + public boolean onSingleTapUp(MotionEvent e) { + if(isDragClicking) { + isDragClicking = false; + //AWTInputBridge.sendKey((char)AWTInputEvent.VK_F5, AWTInputEvent.VK_F5); + } + return super.onSingleTapUp(e); + } + }); + try { placeMouseAt(CallbackBridge.physicalWidth / 2f, CallbackBridge.physicalHeight / 2f); @@ -205,6 +241,28 @@ public boolean onTouch(View v, MotionEvent event) { } } + private void panCamera(float dx, float dy) throws InterruptedException { + //Log.i("downthecrop-pan","dx: " +dx + " dy: " + dy); + final float threshold = 8.0f; // adjust this value as needed to control the sensitivity of the panning + + // Check horizontal panning + if(dx > threshold) { + // Finger moved to the right, pan camera to the right + AWTInputBridge.sendKey((char)AWTInputEvent.VK_RIGHT, AWTInputEvent.VK_RIGHT); + } else if(dx < -threshold) { + AWTInputBridge.sendKey((char)AWTInputEvent.VK_LEFT, AWTInputEvent.VK_LEFT); + } + + // Check vertical panning + if(dy > threshold) { + // Finger moved down, pan camera up + AWTInputBridge.sendKey((char)AWTInputEvent.VK_UP, AWTInputEvent.VK_UP); + } else if(dy < -threshold) { + // Finger moved up, pan camera down + AWTInputBridge.sendKey((char)AWTInputEvent.VK_DOWN, AWTInputEvent.VK_DOWN); + } + } + @Override public void onResume() { super.onResume(); From 668660e13ea463d0776ca0b2d957b41333534467 Mon Sep 17 00:00:00 2001 From: downthecrop Date: Thu, 30 Nov 2023 00:55:47 -0800 Subject: [PATCH 3/7] I'm guessing this was here for debug.. but why?.. anyway removing it --- .../src/main/java/net/kdt/pojavlaunch/utils/KeyEncoder.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/KeyEncoder.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/KeyEncoder.java index 25884bf743..c3f26b3e73 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/KeyEncoder.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/KeyEncoder.java @@ -23,9 +23,7 @@ public class KeyEncoder { public static void sendEncodedChar(int keyCode, char iC){ System.out.println(keyCode); - if(keyCode == 75) - AWTInputBridge.sendKey((char)222,222); - else if(keyCode == backspaceAndroid){ + if(keyCode == backspaceAndroid){ AWTInputBridge.sendKey(backspaceUnicode,backspaceUnicode); } else if(specialChars.contains(""+iC)){ // Send special character to client From 5330ad05effaa215a1f2b7596bd4caacadf6b515 Mon Sep 17 00:00:00 2001 From: downthecrop Date: Thu, 30 Nov 2023 01:35:48 -0800 Subject: [PATCH 4/7] Release 2.2 --- .../src/main/assets/plugins/XPDropPlugin.zip | Bin 6732 -> 0 bytes .../net/kdt/pojavlaunch/GLFWGLSurface.java | 24 +++--------------- .../pojavlaunch/JavaGUILauncherActivity.java | 13 +++------- 3 files changed, 7 insertions(+), 30 deletions(-) delete mode 100644 app_pojavlauncher/src/main/assets/plugins/XPDropPlugin.zip diff --git a/app_pojavlauncher/src/main/assets/plugins/XPDropPlugin.zip b/app_pojavlauncher/src/main/assets/plugins/XPDropPlugin.zip deleted file mode 100644 index c7686e153a6af37297a73c088f26e34e275d0e66..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6732 zcmZ{pWl$W<)^2epIKhIuyA19O?hF=!yE`Nhg1ZJ7g1dW=!F7VWy96C9cnI+2eCOV} zb>2F+yKC>NuCC|js;;#)RS=N~;o#uV;53SI^+N6PE-;Yc;E*xk;HdxJf;8nkT-`LC zylw4WxZM7?(StM<&Fx({EuG9gJ>&JaGzbj{U(R8$bMB7qde|>=`4Vr#UgYK$JwhV3 zI8!&w^upy~_)>1(ai_yce6_6Mn?A|DL7}-~AeCP|aHyCOd#LqAOKmC#T#JUu6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Ee;ESP+WYY0|qges%Mt=uGN`kyb6$b_iw8-=zYMa3cj4!;#;JTPw$#m@UsW>ArH& zfGoMo`zNmEfoSbg^mnD@)rev z7xn+ve^BASj9LDf_D{X|@0fq3DgEWle;L~R8!-Qj`6rzIUyK&fKVtrYDoqt+lz+WO P{JXdQc7uOOPPqR8O Date: Thu, 30 Nov 2023 01:59:41 -0800 Subject: [PATCH 5/7] Longpress rc should only be active in touch mode --- .../main/java/net/kdt/pojavlaunch/JavaGUILauncherActivity.java | 1 - 1 file changed, 1 deletion(-) 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 a1b8f30f64..1c781ff627 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/JavaGUILauncherActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/JavaGUILauncherActivity.java @@ -141,7 +141,6 @@ public boolean onTouch(View v, MotionEvent event) { } } } - longPressDetector.onTouchEvent(event); prevY = y; prevX = x; From fa697c6a757a4d13194d19e5119b0e5493ea8959 Mon Sep 17 00:00:00 2001 From: downthecrop Date: Sun, 17 Dec 2023 01:34:13 -0800 Subject: [PATCH 6/7] Keycode 67 handling --- .../keyboard/TouchCharInput.java | 5 +- .../net/kdt/pojavlaunch/utils/KeyEncoder.java | 148 ++++++------------ 2 files changed, 54 insertions(+), 99 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/keyboard/TouchCharInput.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/keyboard/TouchCharInput.java index 8011684c25..f9b14b3008 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/keyboard/TouchCharInput.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/keyboard/TouchCharInput.java @@ -23,6 +23,7 @@ */ public class TouchCharInput extends androidx.appcompat.widget.AppCompatEditText { public static final String TEXT_FILLER = " "; + public static boolean softKeyboardIsActive = false; public TouchCharInput(@NonNull Context context) { this(context, null); } @@ -49,7 +50,7 @@ protected void onTextChanged(CharSequence text, int start, int lengthBefore, int Log.i("TouchCharInput","New Event (before/after)!: "+ lengthBefore + " : " + lengthAfter); boolean isBackSpace = (lengthBefore > lengthAfter); if(isBackSpace) { - KeyEncoder.sendEncodedChar(KeyEncoder.backspaceUnicode,KeyEncoder.backspaceUnicode); + KeyEncoder.sendUnicodeBackspace(); return; } char c = text.charAt(text.length()-1); @@ -115,6 +116,7 @@ public void clear(){ /** Regain ability to exist, take focus and have some text being input */ public void enable(){ + softKeyboardIsActive = true; setEnabled(true); setFocusable(true); setVisibility(VISIBLE); @@ -123,6 +125,7 @@ public void enable(){ /** Lose ability to exist, take focus and have some text being input */ public void disable(){ + softKeyboardIsActive = false; clear(); setVisibility(GONE); clearFocus(); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/KeyEncoder.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/KeyEncoder.java index c3f26b3e73..4cfaf3da66 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/KeyEncoder.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/KeyEncoder.java @@ -1,110 +1,62 @@ package net.kdt.pojavlaunch.utils; import net.kdt.pojavlaunch.AWTInputBridge; +import net.kdt.pojavlaunch.customcontrols.keyboard.TouchCharInput; -/* - About Key Events. Because the Android Spec doesn't require - soft keyboards to dispatch key events not all keyboard implementations - across Android will trigger these actions. +import java.util.HashMap; +import java.util.Map; - Currently we use the following function to translate keycodes for - special character, capital letters, and digits. +public class KeyEncoder { - keycode 123 (F12) is used as a single digit capslock button which - when sent to the miniclient before a char will act accordingly. - */ + private static final Map specialCharMap = createSpecialCharMap(); + private static final char MODIFIER = 123; // F12 key as a modifier for caps lock + private static final char BACKSPACE_ANDROID = 67; + private static final char BACKSPACE_UNICODE = 8; -public class KeyEncoder { + // Initialize the mapping of special characters to their respective keys + private static Map createSpecialCharMap() { + Map map = new HashMap<>(); + map.put('!', '1'); + map.put('@', '2'); + map.put('#', '3'); + map.put('$', '4'); + map.put('%', '5'); + map.put('^', '6'); + map.put('&', '7'); + map.put('*', '8'); + map.put('(', '9'); + map.put(')', '0'); + map.put('_', '-'); + map.put('+', '='); + map.put('{', '['); + map.put('}', ']'); + map.put(':', ';'); + map.put('"', '\''); + map.put('<', ','); + map.put('>', '.'); + map.put('?', '/'); + map.put('|', '\\'); + return map; + } - static String specialChars = "/*!@#$%^&*()\"{}_[+:;=-_]'|\\?/<>,."; - static char modifier = 123; - static char backspaceAndroid = 67; - public static char backspaceUnicode = 8; + public static void sendUnicodeBackspace(){ + AWTInputBridge.sendKey(BACKSPACE_UNICODE, BACKSPACE_UNICODE); + } - public static void sendEncodedChar(int keyCode, char iC){ - System.out.println(keyCode); - if(keyCode == backspaceAndroid){ - AWTInputBridge.sendKey(backspaceUnicode,backspaceUnicode); - } else if(specialChars.contains(""+iC)){ - // Send special character to client - char c = iC; - switch(c){ - case '!': - c = '1'; - break; - case '@': - c = '2'; - break; - case '#': - c = '3'; - break; - case '$': - c = '4'; - break; - case '%': - c = '5'; - break; - case '^': - c = '6'; - break; - case '&': - c = '7'; - break; - case '*': - c = '8'; - break; - case '(': - c = '9'; - break; - case ')': - c = '0'; - break; - case '_': - c = '-'; - break; - case '+': - c = '='; - break; - case '{': - c = '['; - break; - case '}': - c = ']'; - break; - case ':': - c = ';'; - break; - case '"': - c = '\''; - break; - case '<': - c = ','; - break; - case '>': - c = '.'; - break; - case '?': - c = '/'; - break; - case '|': - c = '\\'; - break; - } - if(c != iC){ - AWTInputBridge.sendKey(modifier,modifier); - } - AWTInputBridge.sendKey(c,c); - } else if(Character.isDigit(iC)){ - AWTInputBridge.sendKey(iC,iC); - } else if (iC == Character.toUpperCase(iC)){ - // We send F12 as a modifier to avoid needing to worry about shift. - // Client takes this modifier and does a toUpperCase(). - AWTInputBridge.sendKey(modifier,modifier); - AWTInputBridge.sendKey(Character.toUpperCase(iC),Character.toUpperCase(iC)); - } else if(iC == Character.toLowerCase(iC)){ - AWTInputBridge.sendKey(Character.toUpperCase(iC),Character.toUpperCase(iC)); + public static void sendEncodedChar(int keyCode, char c) { + if (keyCode == BACKSPACE_ANDROID && !TouchCharInput.softKeyboardIsActive) { + sendUnicodeBackspace(); + } else if (specialCharMap.containsKey(c)) { + AWTInputBridge.sendKey(specialCharMap.get(c), specialCharMap.get(c)); + } else if (Character.isDigit(c)) { + AWTInputBridge.sendKey(c, c); + } else if (Character.isLowerCase(c)){ + AWTInputBridge.sendKey(Character.toUpperCase(c),Character.toUpperCase(c)); + } else if (Character.isUpperCase(c)) { + AWTInputBridge.sendKey(MODIFIER, MODIFIER); + AWTInputBridge.sendKey(c, c); } else { - AWTInputBridge.sendKey(iC,keyCode); + AWTInputBridge.sendKey(c, keyCode); } } -} \ No newline at end of file +} From 5270adf48f376c90101fea01246e1c381ac9fdda Mon Sep 17 00:00:00 2001 From: downthecrop Date: Sun, 17 Dec 2023 01:52:32 -0800 Subject: [PATCH 7/7] regession in special character sending --- .../src/main/java/net/kdt/pojavlaunch/utils/KeyEncoder.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/KeyEncoder.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/KeyEncoder.java index 4cfaf3da66..b5c7ca95a2 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/KeyEncoder.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/utils/KeyEncoder.java @@ -47,6 +47,7 @@ public static void sendEncodedChar(int keyCode, char c) { if (keyCode == BACKSPACE_ANDROID && !TouchCharInput.softKeyboardIsActive) { sendUnicodeBackspace(); } else if (specialCharMap.containsKey(c)) { + AWTInputBridge.sendKey(MODIFIER, MODIFIER); AWTInputBridge.sendKey(specialCharMap.get(c), specialCharMap.get(c)); } else if (Character.isDigit(c)) { AWTInputBridge.sendKey(c, c);