diff --git a/CMakeLists.txt b/CMakeLists.txt index 884bcdb..f4efc60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,7 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.12) project(fcitx5-libthai VERSION 5.1.4) + +set(REQUIRED_FCITX_VERSION 5.1.12) find_package(ECM REQUIRED 1.0.0) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) include(FeatureSummary) @@ -7,7 +9,7 @@ include(GNUInstallDirs) include(ECMUninstallTarget) find_package(PkgConfig REQUIRED) -find_package(Fcitx5Core 5.0.2 REQUIRED) +find_package(Fcitx5Core ${REQUIRED_FCITX_VERSION} REQUIRED) find_package(Iconv REQUIRED) find_package(Gettext REQUIRED) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f3d4ed0..be9f031 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,5 @@ -add_library(iconvwrapper STATIC iconvwrapper.cpp) +add_library(iconvwrapper OBJECT iconvwrapper.cpp) set_target_properties(iconvwrapper PROPERTIES POSITION_INDEPENDENT_CODE ON) target_link_libraries(iconvwrapper Fcitx5::Utils Iconv::Iconv) @@ -7,7 +7,7 @@ set(LIBTHAI_SOURCES engine.cpp thaikb.cpp ) -add_library(libthai MODULE ${LIBTHAI_SOURCES}) +add_fcitx5_addon(libthai ${LIBTHAI_SOURCES}) target_link_libraries(libthai iconvwrapper Fcitx5::Core ${THAI_TARGET} Iconv::Iconv) target_include_directories(libthai PRIVATE ${PROJECT_BINARY_DIR}) set_target_properties(libthai PROPERTIES PREFIX "") diff --git a/src/engine.cpp b/src/engine.cpp index 1c5ad52..87447f3 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -5,18 +5,38 @@ * */ #include "engine.h" +#include "thaikb.h" +#include +#include +#include #include +#include +#include +#include +#include #include #include +#include +#include #include #include +#include +#include +#include +#include +#include #include #include +#include -namespace fcitx { +namespace { FCITX_DEFINE_LOG_CATEGORY(libthai_log, "libthai"); +} + +namespace fcitx { + #define LIBTHAI_DEBUG() FCITX_LOGC(libthai_log, Debug) constexpr auto FALLBACK_BUFF_SIZE = 4; @@ -99,11 +119,13 @@ LibThaiEngine::LibThaiEngine(Instance *instance) LibThaiEngine::~LibThaiEngine() {} -void LibThaiEngine::activate(const InputMethodEntry &, InputContextEvent &) {} +void LibThaiEngine::activate(const InputMethodEntry & /*entry*/, + InputContextEvent & /*event*/) {} -void LibThaiEngine::deactivate(const InputMethodEntry &, InputContextEvent &) {} +void LibThaiEngine::deactivate(const InputMethodEntry & /*entry*/, + InputContextEvent & /*event*/) {} -bool isContextIntactKey(Key key) { +static bool isContextIntactKey(Key key) { return (((key.sym() & 0xFF00) == 0xFF00) && (/* IsModifierKey */ @@ -114,7 +136,7 @@ bool isContextIntactKey(Key key) { key.sym() <= FcitxKey_ISO_Last_Group_Lock)); } -bool isContextLostKey(Key key) { +static bool isContextLostKey(Key key) { return ((key.sym() & 0xFF00) == 0xFF00) && (key.sym() == FcitxKey_BackSpace || key.sym() == FcitxKey_Tab || @@ -134,12 +156,13 @@ bool isContextLostKey(Key key) { (FcitxKey_F1 <= key.sym() && key.sym() <= FcitxKey_F35)); } -void LibThaiEngine::keyEvent(const InputMethodEntry &, KeyEvent &keyEvent) { +void LibThaiEngine::keyEvent(const InputMethodEntry & /*entry*/, + KeyEvent &keyEvent) { auto key = keyEvent.rawKey(); if (keyEvent.isRelease()) { return; } - auto state = keyEvent.inputContext()->propertyFor(&factory_); + auto *state = keyEvent.inputContext()->propertyFor(&factory_); // If any ctrl alt super modifier is pressed, ignore. if (key.states().testAny(KeyStates{KeyState::Ctrl_Alt, KeyState::Super}) || isContextLostKey(key)) { @@ -187,7 +210,7 @@ void LibThaiEngine::keyEvent(const InputMethodEntry &, KeyEvent &keyEvent) { prevChar = prevChars.back(); } if (!th_isaccept(prevChar, newChar, *config_.strictness)) { - return keyEvent.filterAndAccept(); + keyEvent.filterAndAccept(); return; } if (state->commitString(&newChar, 1)) { keyEvent.filterAndAccept(); @@ -200,14 +223,14 @@ void LibThaiEngine::keyEvent(const InputMethodEntry &, KeyEvent &keyEvent) { state->prevCell(&contextCell); if (!th_validate_leveled(contextCell, newChar, &conv, *config_.strictness)) { - return keyEvent.filterAndAccept(); + keyEvent.filterAndAccept(); return; } if (conv.offset < 0) { // SurroundingText not supported, so just reject the key. if (!keyEvent.inputContext()->capabilityFlags().test( CapabilityFlag::SurroundingText)) { - return keyEvent.filter(); + keyEvent.filter(); return; } keyEvent.inputContext()->deleteSurroundingText(conv.offset, @@ -217,15 +240,15 @@ void LibThaiEngine::keyEvent(const InputMethodEntry &, KeyEvent &keyEvent) { state->rememberPrevChars(newChar); if (state->commitString(conv.conv, strlen(reinterpret_cast(conv.conv)))) { - return keyEvent.filterAndAccept(); + keyEvent.filterAndAccept(); return; } } -void LibThaiEngine::reset(const InputMethodEntry &, InputContextEvent &event) { - auto state = event.inputContext()->propertyFor(&factory_); +void LibThaiEngine::reset(const InputMethodEntry & /*entry*/, InputContextEvent &event) { + auto *state = event.inputContext()->propertyFor(&factory_); state->forgetPrevChars(); } } // namespace fcitx -FCITX_ADDON_FACTORY(fcitx::LibThaiFactory); +FCITX_ADDON_FACTORY_V2(libthai, fcitx::LibThaiFactory); diff --git a/src/engine.h b/src/engine.h index c62f58d..653ae5d 100644 --- a/src/engine.h +++ b/src/engine.h @@ -9,10 +9,16 @@ #include "iconvwrapper.h" #include "thaikb.h" +#include +#include #include +#include +#include #include #include +#include #include +#include #include #include #include @@ -47,7 +53,7 @@ class LibThaiEngine final : public InputMethodEngine { void keyEvent(const InputMethodEntry &entry, KeyEvent &keyEvent) override; void reset(const InputMethodEntry &entry, InputContextEvent &event) override; - void deactivate(const fcitx::InputMethodEntry &, + void deactivate(const fcitx::InputMethodEntry & /*entry*/, fcitx::InputContextEvent &event) override; const fcitx::Configuration *getConfig() const override { return &config_; } void setConfig(const fcitx::RawConfig &raw) override { diff --git a/src/iconvwrapper.cpp b/src/iconvwrapper.cpp index 972b8ce..cb93d40 100644 --- a/src/iconvwrapper.cpp +++ b/src/iconvwrapper.cpp @@ -6,8 +6,14 @@ */ #include "iconvwrapper.h" +#include +#include #include #include +#include +#include +#include +#include class IconvWrapperPrivate { public: @@ -30,7 +36,7 @@ IconvWrapper::operator bool() const { } std::vector IconvWrapper::tryConvert(std::string_view s) const { - auto conv = d_ptr->conv_; + iconv_t conv = d_ptr->conv_; for (auto iter = std::begin(s), e = std::end(s); iter != e; iter = fcitx::utf8::nextChar(iter)) { std::vector result; diff --git a/src/libthai-addon.conf.in.in b/src/libthai-addon.conf.in.in index c1c223a..6cff9fe 100644 --- a/src/libthai-addon.conf.in.in +++ b/src/libthai-addon.conf.in.in @@ -6,3 +6,6 @@ Library=libthai Type=SharedLibrary OnDemand=True Configurable=True + +[Addon/Dependencies] +0=core:@REQUIRED_FCITX_VERSION@