Skip to content

feat(keyboard): app setting to override the numeric-input layout - #47

Open
SandyYuR wants to merge 8 commits into
fxliang:fxfrom
SandyYuR:fx
Open

feat(keyboard): app setting to override the numeric-input layout#47
SandyYuR wants to merge 8 commits into
fxliang:fxfrom
SandyYuR:fx

Conversation

@SandyYuR

@SandyYuR SandyYuR commented Aug 18, 2026

Copy link
Copy Markdown

数字输入框使用自定义布局(应用设置)

键盘设置 → 编辑器分类下新增「数字键盘布局」设置项,与「文本键盘布局文件」设置并列。
点击后弹出单选列表:

  • 默认「内置数字键盘」(留空,行为与原来一致);
  • 其余选项直接读取当前启用的布局文件中的层(基础布局与 ime:submode 子布局,
    复用布局编辑器的 LayoutDataManager 解析逻辑,与编辑页下拉枚举一致)。

选择某个层后,数字输入框(TYPE_CLASS_NUMBER / TYPE_CLASS_PHONE,含 PIN 数字密码框)
短路内置数字键盘并展示该自定义布局;用户自行指定、自行负责,布局不存在或值失效时回退内置键盘。

实现解耦说明

  • 选项只存在于应用设置(AppPrefs numeric_layout_override),TextKeyboardLayout.json
    的数据结构与解析逻辑完全未动,未混入任何数字键盘相关定义,避免深耦合、方便后续维护。
  • 运行时复用既有 layer 机制:数字布局仅作为 forcedLayoutKey 的回落值,布局解析管线
    (getLayout/高度/辅助栏/签名)零改动、无新增分支;BACK 层历史在输入重启时清空。
  • 已变基到最新 fx(含 5dfa407 macro metaState 重构):numpad NumLock 修复适配其
    simulatedMetaState() 拆分,并为该函数补充 keyCode 参数,自定义按钮路径同样受益。

数字键盘按键修复

  • 模拟数字键盘键恒开 NumLock,避免MacroKey设定为点击 KP 小数点等按键,出现无法正常输出的情况。
  • 补充 KP_Separator / KP_Equal 的 fcitx↔Android 双向键映射。

PIN 数字密码框

Password capability flag 对 NUMBER/PHONE 两类统一推导(TYPE_NUMBER_VARIATION_PASSWORD),
候选栏与文本密码框一致置空。

已在 SandyYuR/fcitx5-android 的 fx 分支(同步上游最新提交)构建并实测。

@SandyYuR SandyYuR changed the title feat(keyboard): custom default_t9 layout for numeric input fields + numpad key fixes feat(keyboard): option to use a custom layout for numeric input fields Aug 19, 2026
@SandyYuR
SandyYuR force-pushed the fx branch 2 times, most recently from 72aef92 to f2e2f4d Compare August 19, 2026 04:07
@SandyYuR SandyYuR changed the title feat(keyboard): option to use a custom layout for numeric input fields feat(keyboard): app setting to override the numeric-input layout Aug 19, 2026
…_Separator and KP_Equal key mappings

Numpad keys sent through the simulated keyboard now always carry
META_NUM_LOCK_ON so Android KeyCharacterMap produces the correct
digit/symbol unicode characters instead of navigation keys. KP_Separator
(0xffac -> KEYCODE_NUMPAD_COMMA) and KP_Equal (0xffbd ->
KEYCODE_NUMPAD_EQUALS) join the generated fcitx<->android key mapping in
both directions.

The numpad keycode range is hoisted into a shared top-level constant so it
is not reallocated on every simulated key event.
Numeric-only editors (TYPE_CLASS_NUMBER / TYPE_CLASS_PHONE) can now use a
custom text keyboard layout via the new 数字键盘布局 app setting (keyboard
settings, editor category). It opens a picker listing the layers of the
currently enabled text keyboard layout file (base layouts plus ime:submode
entries) with the built-in number keypad as the default; selecting a layer
short-circuits the built-in NumberKeyboard for numeric editors. Stale or
unresolvable values fall back to the built-in keypad.

