Inter Module function call


In order to reusing some common code, Fcitx provides a mechanism to do inter module function call. Although it's call inter module function, but all kinds of addon can provide such functions.

If a module wants to register some inter module function, first it need a header defines correct macro. Here is part of macro defined in fcitx/module/x11stuff.h

#define FCITX_X11_NAME "fcitx-x11"
#define FCITX_X11_GETDISPLAY 0
#define FCITX_X11_GETDISPLAY_RETURNTYPE Display*
#define FCITX_X11_ADDXEVENTHANDLER 1
#define FCITX_X11_ADDXEVENTHANDLER_RETURNTYPE void
#define FCITX_X11_REMOVEXEVENTHANDLER 2
#define FCITX_X11_REMOVEXEVENTHANDLER_RETURNTYPE void
#define FCITX_X11_FINDARGBVISUAL 3
#define FCITX_X11_FINDARGBVISUAL_RETURNTYPE Visual*
#define FCITX_X11_INITWINDOWATTR 4
#define FCITX_X11_INITWINDOWATTR_RETURNTYPE void
#define FCITX_X11_SETWINDOWPROP 5
#define FCITX_X11_SETWINDOWPROP_RETURNTYPE void
#define FCITX_X11_GETSCREENSIZE 6
#define FCITX_X11_GETSCREENSIZE_RETURNTYPE void
#define FCITX_X11_MOUSECLICK 7
#define FCITX_X11_MOUSECLICK_RETURNTYPE void
#define FCITX_X11_ADDCOMPOSITEHANDLER 8
#define FCITX_X11_ADDCOMPOSITEHANDLER_RETURNTYPE void
        

fcitx_add_addon_header is provided by FcitxMacro.cmake to get this header installed to the correct place.

All functions have the same interface, like this:

void* X11GetDisplay(void* arg, FcitxModuleFunctionArg args);
        

For any addon need to call a inter module function it should add that module as dependency in the configuration file. Addon is loaded or not can be also checked at runtime via GetAddonByName.

If addon want to call a function in other module, it should use InvokeFunction macro defined in fcitx/module.h.

InvokeFunction(instance, FCITX_X11, GETDISPLAY, arg);
        

FcitxModuleFunctionArg provides ten void* slot for passing argument, which is enough for passing arguments.