From 19a66fe2e364dd72468139e73b9529d8e5fcf586 Mon Sep 17 00:00:00 2001 From: Weng Xuetian Date: Mon, 18 Nov 2024 12:55:01 -0800 Subject: [PATCH] Introduce FCITX_ADDON_FACTORY_V2 and FCITX_IMPORT_ADDON_FACTORY FCITX_ADDON_FACTORY_V2 will generate an entry based on addon name, so it will be unique and can be referenced more easily with static addon loader. --- .../dbusfrontend/dbusfrontend.conf.in.in | 4 +-- src/frontend/dbusfrontend/dbusfrontend.cpp | 2 +- .../fcitx4frontend/fcitx4frontend.conf.in.in | 3 ++- .../fcitx4frontend/fcitx4frontend.cpp | 2 +- .../ibusfrontend/ibusfrontend.conf.in.in | 3 ++- src/frontend/ibusfrontend/ibusfrontend.cpp | 2 +- src/frontend/waylandim/waylandim.conf.in.in | 3 ++- src/frontend/waylandim/waylandim.cpp | 2 +- src/frontend/xim/xim.conf.in.in | 3 ++- src/frontend/xim/xim.cpp | 2 +- src/im/keyboard/CMakeLists.txt | 1 - src/im/keyboard/keyboard.conf.in.in | 3 +++ src/im/keyboard/keyboard.cpp | 3 +++ src/lib/fcitx/addoninstance.h | 27 +++++++++++++++++++ src/lib/fcitx/addonloader.cpp | 16 ++++++++--- src/lib/fcitx/addonloader.h | 8 +++--- src/lib/fcitx/addonloader_p.h | 20 ++++++++++++-- src/modules/clipboard/clipboard.conf.in.in | 5 ++-- src/modules/clipboard/clipboard.cpp | 2 +- src/modules/dbus/dbus.conf.in.in | 3 ++- src/modules/dbus/dbusmodule.cpp | 2 +- src/modules/emoji/emoji.conf.in.in | 3 +++ src/modules/emoji/emoji.cpp | 2 +- src/modules/imselector/imselector.conf.in.in | 3 +++ src/modules/imselector/imselector.cpp | 2 +- .../notificationitem.conf.in.in | 4 +-- .../notificationitem/notificationitem.cpp | 3 ++- .../notifications/notifications.conf.in.in | 3 ++- src/modules/notifications/notifications.cpp | 2 +- src/modules/quickphrase/quickphrase.cpp | 2 +- src/modules/spell/spell.conf.in.in | 3 +++ src/modules/spell/spell.cpp | 2 +- src/modules/unicode/unicode.conf.in.in | 3 +++ src/modules/unicode/unicode.cpp | 2 +- src/modules/wayland/wayland.conf.in.in | 3 +++ src/modules/wayland/waylandmodule.cpp | 2 +- src/modules/xcb/xcb.conf.in.in | 3 +++ src/modules/xcb/xcbmodule.cpp | 2 +- src/server/main.cpp | 14 +++------- src/ui/classic/classicui.cpp | 2 +- src/ui/kimpanel/kimpanel.cpp | 2 +- src/ui/virtualkeyboard/virtualkeyboard.cpp | 4 ++- test/addon/dummyaddon.cpp | 2 +- test/addon/fcitx5/addon/testfrontend.conf | 3 +++ test/addon/fcitx5/addon/testim.conf | 3 +++ test/testcompose.cpp | 16 ++++++++--- test/testspell.cpp | 17 +++++++----- testing/testfrontend/testfrontend.conf | 2 ++ testing/testfrontend/testfrontend.cpp | 2 +- testing/testim/testim.conf | 3 ++- testing/testim/testim.cpp | 2 +- testing/testui/testui.conf | 3 +++ testing/testui/testui.cpp | 3 ++- 53 files changed, 170 insertions(+), 68 deletions(-) diff --git a/src/frontend/dbusfrontend/dbusfrontend.conf.in.in b/src/frontend/dbusfrontend/dbusfrontend.conf.in.in index 0a5e626d4..bf93102fd 100644 --- a/src/frontend/dbusfrontend/dbusfrontend.conf.in.in +++ b/src/frontend/dbusfrontend/dbusfrontend.conf.in.in @@ -6,5 +6,5 @@ Category=Frontend Version=@PROJECT_VERSION@ [Addon/Dependencies] -0=dbus - +0=core:@PROJECT_VERSION@ +1=dbus diff --git a/src/frontend/dbusfrontend/dbusfrontend.cpp b/src/frontend/dbusfrontend/dbusfrontend.cpp index 20c04fff9..73f9dd803 100644 --- a/src/frontend/dbusfrontend/dbusfrontend.cpp +++ b/src/frontend/dbusfrontend/dbusfrontend.cpp @@ -610,4 +610,4 @@ class DBusFrontendModuleFactory : public AddonFactory { }; } // namespace fcitx -FCITX_ADDON_FACTORY(fcitx::DBusFrontendModuleFactory); +FCITX_ADDON_FACTORY_V2(dbusfrontend, fcitx::DBusFrontendModuleFactory); diff --git a/src/frontend/fcitx4frontend/fcitx4frontend.conf.in.in b/src/frontend/fcitx4frontend/fcitx4frontend.conf.in.in index 07919a3c5..a5470192c 100644 --- a/src/frontend/fcitx4frontend/fcitx4frontend.conf.in.in +++ b/src/frontend/fcitx4frontend/fcitx4frontend.conf.in.in @@ -6,7 +6,8 @@ Category=Frontend Version=@PROJECT_VERSION@ [Addon/Dependencies] -0=dbus +0=core:@PROJECT_VERSION@ +1=dbus [Addon/OptionalDependencies] 0=xcb diff --git a/src/frontend/fcitx4frontend/fcitx4frontend.cpp b/src/frontend/fcitx4frontend/fcitx4frontend.cpp index e1b48947c..62b40ca66 100644 --- a/src/frontend/fcitx4frontend/fcitx4frontend.cpp +++ b/src/frontend/fcitx4frontend/fcitx4frontend.cpp @@ -366,4 +366,4 @@ class Fcitx4FrontendModuleFactory : public AddonFactory { }; } // namespace fcitx -FCITX_ADDON_FACTORY(fcitx::Fcitx4FrontendModuleFactory); +FCITX_ADDON_FACTORY_V2(fcitx4frontend, fcitx::Fcitx4FrontendModuleFactory); diff --git a/src/frontend/ibusfrontend/ibusfrontend.conf.in.in b/src/frontend/ibusfrontend/ibusfrontend.conf.in.in index aed719b09..7827f8206 100644 --- a/src/frontend/ibusfrontend/ibusfrontend.conf.in.in +++ b/src/frontend/ibusfrontend/ibusfrontend.conf.in.in @@ -6,5 +6,6 @@ Category=Frontend Version=@PROJECT_VERSION@ [Addon/Dependencies] -0=dbus +0=core:@PROJECT_VERSION@ +1=dbus diff --git a/src/frontend/ibusfrontend/ibusfrontend.cpp b/src/frontend/ibusfrontend/ibusfrontend.cpp index f3df669e3..39f1a3095 100644 --- a/src/frontend/ibusfrontend/ibusfrontend.cpp +++ b/src/frontend/ibusfrontend/ibusfrontend.cpp @@ -1010,4 +1010,4 @@ class IBusFrontendModuleFactory : public AddonFactory { }; } // namespace fcitx -FCITX_ADDON_FACTORY(fcitx::IBusFrontendModuleFactory); +FCITX_ADDON_FACTORY_V2(ibusfrontend, fcitx::IBusFrontendModuleFactory); diff --git a/src/frontend/waylandim/waylandim.conf.in.in b/src/frontend/waylandim/waylandim.conf.in.in index e70467d1d..d1ba18fd7 100644 --- a/src/frontend/waylandim/waylandim.conf.in.in +++ b/src/frontend/waylandim/waylandim.conf.in.in @@ -7,5 +7,6 @@ Version=@PROJECT_VERSION@ Configurable=True [Addon/Dependencies] -0=wayland:@PROJECT_VERSION@ +0=core:@PROJECT_VERSION@ +1=wayland:@PROJECT_VERSION@ diff --git a/src/frontend/waylandim/waylandim.cpp b/src/frontend/waylandim/waylandim.cpp index bc4e6085a..78f01fa4d 100644 --- a/src/frontend/waylandim/waylandim.cpp +++ b/src/frontend/waylandim/waylandim.cpp @@ -111,4 +111,4 @@ class WaylandIMModuleFactory : public AddonFactory { }; } // namespace fcitx -FCITX_ADDON_FACTORY(fcitx::WaylandIMModuleFactory); +FCITX_ADDON_FACTORY_V2(waylandim, fcitx::WaylandIMModuleFactory); diff --git a/src/frontend/xim/xim.conf.in.in b/src/frontend/xim/xim.conf.in.in index dd1fbcffa..133654deb 100644 --- a/src/frontend/xim/xim.conf.in.in +++ b/src/frontend/xim/xim.conf.in.in @@ -7,7 +7,8 @@ Version=@PROJECT_VERSION@ Configurable=True [Addon/Dependencies] -0=xcb +0=core:@PROJECT_VERSION@ +1=xcb # This intends to load xim after dbus & ibusfrontend, so xim is released before dbus. # This helps new fcitx server to become xim server properly when replacing. diff --git a/src/frontend/xim/xim.cpp b/src/frontend/xim/xim.cpp index c9b81a0b1..2dc18d7c6 100644 --- a/src/frontend/xim/xim.cpp +++ b/src/frontend/xim/xim.cpp @@ -705,4 +705,4 @@ class XIMModuleFactory : public AddonFactory { }; } // namespace fcitx -FCITX_ADDON_FACTORY(fcitx::XIMModuleFactory); +FCITX_ADDON_FACTORY_V2(xim, fcitx::XIMModuleFactory); diff --git a/src/im/keyboard/CMakeLists.txt b/src/im/keyboard/CMakeLists.txt index ae7691ad0..f898c6b32 100644 --- a/src/im/keyboard/CMakeLists.txt +++ b/src/im/keyboard/CMakeLists.txt @@ -6,7 +6,6 @@ endif() if (TARGET Fcitx5::Module::Emoji) target_link_libraries(keyboard Fcitx5::Module::Emoji) endif() -target_include_directories(keyboard PUBLIC "$") configure_file(keyboard.conf.in.in keyboard.conf.in @ONLY) fcitx5_translate_desktop_file(${CMAKE_CURRENT_BINARY_DIR}/keyboard.conf.in keyboard.conf) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/keyboard.conf" DESTINATION "${FCITX_INSTALL_PKGDATADIR}/addon" diff --git a/src/im/keyboard/keyboard.conf.in.in b/src/im/keyboard/keyboard.conf.in.in index 434cdf3f5..c9954dd4e 100644 --- a/src/im/keyboard/keyboard.conf.in.in +++ b/src/im/keyboard/keyboard.conf.in.in @@ -6,6 +6,9 @@ Category=InputMethod Version=@PROJECT_VERSION@ Configurable=True +[Addon/Dependencies] +0=core:@PROJECT_VERSION@ + [Addon/OptionalDependencies] 0=xcb 1=spell diff --git a/src/im/keyboard/keyboard.cpp b/src/im/keyboard/keyboard.cpp index 9b10efa4a..d09bac574 100644 --- a/src/im/keyboard/keyboard.cpp +++ b/src/im/keyboard/keyboard.cpp @@ -35,6 +35,7 @@ #include "fcitx-utils/stringutils.h" #include "fcitx-utils/textformatflags.h" #include "fcitx-utils/utf8.h" +#include "fcitx/addoninstance.h" #include "fcitx/candidatelist.h" #include "fcitx/event.h" #include "fcitx/inputcontext.h" @@ -940,3 +941,5 @@ bool KeyboardEngineState::handleBackspace(const InputMethodEntry &entry) { } } // namespace fcitx + +FCITX_ADDON_FACTORY_V2(keyboard, fcitx::KeyboardEngineFactory); diff --git a/src/lib/fcitx/addoninstance.h b/src/lib/fcitx/addoninstance.h index 30d311fcb..f4d58a952 100644 --- a/src/lib/fcitx/addoninstance.h +++ b/src/lib/fcitx/addoninstance.h @@ -199,6 +199,33 @@ class FCITXCORE_EXPORT AddonInstance { } \ } +#define FCITX_ADDON_FACTORY_V2(AddonName, ClassName) \ + extern "C" { \ + FCITXCORE_EXPORT \ + ::fcitx::AddonFactory *fcitx_addon_factory_instance_##AddonName() { \ + static ClassName factory; \ + return &factory; \ + } \ + } + +#define FCITX_ADDON_FACTORY_V2_BACKWARDS(AddonName, ClassName) \ + FCITX_ADDON_FACTORY_V2(AddonName, ClassName) \ + FCITX_ADDON_FACTORY(ClassName) + +#define FCITX_IMPORT_ADDON_FACTORY(StaticRegistry, AddonName) \ + extern "C" { \ + ::fcitx::AddonFactory *fcitx_addon_factory_instance_##AddonName(); \ + } \ + class StaticAddonRegistrar_##AddonName { \ + public: \ + StaticAddonRegistrar_##AddonName() { \ + (StaticRegistry) \ + .emplace(FCITX_STRINGIFY(AddonName), \ + fcitx_addon_factory_instance_##AddonName()); \ + } \ + }; \ + StaticAddonRegistrar_##AddonName staticAddonRegistrar_##AddonName + /// A convenient macro to obtain the addon pointer of another addon. #define FCITX_ADDON_DEPENDENCY_LOADER(NAME, ADDONMANAGER) \ auto NAME() { \ diff --git a/src/lib/fcitx/addonloader.cpp b/src/lib/fcitx/addonloader.cpp index efa9515ca..1270059ce 100644 --- a/src/lib/fcitx/addonloader.cpp +++ b/src/lib/fcitx/addonloader.cpp @@ -5,8 +5,18 @@ * */ +#include "fcitx/addonloader.h" +#include +#include +#include +#include +#include "fcitx-utils/flags.h" #include "fcitx-utils/library.h" #include "fcitx-utils/log.h" +#include "fcitx-utils/standardpath.h" +#include "fcitx-utils/stringutils.h" +#include "fcitx/addoninfo.h" +#include "fcitx/addoninstance.h" #include "addonloader_p.h" #include "config.h" @@ -41,9 +51,9 @@ AddonInstance *SharedLibraryLoader::load(const AddonInfo &info, continue; } try { - registry_.emplace( - info.uniqueName(), - std::make_unique(std::move(lib))); + registry_.emplace(info.uniqueName(), + std::make_unique( + info, std::move(lib))); } catch (const std::exception &e) { FCITX_ERROR() << "Failed to initialize addon factory for addon " << info.uniqueName() << ". Error: " << e.what(); diff --git a/src/lib/fcitx/addonloader.h b/src/lib/fcitx/addonloader.h index aa7fba88d..e7ebf6b8f 100644 --- a/src/lib/fcitx/addonloader.h +++ b/src/lib/fcitx/addonloader.h @@ -4,8 +4,8 @@ * SPDX-License-Identifier: LGPL-2.1-or-later * */ -#ifndef _FCITX_ADDONRESOLVER_H_ -#define _FCITX_ADDONRESOLVER_H_ +#ifndef _FCITX_ADDONLOADER_H_ +#define _FCITX_ADDONLOADER_H_ #include #include @@ -18,7 +18,7 @@ namespace fcitx { class AddonFactory; class AddonManager; -typedef std::unordered_map StaticAddonRegistry; +using StaticAddonRegistry = std::unordered_map; class FCITXCORE_EXPORT AddonLoader { public: @@ -29,4 +29,4 @@ class FCITXCORE_EXPORT AddonLoader { }; } // namespace fcitx -#endif // _FCITX_ADDONRESOLVER_H_ +#endif // _FCITX_ADDONLOADER_H_ diff --git a/src/lib/fcitx/addonloader_p.h b/src/lib/fcitx/addonloader_p.h index f07a6aa7b..e466f2455 100644 --- a/src/lib/fcitx/addonloader_p.h +++ b/src/lib/fcitx/addonloader_p.h @@ -7,9 +7,15 @@ #ifndef _FCITX_ADDONLOADER_P_H_ #define _FCITX_ADDONLOADER_P_H_ +#include #include +#include +#include +#include +#include #include "fcitx-utils/library.h" #include "fcitx-utils/standardpath.h" +#include "fcitx-utils/stringutils.h" #include "addonfactory.h" #include "addoninfo.h" #include "addoninstance.h" @@ -17,10 +23,20 @@ namespace fcitx { +namespace { +constexpr char FCITX_ADDON_FACTORY_ENTRY[] = "fcitx_addon_factory_instance"; +} + class SharedLibraryFactory { public: - SharedLibraryFactory(Library lib) : library_(std::move(lib)) { - auto *funcPtr = library_.resolve("fcitx_addon_factory_instance"); + SharedLibraryFactory(const AddonInfo &info, Library lib) + : library_(std::move(lib)) { + std::string v2Name = stringutils::concat(FCITX_ADDON_FACTORY_ENTRY, "_", + info.uniqueName()); + auto *funcPtr = library_.resolve(v2Name.data()); + if (!funcPtr) { + funcPtr = library_.resolve(FCITX_ADDON_FACTORY_ENTRY); + } if (!funcPtr) { throw std::runtime_error(library_.error()); } diff --git a/src/modules/clipboard/clipboard.conf.in.in b/src/modules/clipboard/clipboard.conf.in.in index 250865313..46463dc90 100644 --- a/src/modules/clipboard/clipboard.conf.in.in +++ b/src/modules/clipboard/clipboard.conf.in.in @@ -8,5 +8,6 @@ OnDemand=False Configurable=True [Addon/OptionalDependencies] -0=xcb:@PROJECT_VERSION@ -1=wayland:@PROJECT_VERSION@ +0=core:@PROJECT_VERSION@ +1=xcb:@PROJECT_VERSION@ +2=wayland:@PROJECT_VERSION@ diff --git a/src/modules/clipboard/clipboard.cpp b/src/modules/clipboard/clipboard.cpp index 9ba497998..27443de61 100644 --- a/src/modules/clipboard/clipboard.cpp +++ b/src/modules/clipboard/clipboard.cpp @@ -498,4 +498,4 @@ class ClipboardModuleFactory : public AddonFactory { }; } // namespace fcitx -FCITX_ADDON_FACTORY(fcitx::ClipboardModuleFactory); +FCITX_ADDON_FACTORY_V2(clipboard, fcitx::ClipboardModuleFactory); diff --git a/src/modules/dbus/dbus.conf.in.in b/src/modules/dbus/dbus.conf.in.in index 1b0c65fbe..5889e0d93 100644 --- a/src/modules/dbus/dbus.conf.in.in +++ b/src/modules/dbus/dbus.conf.in.in @@ -6,7 +6,8 @@ Category=Module Version=@PROJECT_VERSION@ [Addon/Dependencies] -0=keyboard +0=core:@PROJECT_VERSION@ +1=keyboard [Addon/OptionalDependencies] 0=xcb diff --git a/src/modules/dbus/dbusmodule.cpp b/src/modules/dbus/dbusmodule.cpp index 23e69bfdf..bb46e9936 100644 --- a/src/modules/dbus/dbusmodule.cpp +++ b/src/modules/dbus/dbusmodule.cpp @@ -854,4 +854,4 @@ class DBusModuleFactory : public AddonFactory { }; } // namespace fcitx -FCITX_ADDON_FACTORY(fcitx::DBusModuleFactory) +FCITX_ADDON_FACTORY_V2(dbus, fcitx::DBusModuleFactory) diff --git a/src/modules/emoji/emoji.conf.in.in b/src/modules/emoji/emoji.conf.in.in index ba9078a34..c5cddde35 100644 --- a/src/modules/emoji/emoji.conf.in.in +++ b/src/modules/emoji/emoji.conf.in.in @@ -5,3 +5,6 @@ Library=libemoji Category=Module Version=@PROJECT_VERSION@ OnDemand=True + +[Addon/Dependencies] +0=core:@PROJECT_VERSION@ diff --git a/src/modules/emoji/emoji.cpp b/src/modules/emoji/emoji.cpp index 4c6aa6b91..9dbf57afc 100644 --- a/src/modules/emoji/emoji.cpp +++ b/src/modules/emoji/emoji.cpp @@ -241,4 +241,4 @@ class EmojiModuleFactory : public AddonFactory { } // namespace fcitx -FCITX_ADDON_FACTORY(fcitx::EmojiModuleFactory); +FCITX_ADDON_FACTORY_V2(emoji, fcitx::EmojiModuleFactory); diff --git a/src/modules/imselector/imselector.conf.in.in b/src/modules/imselector/imselector.conf.in.in index a935dd85b..cfa9f6e14 100644 --- a/src/modules/imselector/imselector.conf.in.in +++ b/src/modules/imselector/imselector.conf.in.in @@ -7,3 +7,6 @@ Library=libimselector Type=SharedLibrary OnDemand=False Configurable=True + +[Addon/Dependencies] +0=core:@PROJECT_VERSION@ diff --git a/src/modules/imselector/imselector.cpp b/src/modules/imselector/imselector.cpp index 092a32d41..858d145af 100644 --- a/src/modules/imselector/imselector.cpp +++ b/src/modules/imselector/imselector.cpp @@ -271,4 +271,4 @@ class IMSelectorFactory : public AddonFactory { } // namespace fcitx -FCITX_ADDON_FACTORY(fcitx::IMSelectorFactory); +FCITX_ADDON_FACTORY_V2(imselector, fcitx::IMSelectorFactory); diff --git a/src/modules/notificationitem/notificationitem.conf.in.in b/src/modules/notificationitem/notificationitem.conf.in.in index 9e14810dd..19e45cf74 100644 --- a/src/modules/notificationitem/notificationitem.conf.in.in +++ b/src/modules/notificationitem/notificationitem.conf.in.in @@ -8,5 +8,5 @@ Version=@PROJECT_VERSION@ OnDemand=True [Addon/Dependencies] -0=dbus - +0=core:@PROJECT_VERSION@ +1=dbus diff --git a/src/modules/notificationitem/notificationitem.cpp b/src/modules/notificationitem/notificationitem.cpp index 1182d32c9..195007011 100644 --- a/src/modules/notificationitem/notificationitem.cpp +++ b/src/modules/notificationitem/notificationitem.cpp @@ -13,6 +13,7 @@ #include "fcitx-utils/endian_p.h" #include "fcitx-utils/i18n.h" #include "fcitx/addonfactory.h" +#include "fcitx/addoninstance.h" #include "fcitx/addonmanager.h" #include "fcitx/misc_p.h" #include "classicui_public.h" @@ -423,4 +424,4 @@ class NotificationItemFactory : public AddonFactory { } // namespace fcitx -FCITX_ADDON_FACTORY(fcitx::NotificationItemFactory) +FCITX_ADDON_FACTORY_V2(notificationitem, fcitx::NotificationItemFactory) diff --git a/src/modules/notifications/notifications.conf.in.in b/src/modules/notifications/notifications.conf.in.in index 3c962a3ba..87aea826b 100644 --- a/src/modules/notifications/notifications.conf.in.in +++ b/src/modules/notifications/notifications.conf.in.in @@ -9,4 +9,5 @@ OnDemand=True Configurable=True [Addon/Dependencies] -0=dbus +0=core:@PROJECT_VERSION@ +1=dbus diff --git a/src/modules/notifications/notifications.cpp b/src/modules/notifications/notifications.cpp index 7e0728468..b1d707cc2 100644 --- a/src/modules/notifications/notifications.cpp +++ b/src/modules/notifications/notifications.cpp @@ -222,4 +222,4 @@ class NotificationsModuleFactory : public AddonFactory { }; } // namespace fcitx -FCITX_ADDON_FACTORY(fcitx::NotificationsModuleFactory) +FCITX_ADDON_FACTORY_V2(notifications, fcitx::NotificationsModuleFactory) diff --git a/src/modules/quickphrase/quickphrase.cpp b/src/modules/quickphrase/quickphrase.cpp index d1d1979c4..e7f8a11ba 100644 --- a/src/modules/quickphrase/quickphrase.cpp +++ b/src/modules/quickphrase/quickphrase.cpp @@ -546,4 +546,4 @@ class QuickPhraseModuleFactory : public AddonFactory { }; } // namespace fcitx -FCITX_ADDON_FACTORY(fcitx::QuickPhraseModuleFactory) +FCITX_ADDON_FACTORY_V2(quickphrase, fcitx::QuickPhraseModuleFactory) diff --git a/src/modules/spell/spell.conf.in.in b/src/modules/spell/spell.conf.in.in index 0d8969ee2..96f9ff905 100644 --- a/src/modules/spell/spell.conf.in.in +++ b/src/modules/spell/spell.conf.in.in @@ -6,3 +6,6 @@ Category=Module Version=@PROJECT_VERSION@ OnDemand=True Configurable=True + +[Addon/Dependencies] +0=core:@PROJECT_VERSION@ diff --git a/src/modules/spell/spell.cpp b/src/modules/spell/spell.cpp index a42292340..6044c9359 100644 --- a/src/modules/spell/spell.cpp +++ b/src/modules/spell/spell.cpp @@ -111,4 +111,4 @@ Spell::hintForDisplay(const std::string &language, SpellProvider provider, } } // namespace fcitx -FCITX_ADDON_FACTORY(fcitx::SpellModuleFactory) +FCITX_ADDON_FACTORY_V2(spell, fcitx::SpellModuleFactory) diff --git a/src/modules/unicode/unicode.conf.in.in b/src/modules/unicode/unicode.conf.in.in index 28cbe3f77..fddc5b4c5 100644 --- a/src/modules/unicode/unicode.conf.in.in +++ b/src/modules/unicode/unicode.conf.in.in @@ -8,5 +8,8 @@ Version=@PROJECT_VERSION@ OnDemand=False Configurable=True +[Addon/Dependencies] +0=core:@PROJECT_VERSION@ + [Addon/OptionalDependencies] 0=clipboard diff --git a/src/modules/unicode/unicode.cpp b/src/modules/unicode/unicode.cpp index 9f6c1eb6b..d5b00f8be 100644 --- a/src/modules/unicode/unicode.cpp +++ b/src/modules/unicode/unicode.cpp @@ -471,4 +471,4 @@ class UnicodeModuleFactory : public AddonFactory { }; } // namespace fcitx -FCITX_ADDON_FACTORY(fcitx::UnicodeModuleFactory); +FCITX_ADDON_FACTORY_V2(unicode, fcitx::UnicodeModuleFactory); diff --git a/src/modules/wayland/wayland.conf.in.in b/src/modules/wayland/wayland.conf.in.in index 88fa87e38..b771071b5 100644 --- a/src/modules/wayland/wayland.conf.in.in +++ b/src/modules/wayland/wayland.conf.in.in @@ -5,3 +5,6 @@ Library=libwayland Category=Module Version=@PROJECT_VERSION@ Configurable=True + +[Addon/Dependencies] +0=core:@PROJECT_VERSION@ diff --git a/src/modules/wayland/waylandmodule.cpp b/src/modules/wayland/waylandmodule.cpp index d619e46fc..8595defb1 100644 --- a/src/modules/wayland/waylandmodule.cpp +++ b/src/modules/wayland/waylandmodule.cpp @@ -702,4 +702,4 @@ class WaylandModuleFactory : public AddonFactory { }; } // namespace fcitx -FCITX_ADDON_FACTORY(fcitx::WaylandModuleFactory); +FCITX_ADDON_FACTORY_V2(wayland, fcitx::WaylandModuleFactory); diff --git a/src/modules/xcb/xcb.conf.in.in b/src/modules/xcb/xcb.conf.in.in index feda5536a..a1014ea7a 100644 --- a/src/modules/xcb/xcb.conf.in.in +++ b/src/modules/xcb/xcb.conf.in.in @@ -5,3 +5,6 @@ Library=libxcb Category=Module Version=@PROJECT_VERSION@ Configurable=True + +[Addon/Dependencies] +0=core:@PROJECT_VERSION@ diff --git a/src/modules/xcb/xcbmodule.cpp b/src/modules/xcb/xcbmodule.cpp index b30c7a75a..5c9c8a05a 100644 --- a/src/modules/xcb/xcbmodule.cpp +++ b/src/modules/xcb/xcbmodule.cpp @@ -208,4 +208,4 @@ class XCBModuleFactory : public AddonFactory { }; } // namespace fcitx -FCITX_ADDON_FACTORY(fcitx::XCBModuleFactory); +FCITX_ADDON_FACTORY_V2(xcb, fcitx::XCBModuleFactory); diff --git a/src/server/main.cpp b/src/server/main.cpp index 3e95c8c25..70fa78805 100644 --- a/src/server/main.cpp +++ b/src/server/main.cpp @@ -21,28 +21,20 @@ #include "fcitx-utils/standardpath.h" #include "fcitx-utils/stringutils.h" #include "fcitx/addonfactory.h" +#include "fcitx/addoninstance.h" #include "fcitx/addonloader.h" #include "fcitx/addonmanager.h" #include "fcitx/instance.h" #include "errorhandler.h" -#ifdef ENABLE_KEYBOARD -#include "keyboard.h" -#endif - using namespace fcitx; int selfpipe[2]; std::string crashlog; +StaticAddonRegistry staticAddon; #ifdef ENABLE_KEYBOARD -static KeyboardEngineFactory keyboardFactory; -#endif - -StaticAddonRegistry staticAddon = { -#ifdef ENABLE_KEYBOARD - std::make_pair("keyboard", &keyboardFactory) +FCITX_IMPORT_ADDON_FACTORY(staticAddon, keyboard); #endif -}; int main(int argc, char *argv[]) { umask(077); diff --git a/src/ui/classic/classicui.cpp b/src/ui/classic/classicui.cpp index 9655ac5cb..1a90d0ebd 100644 --- a/src/ui/classic/classicui.cpp +++ b/src/ui/classic/classicui.cpp @@ -508,4 +508,4 @@ bool ClassicUI::showLayoutNameInIcon() const { } // namespace fcitx::classicui -FCITX_ADDON_FACTORY(fcitx::classicui::ClassicUIFactory); +FCITX_ADDON_FACTORY_V2(classicui, fcitx::classicui::ClassicUIFactory); diff --git a/src/ui/kimpanel/kimpanel.cpp b/src/ui/kimpanel/kimpanel.cpp index 76b20afb1..bac72b003 100644 --- a/src/ui/kimpanel/kimpanel.cpp +++ b/src/ui/kimpanel/kimpanel.cpp @@ -591,4 +591,4 @@ class KimpanelFactory : public AddonFactory { }; } // namespace fcitx -FCITX_ADDON_FACTORY(fcitx::KimpanelFactory); +FCITX_ADDON_FACTORY_V2(kimpanel, fcitx::KimpanelFactory); diff --git a/src/ui/virtualkeyboard/virtualkeyboard.cpp b/src/ui/virtualkeyboard/virtualkeyboard.cpp index 787ba4389..01f72b2f1 100644 --- a/src/ui/virtualkeyboard/virtualkeyboard.cpp +++ b/src/ui/virtualkeyboard/virtualkeyboard.cpp @@ -12,6 +12,8 @@ #include "fcitx-utils/key.h" #include "fcitx-utils/log.h" #include "fcitx-utils/utf8.h" +#include "fcitx/addonfactory.h" +#include "fcitx/addoninstance.h" #include "fcitx/addonmanager.h" #include "fcitx/candidatelist.h" #include "fcitx/inputcontext.h" @@ -535,4 +537,4 @@ class VirtualKeyboardFactory : public AddonFactory { }; } // namespace fcitx -FCITX_ADDON_FACTORY(fcitx::VirtualKeyboardFactory); +FCITX_ADDON_FACTORY_V2(virtualkeyboard, fcitx::VirtualKeyboardFactory); diff --git a/test/addon/dummyaddon.cpp b/test/addon/dummyaddon.cpp index a6f752118..41d807fc7 100644 --- a/test/addon/dummyaddon.cpp +++ b/test/addon/dummyaddon.cpp @@ -29,4 +29,4 @@ class DummyAddonFactory : public fcitx::AddonFactory { } }; -FCITX_ADDON_FACTORY(DummyAddonFactory) +FCITX_ADDON_FACTORY_V2_BACKWARDS(dummyaddon, DummyAddonFactory) diff --git a/test/addon/fcitx5/addon/testfrontend.conf b/test/addon/fcitx5/addon/testfrontend.conf index 927f0aadd..55ac86e33 100644 --- a/test/addon/fcitx5/addon/testfrontend.conf +++ b/test/addon/fcitx5/addon/testfrontend.conf @@ -3,3 +3,6 @@ Name=testfrontend Type=SharedLibrary Library=libtestfrontend Category=Frontend + +[Addon/Dependencies] +0=core:@PROJECT_VERSION@ diff --git a/test/addon/fcitx5/addon/testim.conf b/test/addon/fcitx5/addon/testim.conf index f4cf40a1a..737e4fdf7 100644 --- a/test/addon/fcitx5/addon/testim.conf +++ b/test/addon/fcitx5/addon/testim.conf @@ -2,3 +2,6 @@ Name=testim Type=StaticLibrary Category=InputMethod + +[Addon/Dependencies] +0=core:@PROJECT_VERSION@ diff --git a/test/testcompose.cpp b/test/testcompose.cpp index 2e47c1165..cb9f3f639 100644 --- a/test/testcompose.cpp +++ b/test/testcompose.cpp @@ -4,19 +4,27 @@ * SPDX-License-Identifier: LGPL-2.1-or-later * */ +#include +#include +#include #include "fcitx-utils/eventdispatcher.h" +#include "fcitx-utils/key.h" +#include "fcitx-utils/keysym.h" +#include "fcitx-utils/log.h" +#include "fcitx-utils/macros.h" #include "fcitx-utils/testing.h" +#include "fcitx/addoninstance.h" +#include "fcitx/addonloader.h" +#include "fcitx/instance.h" #include "fcitx/instance_p.h" -#include "keyboard.h" #include "testdir.h" #include "testfrontend_public.h" using namespace fcitx; -static KeyboardEngineFactory keyboardFactory; +StaticAddonRegistry staticAddon; +FCITX_IMPORT_ADDON_FACTORY(staticAddon, keyboard); -StaticAddonRegistry staticAddon = { - std::make_pair("keyboard", &keyboardFactory)}; void scheduleEvent(EventDispatcher *dispatcher, Instance *instance) { dispatcher->schedule([instance]() { auto *keyboard = instance->addonManager().addon("keyboard", true); diff --git a/test/testspell.cpp b/test/testspell.cpp index 2cc8f18a3..b6a74df21 100644 --- a/test/testspell.cpp +++ b/test/testspell.cpp @@ -5,16 +5,25 @@ * */ #include "fcitx-utils/eventdispatcher.h" +#include "fcitx-utils/key.h" +#include "fcitx-utils/keysym.h" +#include "fcitx-utils/log.h" +#include "fcitx-utils/macros.h" #include "fcitx-utils/testing.h" +#include "fcitx/addoninstance.h" +#include "fcitx/addonloader.h" #include "fcitx/addonmanager.h" +#include "fcitx/inputmethodgroup.h" #include "fcitx/inputmethodmanager.h" #include "fcitx/instance.h" -#include "keyboard.h" #include "testdir.h" #include "testfrontend_public.h" using namespace fcitx; +StaticAddonRegistry staticAddon; +FCITX_IMPORT_ADDON_FACTORY(staticAddon, keyboard); + void scheduleEvent(EventDispatcher *dispatcher, Instance *instance) { dispatcher->schedule([instance]() { auto *spell = instance->addonManager().addon("spell", true); @@ -64,12 +73,6 @@ int main() { "testing/testim"}, {"test", "src/modules", FCITX5_SOURCE_DIR "/src/modules"}); - static KeyboardEngineFactory keyboardFactory; - - StaticAddonRegistry staticAddon = { - std::make_pair("keyboard", - &keyboardFactory)}; - char arg0[] = "testspell"; char arg1[] = "--disable=all"; char arg2[] = "--enable=keyboard,testfrontend,spell,testui"; diff --git a/testing/testfrontend/testfrontend.conf b/testing/testfrontend/testfrontend.conf index c3120973b..55ac86e33 100644 --- a/testing/testfrontend/testfrontend.conf +++ b/testing/testfrontend/testfrontend.conf @@ -4,3 +4,5 @@ Type=SharedLibrary Library=libtestfrontend Category=Frontend +[Addon/Dependencies] +0=core:@PROJECT_VERSION@ diff --git a/testing/testfrontend/testfrontend.cpp b/testing/testfrontend/testfrontend.cpp index ae1ab7509..afb300563 100644 --- a/testing/testfrontend/testfrontend.cpp +++ b/testing/testfrontend/testfrontend.cpp @@ -106,4 +106,4 @@ class TestFrontendFactory : public AddonFactory { } // namespace fcitx -FCITX_ADDON_FACTORY(fcitx::TestFrontendFactory); +FCITX_ADDON_FACTORY_V2(testfrontend, fcitx::TestFrontendFactory); diff --git a/testing/testim/testim.conf b/testing/testim/testim.conf index 0a7046dd6..3aff9cccd 100644 --- a/testing/testim/testim.conf +++ b/testing/testim/testim.conf @@ -4,4 +4,5 @@ Type=SharedLibrary Library=libtestim Category=InputMethod - +[Addon/Dependencies] +0=core:@PROJECT_VERSION@ diff --git a/testing/testim/testim.cpp b/testing/testim/testim.cpp index 5a65634ea..8895867d9 100644 --- a/testing/testim/testim.cpp +++ b/testing/testim/testim.cpp @@ -32,4 +32,4 @@ class TestIMFactory : public AddonFactory { } // namespace fcitx -FCITX_ADDON_FACTORY(fcitx::TestIMFactory); +FCITX_ADDON_FACTORY_V2(testim, fcitx::TestIMFactory); diff --git a/testing/testui/testui.conf b/testing/testui/testui.conf index e6d684c9f..67ec59379 100644 --- a/testing/testui/testui.conf +++ b/testing/testui/testui.conf @@ -3,3 +3,6 @@ Name=Simple UI for testing Type=SharedLibrary Library=libtestui Category=UI + +[Addon/Dependencies] +0=core:@PROJECT_VERSION@ diff --git a/testing/testui/testui.cpp b/testing/testui/testui.cpp index 1c2e1c013..7d22baec4 100644 --- a/testing/testui/testui.cpp +++ b/testing/testui/testui.cpp @@ -10,6 +10,7 @@ #include "fcitx-utils/utf8.h" #include "fcitx/action.h" #include "fcitx/addonfactory.h" +#include "fcitx/addoninstance.h" #include "fcitx/addonmanager.h" #include "fcitx/candidatelist.h" #include "fcitx/inputcontext.h" @@ -89,4 +90,4 @@ class TestUIFactory : public AddonFactory { }; } // namespace fcitx -FCITX_ADDON_FACTORY(fcitx::TestUIFactory); +FCITX_ADDON_FACTORY_V2(testui, fcitx::TestUIFactory);