Skip to content

feat: Add spacebar language-swipe sensitivity setting - #2131

Open
skorokithakis wants to merge 2 commits into
futo-org:masterfrom
skorokithakis:feat/spacebar-language-swipe-sensitivity
Open

feat: Add spacebar language-swipe sensitivity setting#2131
skorokithakis wants to merge 2 commits into
futo-org:masterfrom
skorokithakis:feat/spacebar-language-swipe-sensitivity

Conversation

@skorokithakis

Copy link
Copy Markdown

The spacebar language-switch swipe used a hardcoded 128dp step. I exposed it as an adjustable distance on the Spacebar settings screen with an 128dp default.

The spacebar language-switch swipe used a hardcoded 128dp step. Expose
it as an adjustable distance on the Spacebar settings screen; the
default keeps the original behaviour.
@FarisZR

FarisZR commented Jun 27, 2026

Copy link
Copy Markdown

i think this has a weird edge case though, it's possible to change layouts multiple times in one swipe.
i think most users will only ever want it to change one layout per swipe, and still want it to get triggered really easily.

Because now I either have a low enough sensitivity so that never happens (but that's a trade-off because i can't make it trigger as fast as i want) or i just have to not swipe for too long.

@skorokithakis

Copy link
Copy Markdown
Author

Ahh you're right, thanks, I'll test and make it only switch once.

@FarisZR

FarisZR commented Jun 27, 2026

Copy link
Copy Markdown

this patch makes it work as a latch, so that it only switches one layout at time

diff --git a/java/src/org/futo/inputmethod/keyboard/PointerTracker.java b/java/src/org/futo/inputmethod/keyboard/PointerTracker.java
--- a/java/src/org/futo/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/org/futo/inputmethod/keyboard/PointerTracker.java
@@ -156,6 +156,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
     private boolean mStartedOnFastLongPress;
     private boolean mCursorMoved = false;
     private boolean mSpacebarLongPressed = false;
+    private boolean mSpacebarLanguageSwipeTriggered = false;
 
     // true if keyboard layout has been changed.
     private boolean mKeyboardLayoutHasBeenChanged;
@@ -757,6 +758,7 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
             mStartTime = System.currentTimeMillis();
             mStartedOnFastLongPress = key.isFastLongPress();
             mSpacebarLongPressed = false;
+            mSpacebarLanguageSwipeTriggered = false;
 
             mIsSlidingCursor = key.getCode() == Constants.CODE_DELETE || key.getCode() == Constants.CODE_SPACE;
             mIsFlickingKey = !mIsSlidingCursor && key.getHasFlick();
@@ -973,28 +975,36 @@ public final class PointerTracker implements PointerTrackerQueue.Element,
                         || (!mSpacebarLongPressed && settingsValues.mSpacebarSwipeMode != Settings.SPACEBAR_MODE_OFF);
 
             if(allowedBySettings) {
+                final boolean isLanguageSwipe = settingsValues.mSpacebarSwipeMode == Settings.SPACEBAR_MODE_LANGUAGE
+                        && !mSpacebarLongPressed;
                 int pointerStep = sPointerStep;
-                if (settingsValues.mSpacebarSwipeMode == Settings.SPACEBAR_MODE_LANGUAGE && !mSpacebarLongPressed) {
+                if (isLanguageSwipe) {
                     // The language-switch step distance is user-configurable in dp. The
                     // widthPixels*3/2 clamp is a safety bound for narrow screens.
                     final DisplayMetrics displayMetrics =
                             Resources.getSystem().getDisplayMetrics();
                     pointerStep = Integer.min(
                             (int)(settingsValues.mSpacebarLanguageSwipeStepDp * displayMetrics.density),
                             displayMetrics.widthPixels * 3 / 2
                     );
                 }
 
                 int steps = (x - mStartX) / pointerStep;
                 final int swipeIgnoreTime = settingsValues.mKeyLongpressTimeout / MULTIPLIER_FOR_LONG_PRESS_TIMEOUT_IN_SLIDING_INPUT;
                 if (steps != 0 && mStartTime + swipeIgnoreTime < System.currentTimeMillis()) {
-                    mCursorMoved = true;
-                    mStartX += steps * pointerStep;
-
-                    if (settingsValues.mSpacebarSwipeMode == Settings.SPACEBAR_MODE_LANGUAGE && !mSpacebarLongPressed) {
-                        sListener.onSwipeLanguage(steps);
+                    if (isLanguageSwipe) {
+                        if (!mSpacebarLanguageSwipeTriggered) {
+                            mCursorMoved = true;
+                            mSpacebarLanguageSwipeTriggered = true;
+                            sListener.onSwipeLanguage(steps > 0 ? 1 : -1);
+                        }
                     } else {
+                        mCursorMoved = true;
+                        mStartX += steps * pointerStep;
                         sListener.onMovePointer(steps);
                     }
                 }

@skorokithakis

Copy link
Copy Markdown
Author

I've implemented the gating on a single language. I'm not sure what the original intent was (to be able to switch multiple languages or not), but it seems more confusing to be able to switch more than one language, so I've added the constraint here, especially since the added sensitivity makes it very easy to overshoot.

@abb128

abb128 commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Do you think it would make more sense to adjust the default rather than adding an option for this? It feels like it would be a strangely specific setting

@skorokithakis

Copy link
Copy Markdown
Author

Depends on how the maintainers want it.

@abb128

abb128 commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

@skorokithakis @FarisZR What values have you guys settled on for the setting?

@skorokithakis

Copy link
Copy Markdown
Author

72 DPI for me.

@FarisZR

FarisZR commented Jun 29, 2026 via email

Copy link
Copy Markdown

@abb128

abb128 commented Jun 29, 2026

Copy link
Copy Markdown
Collaborator

Please try nightly 0.1.29.1-3-g9f05e86ac and tell me what you think. I added some visual and haptic feedback, made the switch more instantaneous, and reduced the threshold to 64dp

@FarisZR

FarisZR commented Jun 30, 2026 via email

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants