Skip to content
Draft
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
3 changes: 2 additions & 1 deletion bamboo/bamboo-c.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ func NewEngine(name *C.cchar, dictHandle uintptr, tableHandle uintptr) uintptr {
timeFormat: "%H:%M",
dateFormat: "%d/%m/%Y",
}
engine.rebuildAppendingKeySet()
return uintptr(cgo.NewHandle(engine))
}

Expand Down Expand Up @@ -201,7 +202,7 @@ func NewCustomEngine(definition **C.char, dictHandle uintptr, tableHandle uintpt
timeFormat: "%H:%M",
dateFormat: "%d/%m/%Y",
}

engine.rebuildAppendingKeySet()
return uintptr(cgo.NewHandle(engine))
}

Expand Down
2 changes: 1 addition & 1 deletion bamboo/bamboo-core
Submodule bamboo-core updated 1 files
+20 −9 utils.go
16 changes: 14 additions & 2 deletions bamboo/fcitxbambooengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

type FcitxBambooEngine struct {
preeditor bamboo.IEngine
appendingKeySet map[rune]struct{}
macroTable *MacroTable
dictionary map[string]bool
autoNonVnRestore bool
Expand Down Expand Up @@ -208,6 +209,14 @@ func (e *FcitxBambooEngine) getBambooInputMode() bamboo.Mode {
return bamboo.VietnameseMode
}

func (e *FcitxBambooEngine) rebuildAppendingKeySet() {
keys := e.preeditor.GetInputMethod().AppendingKeys
e.appendingKeySet = make(map[rune]struct{}, len(keys))
for _, k := range keys {
e.appendingKeySet[k] = struct{}{}
}
}

func inKeyList(list []rune, key rune) bool {
for _, s := range list {
if s == key {
Expand All @@ -225,7 +234,10 @@ func (e *FcitxBambooEngine) toUpper(keyRune rune) rune {
'}': ']',
}

if upperSpecialKey, found := keyMapping[keyRune]; found && inKeyList(e.preeditor.GetInputMethod().AppendingKeys, keyRune) {
if upperSpecialKey, found := keyMapping[keyRune]; found {
if _, ok := e.appendingKeySet[keyRune]; !ok {
return keyRune
}
keyRune = upperSpecialKey
}
return keyRune
Expand Down Expand Up @@ -272,7 +284,7 @@ func (e *FcitxBambooEngine) getCommitText(keyVal, state uint32) (string, bool) {
keyRune = e.toUpper(keyRune)
}
e.preeditor.ProcessKey(keyRune, e.getBambooInputMode())
if inKeyList(e.preeditor.GetInputMethod().AppendingKeys, keyRune) {
if _, ok := e.appendingKeySet[keyRune]; ok {
var newText string
if e.shouldFallbackToEnglish(true) {
newText = e.getProcessedString(bamboo.EnglishMode)
Expand Down
13 changes: 10 additions & 3 deletions src/ack-apps.h → src/app_quirks.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,25 @@
*/

/**
* @file ack-apps.h
* @file app_quirks.h
* @brief List of applications requiring acknowledgment workaround.
*
* These browsers need special handling for uinput mode to work correctly.
*/

#include <string>
#include <vector>
#include <string_view>

/**
* @brief List of application names requiring ACK workaround.
*
* Chromium-based browsers that need special handling for text replacement.
*/
static std::vector<std::string> ack_apps = {"chrome", "chromium", "brave", "edge", "vivaldi", "opera", "coccoc", "cromite", "helium", "thorium", "slimjet", "yandex"};
inline constexpr std::array<std::string_view, 12> ack_apps = {"chrome", "chromium", "brave", "edge", "vivaldi", "opera",
"coccoc", "cromite", "helium", "thorium", "slimjet", "yandex"};

/**
* @brief List of application names have goood support surrowding text
*
*/
inline constexpr std::array<std::string_view, 1> surrtp_apps = {"soffice"};
20 changes: 13 additions & 7 deletions src/lotus-engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "lotus-candidates.h"
#include "lotus-monitor.h"
#include "lotus-utils.h"
#include "ack-apps.h"
#include "app_quirks.h"
#include <sys/socket.h>
#include <utility>
#ifndef DISABLE_VERSION_ACTION
Expand Down Expand Up @@ -376,6 +376,7 @@ namespace fcitx {
// TODO: Properly fixes instead ugly WA
state->wa_chromium_flag = false;

state->surrtp = false;
state->waitAck_ = false;
if (*config_.fixUinputWithAck) {
if (targetMode == LotusMode::Uinput || targetMode == LotusMode::UinputHC || targetMode == LotusMode::Smooth) {
Expand All @@ -388,12 +389,18 @@ namespace fcitx {
if (appName.find(ackApp) != std::string::npos) {
if (is_dbus) {
state->waitAck_ = true;
LOTUS_INFO(ackApp + " detected, waiting for ack");
LOTUS_INFO(std::string(ackApp) + " detected, waiting for ack");
}
state->wa_chromium_flag = true;
break;
}
}
for (const auto& _App : surrtp_apps) {
if (appName.find(_App) != std::string::npos) {
state->surrtp = true;
break;
}
}
}
}
if (event.type() == EventType::InputContextFocusIn && is_dbus && !surrvalid) {
Expand Down Expand Up @@ -611,11 +618,10 @@ namespace fcitx {
}

void LotusEngine::deactivate(const InputMethodEntry& /*entry*/, InputContextEvent& event) {
auto* ic = event.inputContext();
auto* state = ic->propertyFor(&factory_);
const bool surrvalid = ic->surroundingText().isValid();
const bool is_dbus = getFrontendName(ic) == "dbus";
state->lastDeactivateTime_ = now_ms();
auto* ic = event.inputContext();
auto* state = ic->propertyFor(&factory_);
const bool surrvalid = ic->surroundingText().isValid();
const bool is_dbus = getFrontendName(ic) == "dbus";
if (realMode == LotusMode::Preedit && event.type() != EventType::InputContextFocusOut) {
state->commitBuffer();
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/lotus-engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ namespace fcitx {
* @param ic Current input context.
* @return Name of current program
*/
static std::string getProgramName(InputContext* ic);
std::string getProgramName(InputContext* ic);
};

/**
Expand Down
Loading
Loading