Restore InputView state when switching between virtual/physical keyboard

This commit is contained in:
Rocka 2025-11-09 02:58:14 +08:00
parent 23c4d318b6
commit 2ad65bd234
No known key found for this signature in database
GPG Key ID: 28031158FFDD6853
3 changed files with 31 additions and 4 deletions

View File

@ -442,6 +442,11 @@ void AndroidFrontend::showToast(const std::string &s) {
void AndroidFrontend::setCandidatePagingMode(const int mode) {
pagingMode_ = mode;
if (mode == 0) {
activeIC_->updateCandidatesBulk();
} else {
activeIC_->updateCandidatesPaged();
}
}
void AndroidFrontend::updatePagedCandidate(const PagedCandidateEntity &paged) {

View File

@ -37,6 +37,19 @@ abstract class BaseInputView(
}
}
open fun refreshWithCachedEvents() {
val inputPanelData = fcitx.runImmediately { inputPanelCached }
val inputMethodEntry = fcitx.runImmediately { inputMethodEntryCached }
val statusAreaActions = fcitx.runImmediately { statusAreaActionsCached }
arrayOf(
FcitxEvent.InputPanelEvent(inputPanelData),
FcitxEvent.IMChangeEvent(inputMethodEntry),
FcitxEvent.StatusAreaEvent(
FcitxEvent.StatusAreaEvent.Data(statusAreaActions, inputMethodEntry)
)
).forEach { handleFcitxEvent(it) }
}
var handleEvents = false
set(value) {
field = value

View File

@ -20,16 +20,25 @@ class InputDeviceManager(private val onChange: (Boolean) -> Unit) {
private var candidatesView: CandidatesView? = null
private fun setupInputViewEvents(isVirtual: Boolean) {
inputView?.handleEvents = isVirtual
inputView?.visibility = if (isVirtual) View.VISIBLE else View.GONE
val iv = inputView ?: return
iv.handleEvents = isVirtual
if (isVirtual) {
iv.visibility = View.VISIBLE
} else {
iv.visibility = View.GONE
iv.refreshWithCachedEvents()
}
}
private fun setupCandidatesViewEvents(isVirtual: Boolean) {
candidatesView?.handleEvents = !isVirtual
val cv = candidatesView ?: return
cv.handleEvents = !isVirtual
// hide CandidatesView when entering virtual keyboard mode,
// but preserve the visibility when entering physical keyboard mode (in case it's empty)
if (isVirtual) {
candidatesView?.visibility = View.GONE
cv.visibility = View.GONE
} else {
cv.refreshWithCachedEvents()
}
}