Skip to content

Commit

Permalink
Use addon factory v2
Browse files Browse the repository at this point in the history
  • Loading branch information
wengxt committed Jan 18, 2025
1 parent 8d03100 commit 5257b7c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
cmake_minimum_required(VERSION 3.6)
project(fcitx5-chewing VERSION 5.1.6)

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})

find_package(PkgConfig REQUIRED)
find_package(Fcitx5Core 5.1.9 REQUIRED)
find_package(Fcitx5Core ${REQUIRED_FCITX_VERSION} REQUIRED)
find_package(Fcitx5Module REQUIRED COMPONENTS TestFrontend)
find_package(Gettext REQUIRED)
include(FeatureSummary)
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set(CHEWING_SOURCES
eim.cpp
)
add_library(chewing MODULE ${CHEWING_SOURCES})
add_fcitx5_addon(chewing ${CHEWING_SOURCES})
target_link_libraries(chewing Fcitx5::Core Fcitx5::Config ${CHEWING_TARGET})
target_compile_definitions(chewing PRIVATE FCITX_GETTEXT_DOMAIN=\"fcitx5-chewing\")
fcitx5_add_i18n_definition(TARGETS chewing)
Expand Down
3 changes: 3 additions & 0 deletions src/chewing-addon.conf.in.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ OnDemand=True
Configurable=True
Library=libchewing

[Addon/Dependencies]
0=core:@REQUIRED_FCITX_VERSION@

[Addon/OptionalDependencies]
0=chttrans

18 changes: 13 additions & 5 deletions src/eim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
*
*/
#include "eim.h"
#include <chewing.h>
#include <cstdarg>
#include <cstdio>
#include <fcitx-utils/keysym.h>
#include <fcitx-utils/keysymgen.h>
#include <fcitx-utils/log.h>
#include <fcitx-utils/utf8.h>
Expand All @@ -20,6 +23,7 @@
#include <fcitx/userinterfacemanager.h>
#include <memory>
#include <utility>
#include <vector>

FCITX_DEFINE_LOG_CATEGORY(chewing_log, "chewing");
#define CHEWING_DEBUG() FCITX_LOGC(chewing_log, Debug)
Expand Down Expand Up @@ -445,7 +449,8 @@ void ChewingEngine::keyEvent(const InputMethodEntry &entry,
CHEWING_DEBUG() << "KeyEvent: " << keyEvent.key().toString();

if (handleCandidateKeyEvent(keyEvent)) {
return keyEvent.filterAndAccept();
keyEvent.filterAndAccept();
return;
}

if (keyEvent.key().check(FcitxKey_space)) {
Expand All @@ -462,7 +467,8 @@ void ChewingEngine::keyEvent(const InputMethodEntry &entry,
// Workaround a bug in libchewing fixed in 2017 but never has
// stable release.
if (zuin.size() >= 9) {
return keyEvent.filterAndAccept();
keyEvent.filterAndAccept();
return;
}
}
chewing_handle_Default(ctx, scan_code);
Expand All @@ -476,7 +482,8 @@ void ChewingEngine::keyEvent(const InputMethodEntry &entry,
if ((chewing_buffer_Check(ctx)) == 0 &&
(chewing_bopomofo_Check(ctx) == 0)) {
keyEvent.filterAndAccept();
return reset(entry, keyEvent);
reset(entry, keyEvent);
return;
}
} else if (keyEvent.key().check(FcitxKey_Escape)) {
chewing_handle_Esc(ctx);
Expand All @@ -489,7 +496,8 @@ void ChewingEngine::keyEvent(const InputMethodEntry &entry,
if ((chewing_buffer_Check(ctx)) == 0 &&
(chewing_bopomofo_Check(ctx) == 0)) {
keyEvent.filterAndAccept();
return reset(entry, keyEvent);
reset(entry, keyEvent);
return;
}
} else if (keyEvent.key().check(FcitxKey_Up)) {
chewing_handle_Up(ctx);
Expand Down Expand Up @@ -659,4 +667,4 @@ void ChewingEngine::flushBuffer(InputContextEvent &event) {

} // namespace fcitx

FCITX_ADDON_FACTORY(fcitx::ChewingEngineFactory);
FCITX_ADDON_FACTORY_V2(chewing, fcitx::ChewingEngineFactory);
8 changes: 7 additions & 1 deletion src/eim.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,26 @@
#define _FCITX5_CHEWING_EIM_H_

#include <chewing.h>
#include <cstddef>
#include <fcitx-config/configuration.h>
#include <fcitx-config/enum.h>
#include <fcitx-config/iniparser.h>
#include <fcitx-config/option.h>
#include <fcitx-config/rawconfig.h>
#include <fcitx-utils/i18n.h>
#include <fcitx-utils/misc.h>
#include <fcitx-utils/trackableobject.h>
#include <fcitx/addonfactory.h>
#include <fcitx/addoninstance.h>
#include <fcitx/addonmanager.h>
#include <fcitx/candidatelist.h>
#include <fcitx/event.h>
#include <fcitx/inputcontext.h>
#include <fcitx/inputmethodengine.h>
#include <fcitx/instance.h>
#include <fcitx/text.h>
#include <string>
#include <vector>

namespace fcitx {

Expand Down Expand Up @@ -122,7 +128,7 @@ class ChewingLayoutOption : public Option<ChewingLayout> {
}

private:
static inline std::vector<ChewingLayout> supportedLayouts() {
static std::vector<ChewingLayout> supportedLayouts() {
std::vector<ChewingLayout> supported = {ChewingLayout::Default};
auto defaultNum = chewing_KBStr2Num(builtin_keymaps[0]);
for (size_t i = 1; i < ChewingLayoutI18NAnnotation::enumLength; i++) {
Expand Down

0 comments on commit 5257b7c

Please sign in to comment.