Commit Graph
107 Commits
Author SHA1 Message Date
fanlusky 1348ca8eb7 fix(server): D2D 托盘菜单项圆角与外框同心对齐,放宽行高与内边距 2026-09-27 11:19:07 +08:00
fanlusky 573169105f fix(ui): D2D 预编辑光标不再贴住首项高亮
光标原先取整行高度并下移 8%,底部越过预编辑行、碰到候选列表首项的
高亮背景。改为与 CSS 相同的几何:高 1.2em,底边在基线下 0.12em。
2026-09-26 23:38:37 +08:00
fanlusky 7d66b2556c feat(server,ui,ui-html): 候选翻译文本支持在皮肤中单独配色
外部皮肤 skin.toml 的 [candidate.dark] / [candidate.light] 新增 translation 键。
不写时沿用候选文字色叠 62% 不透明度;写了就按原值绘制(含选中行)。
D2D(CandidateList::Appearance::translationColor)、WebView2 注入 CSS
和设置页外部皮肤预览三处一致;预览顺带补上此前漏掉的 number 配色。
2026-09-26 23:38:37 +08:00
fanlusky 0b4d9172f8 feat(ui): CandidateList 让贴着列表四角的项使用外框圆角
Appearance 新增 outerCornerRadius 与 outerTopCornersEnabled:选中或悬停的
填充里,真正落在列表四角上的角改用外框半径,其余角保持 cornerRadius。
既支持内缩高亮与外框同 R,也支持整行铺满、只在外框四角处贴合的皮肤。
2026-09-26 21:49:04 +08:00
fanlusky 3135af32ea fix(ui): 菜单项回调不再读已释放的闭包
在 D2D 候选框上右键删除一个候选,server 进程必定闪退重启,
0xc0000005 访问违例。

MenuFlyoutItem::OnMouseUp 直接调 onClick_()。候选框右键菜单的四个
动作都是「先 CloseContextMenu(true) 再 PostMessageW」的形状,而
CloseContextMenu 会同步 RemovePopup 并 reset 掉 contextMenu,也就是
在 operator() 还在栈上时销毁了这个 MenuFlyoutItem,连带销毁正在执行
的 std::function —— 小闭包按 MSVC 的 small-object optimization 就存
在 MenuFlyoutItem 那个堆块里。紧接着的 RestoreHostAfterMenu() 同步
走 SetWindowPos,派发 WM_SIZE/WM_PAINT 触发重新分配,把那块内存回收
掉;lambda 体回来再读 this 时读到的已经是别人的数据,mov rcx,[rcx+8]
(hwnd_)就炸在这里。

四个动作形状相同,都有这个缺陷;置顶碰巧不崩只是因为 MSVC 没有在那
一处重新从闭包存储里加载捕获,不是它安全。

改法是调用前把 ClickHandler 拷到栈上,让可调用对象活过自己这次调用。
Button::OnClick 是同样的形状,一并改掉。

回归测试不去捕捉内存破坏——能不能复现取决于分配器是否恰好回收了那一
块、以及编译器有没有重新加载捕获,而且读已释放内存本身就是未定义行为。
改为断言修复所建立的不变式:句柄在自己 operator() 执行期间始终存活。
2026-09-19 15:45:25 +08:00
fanlusky a54e2e08e8 fix(ui): 候选窗高亮行的辅助码与翻译跟随选中文字色
微信绿皮肤下高亮行的辅助码压在 #07C160 绿底上仍是暗色,与 webview 不一致。

候选行绘制里 rowTextSelected/rowLabelSelected 只覆盖候选文字和序号,辅助码
(annotation)和翻译一直无条件使用 appearance_.annotationColor。而皮肤 CSS 里
这两者是 .text 的子节点(.cand-content / .cand-translation),颜色继承自 .text,
选中行的 `.first .text { color: ... }` 会一并覆盖它们——D2D 端分开绘制,这层继承
关系就丢了。

改为在高亮行显式跟随 rowTextSelected,翻译再乘 CSS 的 opacity .62 保持原有观感。
判据是 rowTextSelected 的 alpha,所以各皮肤自动与各自 CSS 对齐:wechat 与
willow_green 白色,graphite #111827/#f1f3f5,fluent 没有 .first .text 覆盖,
沿用普通文字色不变。
2026-09-14 14:45:11 +08:00
Jia Sui 3dea733f64 fix(ui,server): 候选窗 D2D 阴影按皮肤对齐 webview——Card 支持 pass 列表
D2D 候选窗的 Card 阴影是内置 Win11 漫射三层(σ11/6/2.8,α0.42/0.30/0.48):
四边对称、无偏移,紧贴边缘合成 α≈0.49、暗晕铺到 15~20 DIP。webview 端候选窗
皮肤 CSS 用的是带右下偏移的双层软阴影(light: 8px 10px 24px rgba(0,0,0,.18)
+ 2px 3px 8px rgba(0,0,0,.10))。用户实机截图剖面实测:webview 底边峰值 α≈0.16、
D2D 0.41,差 2.5 倍,即「D2D 阴影偏重」的根因。对称三层无论怎么调参都拟合不了
带偏移的衰减曲线;浮动工具栏已有的 SetShadowScale 只缩模糊半径压不了深度
(高斯在边缘恒贡献 α/2)。

给 Card 拆出数据驱动的阴影 API,阴影参数跟皮肤走(与颜色/圆角同模式):

- ui/include/msimeui/Layout.h、ui/src/Layout.cpp:ShadowPass{σ,α,offset} +
  SetShadowPasses(空列表保持内置 Mist 三层,逐位不变)、SetShadowEnabled
  (整体开关,语义对齐 Popup 同名 API)、SetShadowOpacity(uniform 缩 α,与
  SetShadowScale 正交);渲染统一走 DrawGaussianShadowPass,无 device context
  时兜底 DrawLayeredMistShadow
- server/src/window/candidate_presenter.cpp:ApplySkin 按皮肤设阴影——内置四皮肤
  与自定义包用皮肤 CSS 标准对(σ=blur÷2)light {12,0.18,(8,10)}+{4,0.10,(2,3)}、
  dark α .34/.22;默认皮肤 webview 端 body HTML 无 box-shadow,D2D 同步关掉
- 浮动工具栏(scale=0.45)与托盘菜单(全默认)不触新 API,观感不变
- 透明垫余量重验:新 pass 可见范围(α>0.02 阈值)左16/上14/右32/下34 DIP,
  均在左32/上20/右32/下40 垫内,无裁切切痕
2026-09-14 12:34:10 +08:00
fanlusky ee5b50133f fix(ui): 竖排候选窗选中项高亮铺满整行
d2d 渲染下,竖排候选窗被卡片最小宽度撑大时,候选项的自然宽度小于卡片内宽,
选中高亮与命中区域只覆盖到文字宽度,右侧留下大片空白(候选项较长、宽度超过
卡片最小宽度时表现正常)。

根因:候选项行矩形取自按自然宽度测量得到的 itemGeometry。列表虽被拉伸到卡片
内宽,但绘制前 Present 阶段会以窗口宽度重新测量,把每项宽度还原为自然宽度,而
此时排布命中缓存(矩形未变)被跳过,铺满逻辑无法重新生效。

改为在 ItemRect 中直接以列表最终布局宽度 bounds_ 计算竖排行矩形,不再依赖逐项
自然宽度,绘制与命中同时受益,且不受测量/排布缓存影响。右侧留白由卡片内边距
提供,与左侧保持一致。横排路径不变。

新增 GetItemBounds 访问器与三个回归测试,其中一个复刻了 Present 重新测量的时序,
可捕获此前方案的退化。
2026-09-14 02:04:58 +08:00
古明四季 42bfd9fc49 fix(ui): 修复候选列表溢出与换行后的点击区域 2026-09-11 23:34:57 +08:00
Jia Sui 62b4688aa1 feat(ui): DeviceResources 与 Window 支持渲染 DPI 覆写 2026-09-11 22:21:57 +08:00
Jia Sui bd7cf1114d fix(server): D2D 内置皮肤补齐 light 配色,对齐 WebView2 CSS
Signed-off-by: Jia Sui <jsfaint@gmail.com>
2026-09-11 22:19:24 +08:00
Neptrue_Lin 2b6bfafeec Merge pull request #327 from ouchihao/codex/fix-295-retained-dpi
fix(ui): refresh DPI when reusing render targets
2026-09-11 20:34:43 +08:00
Ouchihao f3fcd322e9 fix(ui): refresh DPI when reusing render targets 2026-09-11 19:35:07 +08:00
Ouchihao f9a021dc02 fix(ui): collapse text selections before moving the caret 2026-09-11 19:32:34 +08:00
Aegon8719 dea9292814 issue-55 候选窗支持可配置的有序回落字体 2026-09-09 18:03:56 +08:00
fanlusky 43576b75ca fix(ui): make the icon font resolver recover from DirectWrite failures
ResolveIconGlyph() guarded its cache with a mutex, but the work under that
lock reached SharedFactory(), whose lazy DWriteCreateFactory() call was
unsynchronized -- and UiFontFamily()/ApplyUiFontFallback() call the same
helper without that mutex from render paths. Two window threads could both
see a null factory, both create one into the same ComPtr, leak one and race
on the raw pointer. Give SharedFactory() a lock of its own.

IconFonts() memoized its result in a function-local static initialized
exactly once. If SharedFactory() returned null or GetSystemFontCollection()
failed on that first call, the empty list was cached for the process
lifetime and every icon degraded to its text label permanently, with no
retry -- while SharedFactory() itself retried on each call, making the
failure mode asymmetric and hard to diagnose. Keep the list only once the
probe finds a font, and skip the ResolveIconGlyph cache while it is empty
so the retry is actually reachable.
2026-09-08 16:11:16 +08:00
fanlusky 43555460db fix(server): fall back to text when the icon font lacks the glyph
The floating toolbar and the emoji panel hardcoded "Segoe Fluent Icons",
which ships with Windows 11 only. DirectWrite substitutes a font silently
instead of failing, so on Windows 10 every private-use codepoint the toolbar
draws (U+E982, U+F110, U+F138, ...) rendered as a blank box: the buttons
still worked but no longer showed any state.

Resolve the font per codepoint rather than per family, because "Segoe MDL2
Assets" is a subset of Segoe Fluent Icons and swapping the family alone would
still draw tofu wherever a glyph is missing:
- add msimeui::ResolveIconGlyph(), which probes the installed icon fonts with
  IDWriteFont::HasCharacter() and returns the first family that really carries
  the glyph, or no family at all;
- give every toolbar and tab icon a text label to fall back on (中/英, 半/全,
  简/繁, ...) when neither font has the glyph;
- drop the unused ToolbarIconButton::SetGlyph/SetLabel, which would bypass the
  resolved family.

Add unit tests for the resolver, covering the missing-glyph path that cannot
be reached on a host that has Segoe Fluent Icons installed.
2026-09-08 12:41:01 +08:00
Ouchihao 3fc7ba295f feat(server): show translations in horizontal candidate windows 2026-09-06 18:09:01 +08:00
Evan 42238a2af6 style: 用 .clang-format 重排 server / windows / ui / log
一次性重排,无任何行为改动。四个目录各自的 .clang-format 放在仓库里已久,但全组织只有
MSIME-Linux 在 CI 里执行 clang-format 检查,这边 149 个文件里有 149 个不符合自己声明的风格。

已逐文件核对语义等价:去掉空白、注释与相邻字符串字面量拆分之后,全部 149 个文件与重排前逐字节
相同。差异只有三类——缩进与换行、clang-format 补的 } // namespace 结尾注释、以及长字符串被拆成
相邻字面量(C++ 保证自动拼接)。

