Files
qingjian/apps/linux/fcitx5/tests/support/input.h
T
jacklaoz 916bd29e15 feat(linux): 能在 FreeBSD 上源码安装 (#681)
Server、Fcitx5 插件与设置程序与 Linux 共用,差异按 target_os 分开:对端身份用 getpeereid、快捷键缺省走 Linux 那套、字体补 /usr/local 路径、安装脚本不用 GNU 独有的 realpath -m;mio 升到 1.2.4。
2026-10-19 16:08:00 +08:00

30 lines
1.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! 可观测应用上屏与可重入 preedit 回调的真实 Fcitx 上下文。
#pragma once
#include <fcitx/inputcontext.h>
#include <fcitx/inputpanel.h>
#include <functional>
#include <utility>
class Input final : public fcitx::InputContext {
public:
explicit Input(fcitx::InputContextManager &manager) : InputContext(manager, "real-test") { created(); setCapabilityFlags(fcitx::CapabilityFlag::Preedit); }
~Input() override { destroy(); }
const char *frontend() const override { return "test"; }
std::string committed;
std::function<void()> preeditHook;
std::function<void()> commitHook;
std::string preedit() const { return inputPanel().clientPreedit().toString(); }
protected:
void commitStringImpl(const std::string &text) override {
committed += text;
// 回调只触发一次。不用 std::move:libc++ 不保证移走后的 std::function 变空
auto callback = std::exchange(commitHook, nullptr);
if (callback) callback();
}
void deleteSurroundingTextImpl(int, unsigned int) override {}
void forwardKeyImpl(const fcitx::ForwardKeyEvent &) override {}
void updatePreeditImpl() override { auto callback = std::exchange(preeditHook, nullptr); if (callback) callback(); }
};