Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions fcitx5-engine/src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

enum class TriggerMode { Pause, Manual };
enum class AcceptKey { Tab, Enter, Right };
// How inline suggestions are marked in the app's text. Only apps that talk to
// Fcitx5 through its Qt or GTK module apply it; native Wayland text-input-v3
// clients (GTK without the module, Firefox, Electron) carry no styling and
// draw their own underline whatever is chosen.
enum class InlineFormat { Underline, Highlight, Bold, Italic, None };

struct InferenceConfig {
std::string model = "qwen2.5:1.5b";
Expand Down Expand Up @@ -61,9 +66,15 @@ struct AppOverride {
std::optional<std::string> prompt_addendum;
};

// [ghost]: how suggestions are shown.
struct GhostConfig {
InlineFormat inline_format = InlineFormat::Underline;
};

struct XTypeConfig {
InferenceConfig inference;
BehaviourConfig behaviour;
GhostConfig ghost;
LearningConfig learning;
UserPromptConfig user_prompt;
std::map<std::string, AppOverride> apps;
Expand Down
11 changes: 11 additions & 0 deletions fcitx5-engine/src/config_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ XTypeConfig config_loader::load(const std::string& path) {
}
}

// [ghost]
if (auto* t = tbl["ghost"].as_table()) {
if (auto v = (*t)["inline_format"].value<std::string>()) {
if (*v == "highlight") cfg.ghost.inline_format = InlineFormat::Highlight;
else if (*v == "bold") cfg.ghost.inline_format = InlineFormat::Bold;
else if (*v == "italic") cfg.ghost.inline_format = InlineFormat::Italic;
else if (*v == "none") cfg.ghost.inline_format = InlineFormat::None;
else cfg.ghost.inline_format = InlineFormat::Underline;
}
}

// [learning]
if (auto* t = tbl["learning"].as_table()) {
if (auto v = (*t)["enabled"].value<bool>()) cfg.learning.enabled = *v;
Expand Down
18 changes: 15 additions & 3 deletions fcitx5-engine/src/xtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,12 +471,24 @@ void XTypeEngine::requestInference(

// ── Preedit ───────────────────────────────────────────────────────────────────

// Preedit flags for an inline suggestion. DontCommit keeps the app from
// committing the ghost text itself (e.g. when focus moves away).
static fcitx::TextFormatFlags inlineFlags(InlineFormat f) {
fcitx::TextFormatFlags flags{fcitx::TextFormatFlag::DontCommit};
switch (f) {
case InlineFormat::Underline: flags |= fcitx::TextFormatFlag::Underline; break;
case InlineFormat::Highlight: flags |= fcitx::TextFormatFlag::HighLight; break;
case InlineFormat::Bold: flags |= fcitx::TextFormatFlag::Bold; break;
case InlineFormat::Italic: flags |= fcitx::TextFormatFlag::Italic; break;
case InlineFormat::None: break;
}
return flags;
}

void XTypeEngine::updatePreedit(fcitx::InputContext *ic) {
auto &panel = ic->inputPanel();
if (_ctx.hasSuggestion()) {
fcitx::Text t(*_ctx.suggestion(),
fcitx::TextFormatFlags{fcitx::TextFormatFlag::Underline,
fcitx::TextFormatFlag::DontCommit});
fcitx::Text t(*_ctx.suggestion(), inlineFlags(_cfg.ghost.inline_format));
panel.setClientPreedit(t);
} else {
panel.setClientPreedit(fcitx::Text{});
Expand Down
3 changes: 3 additions & 0 deletions fcitx5-engine/tests/fixtures/config_full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ passthrough_terminals = false
blocklist_apps = ["kate", "subl"]
blocked_phrases = ["pursuant to", "hereinafter"]

[ghost]
inline_format = "italic"

[learning]
enabled = true
corpus_path = "~/.local/share/xtype/corpus2.txt"
Expand Down
2 changes: 2 additions & 0 deletions fcitx5-engine/tests/test_config_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ TEST_CASE("empty file returns all defaults") {
CHECK(cfg.inference.temperature == Catch::Approx(0.3f).margin(0.001));
CHECK(cfg.behaviour.engine_enabled == true);
CHECK(cfg.behaviour.accept_full_key == AcceptKey::Tab);
CHECK(cfg.ghost.inline_format == InlineFormat::Underline);
CHECK(cfg.learning.enabled == false);
CHECK(cfg.user_prompt.description.empty());
CHECK(cfg.apps.empty());
Expand All @@ -29,6 +30,7 @@ TEST_CASE("full config round-trips every field") {
CHECK(cfg.behaviour.partial_accept == false);
CHECK(cfg.behaviour.blocklist_apps == std::vector<std::string>{"kate", "subl"});
CHECK(cfg.behaviour.blocked_phrases == std::vector<std::string>{"pursuant to", "hereinafter"});
CHECK(cfg.ghost.inline_format == InlineFormat::Italic);
CHECK(cfg.learning.enabled == true);
CHECK(cfg.learning.max_corpus_mb == 25);
CHECK(cfg.learning.voice_strength == 80);
Expand Down
23 changes: 23 additions & 0 deletions settings/qt6-app/qml/pages/PageGeneral.qml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,29 @@ Item {
}
}
}
XRow {
label: "Inline look"
desc: "Qt apps only; Firefox, Electron and most GTK apps always underline."
width: parent.width
Row {
spacing: 6
Repeater {
model: [
{ label: "Underline", value: "underline" },
{ label: "Highlight", value: "highlight" },
{ label: "Bold", value: "bold" },
{ label: "Italic", value: "italic" },
{ label: "None", value: "none" },
]
delegate: XPill {
required property var modelData
label: modelData.label
on: Config.ghostInlineFormat === modelData.value
onClicked: Config.ghostInlineFormat = modelData.value
}
}
}
}
XRow {
label: "Partial accept (word-by-word)"
desc: "Accept one word at a time"
Expand Down
13 changes: 13 additions & 0 deletions settings/qt6-app/src/config_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ void ConfigStore::load() {
}
}

// --- [ghost] ---
if (auto *g = root["ghost"].as_table()) {
if (auto v = (*g)["inline_format"].value<std::string>()) _ghostInlineFormat = QString::fromStdString(*v);
}

// --- [learning] ---
if (auto *lrn = root["learning"].as_table()) {
if (auto v = (*lrn)["enabled"].value<bool>()) _learningEnabled = *v;
Expand Down Expand Up @@ -189,6 +194,11 @@ void ConfigStore::writeToml(const QString &path) {
writeStringArray(beh, "blocked_phrases", _blockedPhrases);
root.insert_or_assign("behaviour", std::move(beh));

// [ghost]
toml::table ghost;
ghost.insert_or_assign("inline_format", _ghostInlineFormat.toStdString());
root.insert_or_assign("ghost", std::move(ghost));

// [learning]
toml::table lrn;
lrn.insert_or_assign("enabled", _learningEnabled);
Expand Down Expand Up @@ -263,6 +273,7 @@ void ConfigStore::resetAll() {
_engineEnabled = true;
_triggerMode = "pause";
_acceptKey = "tab";
_ghostInlineFormat = "underline";
_partialAccept = true;
_escDismisses = true;
_passThroughTerminals = true;
Expand Down Expand Up @@ -306,6 +317,7 @@ void ConfigStore::resetAll() {
emit engineEnabledChanged();
emit triggerModeChanged();
emit acceptKeyChanged();
emit ghostInlineFormatChanged();
emit partialAcceptChanged();
emit escDismissesChanged();
emit passThroughTerminalsChanged();
Expand Down Expand Up @@ -349,6 +361,7 @@ void ConfigStore::setEscDismisses(bool v) { CS_SET(escDismisses,
void ConfigStore::setPassThroughTerminals(bool v) { CS_SET(passThroughTerminals, passThroughTerminalsChanged); }
void ConfigStore::setTriggerMode(const QString &v) { CS_SET(triggerMode, triggerModeChanged); }
void ConfigStore::setAcceptKey(const QString &v) { CS_SET(acceptKey, acceptKeyChanged); }
void ConfigStore::setGhostInlineFormat(const QString &v){ CS_SET(ghostInlineFormat, ghostInlineFormatChanged); }
void ConfigStore::setBlocklistApps(const QStringList &v){ CS_SET(blocklistApps, blocklistAppsChanged); }
void ConfigStore::setBlockedPhrases(const QStringList &v){ CS_SET(blockedPhrases, blockedPhrasesChanged); }

Expand Down
8 changes: 7 additions & 1 deletion settings/qt6-app/src/config_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
#include <QVariantMap>

// TOML key names mirror XTypeConfig struct fields exactly (snake_case).
// Enum strings: TriggerMode → "pause"|"manual"; AcceptKey → "tab"|"enter"|"right".
// Enum strings: TriggerMode → "pause"|"manual"; AcceptKey → "tab"|"enter"|"right";
// [ghost] inline_format → "underline"|"highlight"|"bold"|"italic"|"none".
// std::optional round-trip: absent key ↔ invalid QVariant / empty optional.

class ConfigStore : public QObject {
Expand All @@ -18,6 +19,7 @@ class ConfigStore : public QObject {
Q_PROPERTY(bool engineEnabled READ engineEnabled WRITE setEngineEnabled NOTIFY engineEnabledChanged)
Q_PROPERTY(QString triggerMode READ triggerMode WRITE setTriggerMode NOTIFY triggerModeChanged)
Q_PROPERTY(QString acceptKey READ acceptKey WRITE setAcceptKey NOTIFY acceptKeyChanged)
Q_PROPERTY(QString ghostInlineFormat READ ghostInlineFormat WRITE setGhostInlineFormat NOTIFY ghostInlineFormatChanged)
Q_PROPERTY(bool partialAccept READ partialAccept WRITE setPartialAccept NOTIFY partialAcceptChanged)
Q_PROPERTY(bool escDismisses READ escDismisses WRITE setEscDismisses NOTIFY escDismissesChanged)
Q_PROPERTY(bool passThroughTerminals READ passThroughTerminals WRITE setPassThroughTerminals NOTIFY passThroughTerminalsChanged)
Expand Down Expand Up @@ -67,6 +69,7 @@ class ConfigStore : public QObject {
bool engineEnabled() const { return _engineEnabled; }
QString triggerMode() const { return _triggerMode; }
QString acceptKey() const { return _acceptKey; }
QString ghostInlineFormat() const { return _ghostInlineFormat; }
bool partialAccept() const { return _partialAccept; }
bool escDismisses() const { return _escDismisses; }
bool passThroughTerminals() const { return _passThroughTerminals; }
Expand Down Expand Up @@ -103,6 +106,7 @@ class ConfigStore : public QObject {
void setEngineEnabled(bool v);
void setTriggerMode(const QString &v);
void setAcceptKey(const QString &v);
void setGhostInlineFormat(const QString &v);
void setPartialAccept(bool v);
void setEscDismisses(bool v);
void setPassThroughTerminals(bool v);
Expand Down Expand Up @@ -151,6 +155,7 @@ public slots:
void engineEnabledChanged();
void triggerModeChanged();
void acceptKeyChanged();
void ghostInlineFormatChanged();
void partialAcceptChanged();
void escDismissesChanged();
void passThroughTerminalsChanged();
Expand Down Expand Up @@ -194,6 +199,7 @@ public slots:
bool _engineEnabled = true;
QString _triggerMode = "pause";
QString _acceptKey = "tab";
QString _ghostInlineFormat = "underline";
bool _partialAccept = true;
bool _escDismisses = true;
bool _passThroughTerminals = true;
Expand Down
17 changes: 17 additions & 0 deletions settings/qt6-app/tests/test_config_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,20 @@ TEST_CASE("resetAll: backup file exists, main file reverts to defaults", "[confi
CHECK(cs2.model() == "qwen2.5:1.5b");
CHECK(cs2.debounceMs() == 220);
}

TEST_CASE("[ghost] inline_format round-trip and default", "[config_store]") {
QTemporaryDir tmp; REQUIRE(tmp.isValid());
const QString dst = tmp.filePath("config.toml");

{
ConfigStore cs(dst);
cs.load();
CHECK(cs.ghostInlineFormat() == "underline");
cs.setGhostInlineFormat("italic");
cs.saveNow();
}

ConfigStore cs2(dst);
cs2.load();
CHECK(cs2.ghostInlineFormat() == "italic");
}