Frontend is a library that communicates with the client, and processes the key input from client, and sends string to client.
Currently, there are 13 functions need to be implemented for a Frontend. (Defined in fcitx/frontend.h)
void* (*Create)(struct _FcitxInstance*, int frontendindex);
boolean (*Destroy)(void *arg);
void (*CreateIC)(void* arg, FcitxInputContext*, void* priv);
boolean (*CheckIC)(void* arg, FcitxInputContext* arg1, void* arg2);
void (*DestroyIC) (void* arg, FcitxInputContext *context);
void (*EnableIM)(void* arg, FcitxInputContext* arg1);
void (*CloseIM)(void* arg, FcitxInputContext* arg1);
void (*CommitString)(void* arg, FcitxInputContext* arg1, char* arg2);
void (*ForwardKey)(void* arg, FcitxInputContext* arg1, FcitxKeyEventType event, FcitxKeySym sym, unsigned int state);
void (*SetWindowOffset)(void* arg, FcitxInputContext* ic, int x, int y);
void (*GetWindowPosition)(void* arg, FcitxInputContext* ic, int* x, int* y);
void (*UpdatePreedit)(void* arg, FcitxInputContext* ic);
void (*UpdateClientSideUI)(void* arg, FcitxInputContext* ic);
Frontend needs to manage its input contexts. A client at least has one input context with some private data, which can identify the specific input context. The CreateIC and DestroyIC are functions that create and destroy private input context data. A input context usually has a private unique id, which will be used in CheckIC to find the specific input context.
Some input contexts hold a state at the client side, which indicates whether this input context is active or not. EnableIM and CloseIM will be called when fcitx want to enable or disable input context from Fcitx side.
CommitString and ForwardKey will be called when fcitx wants to commit string to client window, or forward a key event to client window.
SetWindowOffset and GetWindowOffset is to set and get the client cursor position.
UpdatePreedit and UpdateClientSideUI will be called when UI elements, like preedit string, or any ui element update. These two function are especially for input context with capacity CAPACITY_PREEDIT or CAPACITY_CLIENT_SIDE_UI. Only when a input context claims to support opposite capacity, these two function will be used.