Skip to content

Commit

Permalink
avoid getting stuck after one full round
Browse files Browse the repository at this point in the history
now doing a full round in language swipe is not allowed any more
  • Loading branch information
Helium314 authored Feb 2, 2025
1 parent 18283df commit 1815bbb
Showing 1 changed file with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package helium314.keyboard.keyboard

import android.view.KeyEvent
import android.view.inputmethod.InputMethodSubtype
import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode
import helium314.keyboard.latin.LatinIME
import helium314.keyboard.latin.RichInputMethodManager
Expand All @@ -17,9 +18,12 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp

private val keyboardSwitcher = KeyboardSwitcher.getInstance()
private val settings = Settings.getInstance()
private var mSubtypeSwitchCount = 0 // for use with onLanguageSlide()
private var metaState = 0 // is this enough, or are there threading issues with the different PointerTrackers?

// language slide state
private var initialSubtype: InputMethodSubtype? = null
private var subtypeSwitchCount = 0

// todo: maybe keep meta state presses to KeyboardActionListenerImpl, and avoid calls to press/release key
private fun adjustMetaState(code: Int, remove: Boolean) {
val metaCode = when (code) {
Expand Down Expand Up @@ -86,7 +90,8 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp
}

override fun onEndSpaceSwipe(){
mSubtypeSwitchCount = 0
initialSubtype = null
subtypeSwitchCount = 0
}

override fun toggleNumpad(withSliding: Boolean, forceReturnToAlpha: Boolean): Boolean {
Expand Down Expand Up @@ -131,7 +136,7 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp
private fun onLanguageSlide(steps: Int): Boolean {
if (abs(steps) < settings.current.mLanguageSwipeDistance) return false
val subtypes = RichInputMethodManager.getInstance().getMyEnabledInputMethodSubtypeList(false)
if (subtypes.size - 1 <= abs(mSubtypeSwitchCount)) { // only allow if we are yet to cycle through all subtypes
if (subtypes.size <= 1) { // only allow if we have more than one subtype
return false
}
// decide next or previous dependent on up or down
Expand All @@ -140,8 +145,18 @@ class KeyboardActionListenerImpl(private val latinIME: LatinIME, private val inp
wantedIndex %= subtypes.size
if (wantedIndex < 0)
wantedIndex += subtypes.size
KeyboardSwitcher.getInstance().switchToSubtype(subtypes[wantedIndex])
if (steps > 0) mSubtypeSwitchCount++ else mSubtypeSwitchCount--
val newSubtype = subtypes[wantedIndex]

// do not switch if we would switch to the initial subtype after cycling all other subtypes
if (initialSubtype == null)
initialSubtype = current
if (initialSubtype == newSubtype) {
if ((subtypeSwitchCount > 0 && steps > 0) || ((subtypeSwitchCount < 0 && steps < 0)))
return true
}
if (steps > 0) subtypeSwitchCount++ else subtypeSwitchCount--

KeyboardSwitcher.getInstance().switchToSubtype(newSubtype)
return true
}

Expand Down

0 comments on commit 1815bbb

Please sign in to comment.