The option lives only in app settings: TextKeyboardLayout.json keeps defining
text keyboard layouts exclusively, with no data-structure or parsing changes.
At runtime the override reuses the existing forced-layer pipeline as a
fallback value (getLayout/height/aux bar/signature untouched), and the BACK
layer history is cleared on input restart.

PIN-style numeric password fields are included; their candidate bar stays
empty via the Password capability flag now derived uniformly for NUMBER and
PHONE classes.
@SandyYuR

Copy link
Copy Markdown
Author

Screenshot_2026-08-19-18-39-29-49_9ed49db8ab55c3d936ef9a36fb5b5b62.jpg

现在是直接读取布局编辑页面的层列表,在设置里面提供给用户选择,可选默认内置t9键盘和自定义布局的任意层。

fxliang and others added 5 commits August 20, 2026 10:56
Pressing an explicit user key targeting the text keyboard (e.g. an
ABC-style LayoutSwitchKey with switch target Text) now resets latched and
one-shot layers in addition to the numeric override handling. Previously a
MacroKey layer switch (TO/OSL) kept its forced layer in the controller, so
while the keyboard was already the TextKeyboard the switchLayout early
return left the latched layer in place and the key appeared to do nothing.

Also clears the BACK layer history on the explicit reset so a later BACK
key cannot resurrect a stale layer.
@SandyYuR

Copy link
Copy Markdown
Author

补充修复(d421ba66):MacroKey 层切换(TO/OSL)锁存的层会让 LayoutSwitchKey 切回文本键盘失效。

原因:层切换走 handleLayerSwitchAction 把 forcedKey 锁存在 override controller;
随后按下目标为 Text 的 LayoutSwitchKey 时,switchLayout("Text", fromUserKey=true) 因为
当前已经是 TextKeyboard 而走 early-return,只处理了数字 override 的释放,没有清掉锁存层。

修复:显式用户按键切回文本键盘时,同时清空 latched/one-shot 层与 BACK 历史栈,
再按既有逻辑释放数字 override(数字会话)或手动数字布局(文本会话)。

日志复现:BaseKeyboard executeMacro TO target=数字 / OSL target=符号 之后,
LayoutSwitchKey 无任何效果;本提交已修复该路径。

A MacroKey layer switch (TO) applies the latched layer via
applyEffectiveTextLayer and then relayouts through switchLayout(Text,
remember=false). That internal Text->Text switch hit the releaseManualNumericLayout
branch inherited from the layoutswitch-key fix: after the user had manually
shown the numeric keyboard with a LayoutSwitchKey, manual=true, so the
relayout reset forcedKey to the (null) session fallback and clobbered the
layer that was latched a moment earlier - the keyboard jumped back to the
text main keyboard instead of the target layer.

Internal Text->Text relayouts (layer switches, one-shot consumption,
onStartInput) now leave the manual numeric state untouched; releasing it
remains exclusive to explicit user keys targeting the text keyboard
(fromUserKey=true), which already clears latched layers as well.
@SandyYuR

Copy link
Copy Markdown
Author

补充修复(9358ec9e,与上一条修复同区域):LayoutSwitchKey 手动切出数字键盘后,MacroKey 层切换被冲掉、落回文本主键盘。

原因:MacroKey TO 层切换在 applyLayerOverridesAndRelayout 里走内部 switchLayout(Text, remember=false)
命中了 releaseManualNumericLayout() 分支。手动切过数字键盘后 manual=true,该释放把 forcedKey
重置为 sessionKey(文本会话为 null),把前一瞬间刚锁存的层覆盖掉——日志里每次 TO 符号后的两次连续
reloadLayout 即「先锁存、再被冲掉」。

修复:内部 Text→Text 重排(层切换、one-shot 消费、onStartInput)不再触碰手动数字布局状态;
释放仅保留在显式用户按键切回文本键盘(fromUserKey=true)的路径,与上一条修复合并后行为如下:

  • 层切换 → 正常锁存到目标层(数字/符号/rime 均可再切);
  • 显式 ABC/Text 目标按键 → 清锁存层 + 释放数字 override/手动数字布局,回到默认文本键盘。

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants