Skip to content

Commit 4b0ccec

Browse files
authored
Merge pull request AngelAuraMC#67 from AngelAuraMC/fix/revert-forced-grabbing
fix(Pointer): Simplify code, fix AngelAuraMC#58..again
2 parents 3a8db25 + 4c7098a commit 4b0ccec

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/mouse/AndroidPointerCapture.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,42 +40,40 @@ public AndroidPointerCapture(AbstractTouchpad touchpad, View hostView) {
4040
hostView.setOnCapturedPointerListener(this);
4141
hostView.getViewTreeObserver().addOnWindowFocusChangeListener(this);
4242
DEFAULT_PREF.registerOnSharedPreferenceChangeListener(this);
43-
if (!PREF_MOUSE_GRAB_FORCE)
44-
CallbackBridge.addGrabListener(this);
43+
CallbackBridge.addGrabListener(this);
4544
}
4645

46+
/**
47+
* Checks whether or not the touchpad is already enabled and if user prefers virtual cursor
48+
* if they don't, the touchpad is not enabled
49+
*/
4750
private void enableTouchpadIfNecessary() {
4851
if(!mTouchpad.getDisplayState() && PREF_MOUSE_GRAB_FORCE) mTouchpad.enable(true);
4952
}
5053

5154
// Needed so it releases the cursor when inside game menu
5255
@Override
5356
public void onGrabState(boolean isGrabbing) {
54-
updateCursorState(isGrabbing);
57+
handleAutomaticCapture();
5558
}
5659
// It's only here so the side-dialog changes it live
5760
@Override
5861
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, @Nullable String key) {
59-
updateCursorState(CallbackBridge.isGrabbing());
60-
}
61-
private void updateCursorState(boolean isGrabbing) {
62-
if (!isGrabbing // Only capture if not in menu and user said so
63-
&& !PREF_MOUSE_GRAB_FORCE) {
64-
mHostView.releasePointerCapture(); // Release the capture since user said so
65-
}
66-
// Capture the pointer when not inside a menu
67-
// So user doesn't have to click to get rid of cursor
62+
if (sharedPreferences.getBoolean("always_grab_mouse", true)){
63+
enableTouchpadIfNecessary();
64+
} else mTouchpad.disable();
6865
handleAutomaticCapture();
6966
}
7067

7168
public void handleAutomaticCapture() {
72-
if (!CallbackBridge.isGrabbing() // Only capture if not in menu and user said so
69+
// isGrabbing checks for whether we are in menu
70+
if (!CallbackBridge.isGrabbing()
7371
&& !PREF_MOUSE_GRAB_FORCE) {
72+
mHostView.releasePointerCapture();
7473
return;
7574
}
7675
if (mHostView.hasPointerCapture()) {
7776
enableTouchpadIfNecessary();
78-
return;
7977
}
8078
if (!mHostView.hasWindowFocus()) {
8179
mHostView.requestFocus();

0 commit comments

Comments
 (0)