From 8e27a12ac4edf29f35d0e336ca0e0b52241f8121 Mon Sep 17 00:00:00 2001 From: Eric Ma Date: Sun, 22 Nov 2026 11:01:18 +0300 Subject: [PATCH] =?UTF-8?q?feat(gnome-shell,fcitx5):=20=E5=B1=95=E5=BC=80?= =?UTF-8?q?=E7=BD=91=E6=A0=BC=E5=BA=95=E9=83=A8=E5=A2=9E=E5=8A=A0=20?= =?UTF-8?q?=E2=80=B9=20/=20=E2=80=BA=20=E7=BF=BB=E9=A1=B5=E6=8C=89?= =?UTF-8?q?=E9=92=AE=EF=BC=88#270=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fcitx5-addon/src/wowtype_engine.cpp | 27 +++++++++ fcitx5-addon/src/wowtype_engine.h | 2 + .../wowtype-theme@gloridust.github.io/grid.js | 55 +++++++++++++++++-- .../stylesheet.css | 18 +++++- 4 files changed, 97 insertions(+), 5 deletions(-) diff --git a/fcitx5-addon/src/wowtype_engine.cpp b/fcitx5-addon/src/wowtype_engine.cpp index 3b6e7ed1..daee89e6 100644 --- a/fcitx5-addon/src/wowtype_engine.cpp +++ b/fcitx5-addon/src/wowtype_engine.cpp @@ -217,6 +217,7 @@ constexpr uint64_t kOverlayAckUsec = 800 * 1000; // 扩展 -> 插件 Ack(u serial) 画好了、显示出来了 // Select(u serial, u 下标) 点了一格(全局下标) // Forget(u serial, u 下标) 右键点了一格、选了「忘掉这个词」(#229) +// Page(u serial, i 方向) 点了翻页按钮(-1 上一页,+1 下一页) // 光标矩形和语音浮条、kimpanel 的一样。扩展回执期间 kimpanel 拿到的是一个空列表(提示、编辑区也挪进网格), // 它的候选框整个不画;扩展没登记这个名字(没装、停用了、只会画语音浮条的旧版)就照旧把网格拼成几行给 kimpanel, // 发了 kGridAckUsec 还没有回执也退回去。 @@ -1035,6 +1036,7 @@ void WowtypeEngine::setupOverlays() { gridEventWatchers_.clear(); gridSelectSlot_.reset(); gridForgetSlot_.reset(); + gridPageSlot_.reset(); gridAckSlot_.reset(); gridWatch_.reset(); gridOwner_.clear(); @@ -1156,6 +1158,17 @@ void WowtypeEngine::setupGridOverlay() { } return true; }); + gridPageSlot_ = overlayBus_->addMatch( + fcitx::dbus::MatchRule(kGridService, kOverlayPath, kGridInterface, "Page"), + [this](fcitx::dbus::Message &msg) { + uint32_t serial = 0; + int32_t delta = 0; + msg >> serial >> delta; + if (msg && msg.sender() == gridOwner_) { + pageGrid(serial, delta); + } + return true; + }); for (const auto type : {fcitx::EventType::InputContextUpdateUI, fcitx::EventType::InputContextFocusOut}) { gridEventWatchers_.push_back(instance_->watchEvent( @@ -1252,6 +1265,20 @@ void WowtypeEngine::forgetGridCell(uint32_t serial, uint32_t index) { forgetCandidate(ic, ic->propertyFor(&factory_), index); } +void WowtypeEngine::pageGrid(uint32_t serial, int32_t delta) { + auto *ic = gridIc_.get(); + if (!ic || serial != gridSerial_ || delta == 0) { + return; + } + auto *state = ic->propertyFor(&factory_); + const uint32_t action = delta < 0 ? WOWTYPE_KEY_ACTION_PREV_PAGE + : WOWTYPE_KEY_ACTION_NEXT_PAGE; + const WowtypeFrame *frame = sessionKey(ic, state, fcitx::Key(), action); + if (frame && frame->handled) { + applySessionFrame(ic, state, frame); + } +} + void WowtypeEngine::onGridUiEvent(fcitx::Event &event) { auto *shown = gridIc_.get(); if (!shown || static_cast(event).inputContext() != shown) { diff --git a/fcitx5-addon/src/wowtype_engine.h b/fcitx5-addon/src/wowtype_engine.h index a7c9b30e..1316d75e 100644 --- a/fcitx5-addon/src/wowtype_engine.h +++ b/fcitx5-addon/src/wowtype_engine.h @@ -622,6 +622,7 @@ class WowtypeEngine final : public fcitx::InputMethodEngineV2 { void selectGridCell(uint32_t serial, uint32_t index); /// 扩展上右键点了一格、选了「忘掉这个词」(#229)。 void forgetGridCell(uint32_t serial, uint32_t index); + void pageGrid(uint32_t serial, int32_t delta); /// 输入框换了面板(收起、上屏、失去焦点):网格跟着收起。 void onGridUiEvent(fcitx::Event &event); /// 在会话总线上登记 org.wowtype.Input(外部命令切模式)。 @@ -798,6 +799,7 @@ class WowtypeEngine final : public fcitx::InputMethodEngineV2 { std::unique_ptr gridAckSlot_; std::unique_ptr gridSelectSlot_; std::unique_ptr gridForgetSlot_; + std::unique_ptr gridPageSlot_; std::string gridOwner_; uint32_t gridSerial_ = 0; uint32_t gridAckedSerial_ = 0; diff --git a/themes/gnome-shell/wowtype-theme@gloridust.github.io/grid.js b/themes/gnome-shell/wowtype-theme@gloridust.github.io/grid.js index 0e49b40a..b183a4ca 100644 --- a/themes/gnome-shell/wowtype-theme@gloridust.github.io/grid.js +++ b/themes/gnome-shell/wowtype-theme@gloridust.github.io/grid.js @@ -114,14 +114,45 @@ export class CandidateGrid { this._header = new St.Label({style_class: 'kimpanel-label wowtype-grid-header', visible: false}); this._layout = new Clutter.GridLayout({column_spacing: 0, row_spacing: 0}); this._grid = new St.Widget({style_class: 'wowtype-grid', layout_manager: this._layout}); - this._page = new St.Label({ - style_class: 'wowtype-grid-page', + this._pager = new St.BoxLayout({ + style_class: 'wowtype-grid-pager', x_align: Clutter.ActorAlign.END, visible: false, }); + this._prevBtn = new St.Label({ + style_class: 'wowtype-grid-page-btn', + text: '‹', + reactive: true, + track_hover: true, + y_align: Clutter.ActorAlign.CENTER, + }); + this._prevBtn.connect('button-release-event', (_actor, event) => { + if (event.get_button() === Clutter.BUTTON_PRIMARY) + this._pageStep(-1); + return Clutter.EVENT_STOP; + }); + this._page = new St.Label({ + style_class: 'wowtype-grid-page', + y_align: Clutter.ActorAlign.CENTER, + }); + this._nextBtn = new St.Label({ + style_class: 'wowtype-grid-page-btn', + text: '›', + reactive: true, + track_hover: true, + y_align: Clutter.ActorAlign.CENTER, + }); + this._nextBtn.connect('button-release-event', (_actor, event) => { + if (event.get_button() === Clutter.BUTTON_PRIMARY) + this._pageStep(1); + return Clutter.EVENT_STOP; + }); + this._pager.add_child(this._prevBtn); + this._pager.add_child(this._page); + this._pager.add_child(this._nextBtn); this._content.add_child(this._header); this._content.add_child(this._grid); - this._content.add_child(this._page); + this._content.add_child(this._pager); this._box.bin.set_child(this._content); // addChrome:X11 下点得到(输入区域),和 kimpanel 一样 @@ -245,6 +276,18 @@ export class CandidateGrid { } } + _pageStep(delta) { + this._closeMenu(); + if (!this._shown || !this._sender || !delta) + return; + try { + Gio.DBus.session.emit_signal(this._sender, OBJECT_PATH, INTERFACE, 'Page', + new GLib.Variant('(ui)', [this._serial, delta])); + } catch (e) { + console.error('WowType 展开面板翻页发不出去:', e); + } + } + // 右键菜单挂在鼠标处,放不下时往左、往上挪进屏幕 _openMenu(index, [px, py]) { this._menuIndex = index; @@ -292,7 +335,11 @@ export class CandidateGrid { this._header.text = header || ''; this._header.visible = !!header; this._page.text = `${page + 1}/${pages}`; - this._page.visible = pages > 1; + this._pager.visible = pages > 1; + this._prevBtn.reactive = page > 0; + this._prevBtn.opacity = page > 0 ? 255 : 90; + this._nextBtn.reactive = page + 1 < pages; + this._nextBtn.opacity = page + 1 < pages ? 255 : 90; const cursorRow = Math.floor((cursor - first) / cols); for (let i = 0; i < Math.max(cells.length, this._cells.length); i++) { diff --git a/themes/gnome-shell/wowtype-theme@gloridust.github.io/stylesheet.css b/themes/gnome-shell/wowtype-theme@gloridust.github.io/stylesheet.css index 7df2af37..7b1db420 100644 --- a/themes/gnome-shell/wowtype-theme@gloridust.github.io/stylesheet.css +++ b/themes/gnome-shell/wowtype-theme@gloridust.github.io/stylesheet.css @@ -47,12 +47,28 @@ margin-right: 0.35em; } +.wowtype-grid-pager { + spacing: 2px; + padding: 0.2em 0.35em 0 0; +} + .wowtype-grid-page { font-size: 0.8em; - padding: 0.2em 0.6em 0 0; + padding: 0 0.25em; color: rgba(127, 127, 127, 0.9); } +.wowtype-grid-page-btn { + font-size: 0.95em; + padding: 0.05em 0.45em; + border-radius: 6px; + color: rgba(127, 127, 127, 0.95); +} + +.wowtype-grid-page-btn:hover { + background-color: rgba(14, 175, 118, 0.16); +} + /* 展开面板网格上右键的小菜单「忘掉这个词」(#229),外观照 popup-menu */ .wowtype-grid-menu { border-radius: 12px;