mirror of
https://gitlab.futo.org/keyboard/latinime.git
synced 2024-09-28 14:54:30 +01:00
Add back ManuallyShifted state
This commit is contained in:
parent
9ac6f233d7
commit
778c973c60
@ -19,6 +19,7 @@ enum class KeyboardLayoutKind {
|
|||||||
enum class KeyboardLayoutPage(val locked: Boolean, val altIdx: Int? = null) {
|
enum class KeyboardLayoutPage(val locked: Boolean, val altIdx: Int? = null) {
|
||||||
Base(true),
|
Base(true),
|
||||||
Shifted(false),
|
Shifted(false),
|
||||||
|
ManuallyShifted(false),
|
||||||
ShiftLocked(true),
|
ShiftLocked(true),
|
||||||
Alt0(false, 0),
|
Alt0(false, 0),
|
||||||
Alt1(false, 1),
|
Alt1(false, 1),
|
||||||
@ -26,28 +27,44 @@ enum class KeyboardLayoutPage(val locked: Boolean, val altIdx: Int? = null) {
|
|||||||
Alt3(false, 3),
|
Alt3(false, 3),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Normalizes to the base page (for shifted variationsu) */
|
||||||
|
fun KeyboardLayoutPage.normalize(): KeyboardLayoutPage =
|
||||||
|
when(this) {
|
||||||
|
KeyboardLayoutPage.ManuallyShifted -> KeyboardLayoutPage.Shifted
|
||||||
|
KeyboardLayoutPage.ShiftLocked -> KeyboardLayoutPage.Shifted
|
||||||
|
else -> this
|
||||||
|
}
|
||||||
|
|
||||||
data class KeyboardLayoutElement(
|
data class KeyboardLayoutElement(
|
||||||
val kind: KeyboardLayoutKind,
|
val kind: KeyboardLayoutKind,
|
||||||
val page: KeyboardLayoutPage
|
val page: KeyboardLayoutPage
|
||||||
) {
|
) {
|
||||||
|
fun normalize(): KeyboardLayoutElement =
|
||||||
|
this.copy(kind = kind, page = page.normalize())
|
||||||
|
|
||||||
val elementId: Int
|
val elementId: Int
|
||||||
get() = when(kind) {
|
get() = when(kind) {
|
||||||
KeyboardLayoutKind.Alphabet -> when(page) {
|
KeyboardLayoutKind.Alphabet -> when(page) {
|
||||||
KeyboardLayoutPage.Base -> KeyboardId.ELEMENT_ALPHABET
|
KeyboardLayoutPage.Base -> KeyboardId.ELEMENT_ALPHABET
|
||||||
KeyboardLayoutPage.Shifted -> KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED
|
KeyboardLayoutPage.Shifted -> KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED
|
||||||
|
KeyboardLayoutPage.ManuallyShifted -> KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED
|
||||||
KeyboardLayoutPage.ShiftLocked -> KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED
|
KeyboardLayoutPage.ShiftLocked -> KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED
|
||||||
else -> KeyboardId.ELEMENT_ALPHABET
|
else -> KeyboardId.ELEMENT_ALPHABET
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyboardLayoutKind.Symbols -> when(page) {
|
KeyboardLayoutKind.Symbols -> when(page) {
|
||||||
KeyboardLayoutPage.Base -> KeyboardId.ELEMENT_SYMBOLS
|
KeyboardLayoutPage.Base -> KeyboardId.ELEMENT_SYMBOLS
|
||||||
KeyboardLayoutPage.Shifted, KeyboardLayoutPage.ShiftLocked -> KeyboardId.ELEMENT_SYMBOLS_SHIFTED
|
KeyboardLayoutPage.Shifted,
|
||||||
|
KeyboardLayoutPage.ManuallyShifted,
|
||||||
|
KeyboardLayoutPage.ShiftLocked -> KeyboardId.ELEMENT_SYMBOLS_SHIFTED
|
||||||
else -> KeyboardId.ELEMENT_SYMBOLS
|
else -> KeyboardId.ELEMENT_SYMBOLS
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyboardLayoutKind.Phone -> when(page) {
|
KeyboardLayoutKind.Phone -> when(page) {
|
||||||
KeyboardLayoutPage.Base -> KeyboardId.ELEMENT_PHONE
|
KeyboardLayoutPage.Base -> KeyboardId.ELEMENT_PHONE
|
||||||
KeyboardLayoutPage.Shifted, KeyboardLayoutPage.ShiftLocked -> KeyboardId.ELEMENT_PHONE_SYMBOLS
|
KeyboardLayoutPage.Shifted,
|
||||||
|
KeyboardLayoutPage.ManuallyShifted,
|
||||||
|
KeyboardLayoutPage.ShiftLocked -> KeyboardId.ELEMENT_PHONE_SYMBOLS
|
||||||
else -> KeyboardId.ELEMENT_PHONE
|
else -> KeyboardId.ELEMENT_PHONE
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +76,7 @@ data class KeyboardLayoutElement(
|
|||||||
fun fromElementId(value: Int): KeyboardLayoutElement =
|
fun fromElementId(value: Int): KeyboardLayoutElement =
|
||||||
when(value) {
|
when(value) {
|
||||||
KeyboardId.ELEMENT_ALPHABET -> KeyboardLayoutElement(kind = KeyboardLayoutKind.Alphabet, page = KeyboardLayoutPage.Base)
|
KeyboardId.ELEMENT_ALPHABET -> KeyboardLayoutElement(kind = KeyboardLayoutKind.Alphabet, page = KeyboardLayoutPage.Base)
|
||||||
KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED -> KeyboardLayoutElement(kind = KeyboardLayoutKind.Alphabet, page = KeyboardLayoutPage.Shifted)
|
KeyboardId.ELEMENT_ALPHABET_MANUAL_SHIFTED -> KeyboardLayoutElement(kind = KeyboardLayoutKind.Alphabet, page = KeyboardLayoutPage.ManuallyShifted)
|
||||||
KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED -> KeyboardLayoutElement(kind = KeyboardLayoutKind.Alphabet, page = KeyboardLayoutPage.Shifted)
|
KeyboardId.ELEMENT_ALPHABET_AUTOMATIC_SHIFTED -> KeyboardLayoutElement(kind = KeyboardLayoutKind.Alphabet, page = KeyboardLayoutPage.Shifted)
|
||||||
KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED -> KeyboardLayoutElement(kind = KeyboardLayoutKind.Alphabet, page = KeyboardLayoutPage.ShiftLocked)
|
KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCKED -> KeyboardLayoutElement(kind = KeyboardLayoutKind.Alphabet, page = KeyboardLayoutPage.ShiftLocked)
|
||||||
KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED -> KeyboardLayoutElement(kind = KeyboardLayoutKind.Alphabet, page = KeyboardLayoutPage.ShiftLocked)
|
KeyboardId.ELEMENT_ALPHABET_SHIFT_LOCK_SHIFTED -> KeyboardLayoutElement(kind = KeyboardLayoutKind.Alphabet, page = KeyboardLayoutPage.ShiftLocked)
|
||||||
@ -228,13 +245,19 @@ class KeyboardState(private val switchActions: SwitchActions) {
|
|||||||
|
|
||||||
private val shifted: Boolean
|
private val shifted: Boolean
|
||||||
get() = currentLayout.page == KeyboardLayoutPage.Shifted ||
|
get() = currentLayout.page == KeyboardLayoutPage.Shifted ||
|
||||||
|
currentLayout.page == KeyboardLayoutPage.ManuallyShifted ||
|
||||||
currentLayout.page == KeyboardLayoutPage.ShiftLocked
|
currentLayout.page == KeyboardLayoutPage.ShiftLocked
|
||||||
private fun toggleShift(to: Boolean = !shifted) {
|
private fun toggleShift(to: Boolean = !shifted, manually: Boolean = false) {
|
||||||
setLayout(currentLayout.copy(page = when {
|
setLayout(currentLayout.copy(page = when {
|
||||||
to -> {
|
to -> {
|
||||||
if(isAlphabet) alphabetShiftState.setShifted(true)
|
if(isAlphabet) alphabetShiftState.setShifted(true)
|
||||||
|
|
||||||
|
if(manually) {
|
||||||
|
KeyboardLayoutPage.ManuallyShifted
|
||||||
|
} else {
|
||||||
KeyboardLayoutPage.Shifted
|
KeyboardLayoutPage.Shifted
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
if(isAlphabet) alphabetShiftState.setShifted(false)
|
if(isAlphabet) alphabetShiftState.setShifted(false)
|
||||||
@ -290,7 +313,7 @@ class KeyboardState(private val switchActions: SwitchActions) {
|
|||||||
when (code) {
|
when (code) {
|
||||||
Constants.CODE_SHIFT -> {
|
Constants.CODE_SHIFT -> {
|
||||||
shiftKeyState.onPress()
|
shiftKeyState.onPress()
|
||||||
toggleShift()
|
toggleShift(manually = true)
|
||||||
onShiftTapForShiftLockTimer()
|
onShiftTapForShiftLockTimer()
|
||||||
}
|
}
|
||||||
Constants.CODE_CAPSLOCK -> {
|
Constants.CODE_CAPSLOCK -> {
|
||||||
@ -392,7 +415,7 @@ class KeyboardState(private val switchActions: SwitchActions) {
|
|||||||
if(autoCapsFlags != Constants.TextUtils.CAP_MODE_OFF) {
|
if(autoCapsFlags != Constants.TextUtils.CAP_MODE_OFF) {
|
||||||
// Only shift from base layout. If we are in an alt layout, do nothing.
|
// Only shift from base layout. If we are in an alt layout, do nothing.
|
||||||
if(currentLayout.page == KeyboardLayoutPage.Base) {
|
if(currentLayout.page == KeyboardLayoutPage.Base) {
|
||||||
toggleShift(true)
|
toggleShift(true, manually = false)
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -156,14 +156,7 @@ class KeyboardLayoutSetV2 internal constructor(
|
|||||||
)
|
)
|
||||||
|
|
||||||
private fun getKeyboardLayoutForElement(element: KeyboardLayoutElement): org.futo.inputmethod.v2keyboard.Keyboard {
|
private fun getKeyboardLayoutForElement(element: KeyboardLayoutElement): org.futo.inputmethod.v2keyboard.Keyboard {
|
||||||
return elements[element] ?: run {
|
return elements[element.normalize()] ?: run {
|
||||||
// ShiftLocked is equivalent to Shifted
|
|
||||||
if(element.page == KeyboardLayoutPage.ShiftLocked) {
|
|
||||||
elements[element.copy(page = KeyboardLayoutPage.Shifted)]
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
} ?: run {
|
|
||||||
// If this is an alt layout, try to get the matching alt
|
// If this is an alt layout, try to get the matching alt
|
||||||
element.page.altIdx?.let { altIdx ->
|
element.page.altIdx?.let { altIdx ->
|
||||||
val baseElement = element.copy(page = KeyboardLayoutPage.Base)
|
val baseElement = element.copy(page = KeyboardLayoutPage.Base)
|
||||||
|
Loading…
Reference in New Issue
Block a user