这个提交会写进 .git-blame-ignore-revs。
2026-09-06 12:13:47 +09:00
Evan 2562026a2a fix: 修复审计发现的候选页竞态、管道权限、TSF 空指针与皮肤 CSS 逃逸等八项缺陷 (#169)
* fix(server): publish candidate pages as immutable snapshots

Global::candidate_ui is a plain global with no lock. The IPC worker rebuilds and destroys its vectors while the UI thread paints from them, and the handoff is an asynchronous PostMessage, so the worker returns to its loop and pops the next task without waiting. A second keystroke, or an async english.db candidate arrival, could free the page_views buffer and its strings while FillItemsFromUi held a reference into it. ShowItemContextMenu reads the same vectors from a mouse callback with no message handoff at all.

The worker now copies each finished page into an immutable snapshot and publishes it at the single point where the rebuild completes; every UI-thread reader loads that snapshot once and reads only its own copy. PostMessage is deliberately left alone: the worker also serves UI-originated tasks, so a synchronous handoff would invite a cross-thread deadlock.

* fix(server): bound the aux and diagnostic pipe reads

Both listeners serve a single pipe instance inline and polled a NOWAIT handle for as long as the process ran, breaking only on a read that succeeded or failed with something other than ERROR_NO_DATA. A client that connected and never wrote held the only instance forever, so the loop never returned to ConnectNamedPipe and no later client was accepted, permanently losing the langbar right-click channel and the terminal-deactivation teardown fallback.

Give both loops the same deadline the hello reads already use and go back to accepting when it expires.

* fix(server): snapshot the voice config and replace config.toml atomically

GetConfiguredVoiceInput handed out a reference to a global that LoadImeConfig rewrites from the IPC worker thread, clearing and refilling two std::map members and around twenty strings. The voice control thread and the low-level keyboard hook, which copies the struct on every keystroke, walked those nodes as they were freed. LoadImeConfig now parses into a local and publishes it in one step under a process-local shared_mutex, and the getter returns a snapshot by value. The file lock is deliberately not reused for readers: it is a named cross-process mutex with a five second wait, and taking it in a keyboard hook would stall typing system-wide.

WriteConfiguredValue also reopened the live config.toml with ios::trunc, so a crash mid-write destroyed the user settings and could leave the file unparseable for good. It now goes through WriteFileTextAtomically, which this file already uses elsewhere. That makes the directory entry swap atomic; it does not flush, so it is not a durability guarantee.

* fix(ipc): restrict the server pipes to the owning account

The pipe DACL granted Everyone FILE_ALL_ACCESS. That bit set includes FILE_CREATE_PIPE_INSTANCE, so any local account could add an instance to a name this server already owned and answer part of the connections in its place. The names are machine-global with no per-user component, and the TSF client opened them with no SQOS, so a squatter could also impersonate the connecting thread.

Build the descriptor from the process owner SID and admit only LocalSystem, that account, and app containers with connect-only rights so UWP text input still works; fail pipe creation outright when the SID cannot be resolved rather than falling back to something permissive. Pass FILE_FLAG_FIRST_PIPE_INSTANCE on the first instance of each name so a squatted name fails loudly, and request SECURITY_IDENTIFICATION on the client side.

Authenticating the peer process after connect is a larger change to the handshake and is not attempted here.

* fix(tsf): guard the null focus paths and unadvise the compartment sink

_CandidateChangeNotification treated ITfThreadMgr::GetFocus and ITfDocumentMgr::GetTop as if they could only fail through a FAILED HRESULT. Both return S_OK with a null out-pointer when nothing has focus or the document stack is empty, and the results were dereferenced unconditionally, so an external UILess host calling Finalize while focus moved away crashed the host application. The sibling _RequestCancelComposition in the same class already checks both.

CLangBarItemButton::CleanUp only unregistered the compartment inside the SUCCEEDED branch of a CoCreateInstance, then deleted the sink regardless. This TIP registers COM-less activation support, where that call does fail, and the sink was freed while TSF still held it advised. Unadvising never needed the thread manager, so it now runs unconditionally before the deletes.

* fix(ui): drop the cached visuals when the scene is replaced

Window caches focused, hovered and captured Visual pointers into the scene tree, and SetScene destroyed that tree without clearing them. Toggling the input mode rebuilds the floating toolbar scene, so the next mouse move dispatched a virtual call through a freed object.

Clear all three before the assignment, and release the capture only when this window actually holds it: an adopted HWND may never have called SetCapture, and capturedVisual_ is set even when it did not.

* fix(settings): scope external skin CSS through the CSS parser

injectScopedSkinCss concatenated a skin toolbar.css into an @scope block as text. Block nesting is textual, so a leading close brace in the skin ended the block early and the rest styled the whole settings window. The host validates only the skin file name, never the body, and candidatePreviewCss interpolated unvalidated colour strings into rule bodies the same way.

Create the scope rule empty and re-insert every rule parsed out of the skin as a child of it, so nothing lands outside however the braces are balanced, and accept a colour only in the plain notations we actually render.

* fix(release): gate the dictionary source commit on its default branch

verify_published iterated only data["repositories"], but the dictionary block pins a source_commit exactly like they do. The manifest check merely proves the release agrees with the lock about that commit, which a branch commit satisfies just as happily, so a dictionary built from an unmerged branch shipped with the provenance the gate exists to refuse.

Run the dictionary through the same loop under its own name, resolving its repository from the lock. A retired dictionary repository that no longer answers is reported rather than failing the release: its published artifacts are immutable history, and being unable to re-check them is not the same as finding them unmerged.
2026-09-06 10:31:48 +09:00
fanlusky a0c4daa9ad Allow Card window shadows to scale for compact surfaces
Add Card::SetShadowScale so the Win11 mist shadow can shrink with the
control. The floating toolbar can then keep the same shadow style without
clipping or a oversized host.
2026-09-02 19:12:01 +08:00
fanlusky 4e66d19614 Optimize the shadow style of the candidate window. 2026-09-02 17:23:03 +08:00
fanlusky 2ac86ea0e2 Stop mapping all Unicode through CJK fonts and cut D2D working-set growth
Custom font fallback no longer covers the whole BMP/SIP, so Segoe UI Emoji
can paint color glyphs again; CJK still prefers Noto Sans SC then YaHei.
Drop GaussianBlur compatible targets during BeginDraw (they retained GPU
memory as the candidate window grew), grow the composition swapchain in
64px steps without shrinking, and reuse Card chrome plus cached text
formats instead of reallocating them every layout.
2026-09-02 16:25:54 +08:00
fanlusky 5421c1dd1b Add SVG icon rendering, toggle switch, and font fallback for MenuFlyoutItem
MenuFlyoutItem gains leading SVG icons (ID2D1SvgDocument), an optional
trailing toggle switch, and content-based width measurement so tray-style
menu items match the HTML menu layout. Default UI font is now Noto Sans SC
with Microsoft YaHei fallback via IDWriteFontFallback; CreateTextFormat
gracefully falls back when the primary family is missing.
2026-09-02 16:03:57 +08:00
fanlusky d16f9f3fea Add DirectComposition hosting and candidate-list chrome for the IME window
Adopt an existing HWND, render through D3D11/DXGI/DirectComposition, and
extend CandidateList with horizontal layout, skin colors, click-to-commit,
and a D2D context menu. Preedit TextBlock draws a caret in a fixed insert
slot so neighboring glyphs reflow instead of using letter-spacing; the
default end caret sits slightly after the last character.
2026-09-02 15:29:14 +08:00
fanlusky 3d7b8a3c24 Add support for svg render. 2026-08-17 04:42:53 +08:00
fanlusky 64c08a7c02 Adjust some controls for emoji panel. 2026-08-15 02:32:00 +08:00
fanlusky f3c7a9557a Set the initial position setting method for the window. 2026-07-20 23:22:05 +08:00
fanlusky 548330b8cf Make a demo of an on-screen keyboard. 2026-07-15 18:22:50 +08:00
fanlusky 3a41372f24 Adjust font size and some layouts 2026-07-15 15:50:50 +08:00
fanlusky 59a73b8476 Optimize the emoji panel size. 2026-07-15 15:43:58 +08:00
fanlusky 05a4ada19d Optimize the emoji panel. 2026-07-15 15:34:53 +08:00
fanlusky 604cf987b1 emoji panel demo step01 2026-07-15 14:49:36 +08:00
fanlusky 4f62123699 Support image render 2026-07-15 14:39:55 +08:00
fanlusky a91baf56c1 Add dictionary-backed word deletion 2026-06-19 13:46:10 +08:00
fanlusky ab5516da96 Unclamp combo box popups 2026-06-19 13:03:32 +08:00
fanlusky e210c8eb4c Allow popups to scroll out of view 2026-06-19 13:00:35 +08:00
fanlusky 19257221cc Restore popup trigger press feedback 2026-06-19 12:54:41 +08:00
fanlusky 8a20c1461a Remove sticky button focus border 2026-06-19 12:50:00 +08:00
fanlusky d2ca118d89 Add candidate hover highlight 2026-06-19 11:52:43 +08:00
fanlusky 7361a13b19 Keep arrow cursor over candidate list 2026-06-19 11:49:15 +08:00
fanlusky 7075c06aee Emphasize candidate highlight bar 2026-06-19 11:46:45 +08:00
fanlusky 33350ab7c2 Trim candidate header text metrics 2026-06-19 11:34:30 +08:00
fanlusky fffcf648b2 Widen candidate highlight block 2026-06-19 11:24:32 +08:00
fanlusky abe110c6e1 Refine candidate preview weight 2026-06-19 11:14:22 +08:00
fanlusky 718d4f9559 Align candidate preview typography 2026-06-19 11:06:54 +08:00
fanlusky 9e7d1acdac Scale candidate preview back up 2026-06-19 10:59:29 +08:00
fanlusky eb6d49b7ea Compress candidate preview spacing 2026-06-19 08:12:20 +08:00
fanlusky 912cf30148 Align candidate bar to selection edge 2026-06-19 08:07:54 +08:00
fanlusky d35dd7b2de Tighten candidate preview toward reference 2026-06-19 08:00:25 +08:00