fix: keep each key cap's gesture keyed and make the default size selectable

This commit is contained in:
Dantalian committed 2026-11-01 05:38:54 +08:00
1 parent 3df48d5625
commit 113ba7b77c
2 files changed
+14 -8

No files matched your search

@@ -36,6 +36,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.key
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateMapOf
import androidx.compose.runtime.mutableStateOf
@@ -136,11 +137,13 @@ fun PcKeyboard(
key.label.length == 1 && key.label[0].isLetter() && (shifted xor capsOn) -> key.label.uppercase()
else -> key.label
}
KeyCap(
label, key.weight, lit, locked = state == MOD_LOCKED,
modifier = if (r == 0 && i == 0) Modifier.focusRequester(firstKey) else Modifier,
onDown = { press(key) }, onUp = { release(key) },
)
key(key.code) {
KeyCap(
label, key.weight, lit, locked = state == MOD_LOCKED,
modifier = if (r == 0 && i == 0) Modifier.focusRequester(firstKey) else Modifier,
onDown = { press(key) }, onUp = { release(key) },
)
}
}
}
}
@@ -174,8 +177,11 @@ private fun RowScope.KeyCap(
awaitEachGesture {
awaitFirstDown().consume()
down = true; onDown()
waitForUpOrCancellation()?.consume()
down = false; onUp()
try {
waitForUpOrCancellation()?.consume()
} finally {
down = false; onUp()
}
}
}
.onPreviewKeyEvent { e ->
@@ -677,7 +677,7 @@ internal fun SessionDrawer(open: Boolean, requestedPage: SessionDrawerPage, cont
remember { PcKeyboardPrefs.load(keyboardContext) }
SliderRow(
stringResource(R.string.pckb_size), stringResource(R.string.pckb_size_hint),
PcKeyboardPrefs.size, SessionPrefs.PC_KEYBOARD_SIZE_RANGE, step = 5,
PcKeyboardPrefs.size, SessionPrefs.PC_KEYBOARD_SIZE_RANGE, step = 1,
format = { "$it%" }, modifier = focus.track(page, "pckb-size"),
onChange = { PcKeyboardPrefs.setSize(keyboardContext, it) })
SliderRow(