diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MainActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MainActivity.java index 885ace85f..c31a20d41 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MainActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/MainActivity.java @@ -501,6 +501,10 @@ public class MainActivity extends BaseActivity implements ControlButtonMenuListe Tools.runOnUiThread(()-> mServiceBinder.isActive = false); } + public void setmLastIndex(int a){ + mHotbarView.setmLastIndex(a); + } + private void dialogSendCustomKey() { AlertDialog.Builder dialog = new AlertDialog.Builder(this); dialog.setTitle(R.string.control_customkey); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/HotbarView.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/HotbarView.java index b969fc83a..837a82abc 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/HotbarView.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/HotbarView.java @@ -97,6 +97,10 @@ public class HotbarView extends View implements MCOptionUtils.MCOptionListener, setLayoutParams(marginLayoutParams); } + public void setmLastIndex(int mLastIndex) { + this.mLastIndex = mLastIndex; + } + @SuppressWarnings("ClickableViewAccessibility") // performClick does not report coordinates. @Override public boolean onTouchEvent(MotionEvent event) { diff --git a/app_pojavlauncher/src/main/java/org/lwjgl/glfw/CallbackBridge.java b/app_pojavlauncher/src/main/java/org/lwjgl/glfw/CallbackBridge.java index 27248358e..358bde995 100644 --- a/app_pojavlauncher/src/main/java/org/lwjgl/glfw/CallbackBridge.java +++ b/app_pojavlauncher/src/main/java/org/lwjgl/glfw/CallbackBridge.java @@ -8,6 +8,7 @@ import android.content.*; import android.util.DisplayMetrics; import android.util.Log; import android.view.Choreographer; +import android.view.KeyEvent; import android.view.MotionEvent; import androidx.annotation.Keep; @@ -93,6 +94,13 @@ public class CallbackBridge { if(isDown){ SDLActivity.onNativeKeyDown(EfficientAndroidLWJGLKeycode.getAndroidKeycode(keycode)); } else SDLActivity.onNativeKeyUp(EfficientAndroidLWJGLKeycode.getAndroidKeycode(keycode)); + // If not in GUI and pressed a hotbar key, update HotbarView's last index for gesture + // detection. This is still faulty but should be less so. + if (isGrabbing()){ + if (keycode >= LwjglGlfwKeycode.GLFW_KEY_0 && keycode <= LwjglGlfwKeycode.GLFW_KEY_9){ + ((MainActivity) SDLActivity.getContext()).setmLastIndex(keycode - LwjglGlfwKeycode.GLFW_KEY_0); + } + } } public static void sendChar(char keychar, int modifiers){