Fcitx
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
fcitx::Instance Class Reference

An instance represents a standalone Fcitx instance. More...

#include <fcitx/instance.h>

Inheritance diagram for fcitx::Instance:
Inheritance graph
[legend]
Collaboration diagram for fcitx::Instance:
Collaboration graph
[legend]

Public Member Functions

 Instance (int argc, char *argv[])
 A main function like construct to be used to create Fcitx Instance. More...
 
bool initialized () const
 
void setSignalPipe (int fd)
 Set the pipe forwarding unix signal information. More...
 
int exec ()
 Start the event loop of Fcitx. More...
 
bool willTryReplace () const
 Check whether command line specify if it will replace an existing fcitx server. More...
 
bool exitWhenMainDisplayDisconnected () const
 Check whether command line specify whether to keep fcitx running. More...
 
bool exiting () const
 Check whether fcitx is in exiting process. More...
 
EventLoopeventLoop ()
 Get the fcitx event loop.
 
EventDispatchereventDispatcher ()
 Return a shared event dispatcher that is already attached to instance's event loop. More...
 
AddonManageraddonManager ()
 Get the addon manager.
 
InputContextManagerinputContextManager ()
 Get the input context manager.
 
UserInterfaceManageruserInterfaceManager ()
 Get the user interface manager.
 
InputMethodManagerinputMethodManager ()
 Get the input method manager.
 
const InputMethodManagerinputMethodManager () const
 Get the input method manager.
 
GlobalConfigglobalConfig ()
 Get the global config.
 
bool postEvent (Event &event)
 
bool postEvent (Event &&event)
 
bool postEvent (Event &event) const
 Put a event to the event pipe line. More...
 
bool postEvent (Event &&event) const
 
FCITX_NODISCARD std::unique_ptr< HandlerTableEntry< EventHandler > > watchEvent (EventType type, EventWatcherPhase phase, EventHandler callback)
 Add a callback to for certain event type. More...
 
std::string inputMethod (InputContext *ic)
 Return the unique name of input method for given input context.
 
const InputMethodEntryinputMethodEntry (InputContext *ic)
 Return the input method entry for given input context.
 
InputMethodEngineinputMethodEngine (InputContext *ic)
 Return the input method engine object for given input context.
 
InputMethodEngineinputMethodEngine (const std::string &name)
 Return the input method engine object for given unique input method name. More...
 
std::string inputMethodIcon (InputContext *ic)
 Return the input method icon for input context. More...
 
std::string inputMethodLabel (InputContext *ic)
 Return the input method label for input context. More...
 
FCITXCORE_DEPRECATED uint32_t processCompose (InputContext *ic, KeySym keysym)
 Handle current XCompose state. More...
 
std::optional< std::string > processComposeString (InputContext *ic, KeySym keysym)
 Handle current XCompose state. More...
 
void resetCompose (InputContext *inputContext)
 Reset the compose state.
 
bool isComposing (InputContext *inputContext)
 Check whether input context is composing or not.
 
std::string commitFilter (InputContext *inputContext, const std::string &orig)
 Update the commit string to frontend. More...
 
Text outputFilter (InputContext *inputContext, const Text &orig)
 Update the string that will be displayed in user interface. More...
 
 FCITX_DECLARE_SIGNAL (Instance, CommitFilter, void(InputContext *inputContext, std::string &orig))
 
 FCITX_DECLARE_SIGNAL (Instance, OutputFilter, void(InputContext *inputContext, Text &orig))
 
 FCITX_DECLARE_SIGNAL (Instance, KeyEventResult, void(const KeyEvent &keyEvent))
 
 FCITX_DECLARE_SIGNAL (Instance, CheckUpdate, bool())
 
InputContextlastFocusedInputContext ()
 Return a focused input context.
 
InputContextmostRecentInputContext ()
 Return the most recent focused input context. More...
 
void flushUI ()
 All user interface update is batched internally. More...
 
void exit ()
 Exit the fcitx event loop.
 
void exit (int exitCode)
 Exit the fcitx event loop with an exit code.
 
void restart ()
 Restart fcitx instance, this should only be used within a regular Fcitx server, not within embedded mode. More...
 
void configure ()
 Launch configtool.
 
FCITXCORE_DEPRECATED void configureAddon (const std::string &addon)
 
FCITXCORE_DEPRECATED void configureInputMethod (const std::string &imName)
 
std::string currentUI ()
 Return the name of current user interface addon.
 
std::string addonForInputMethod (const std::string &imName)
 Return the addon name of given input method.
 
void activate ()
 Activate last focused input context. (Switch to the active input method)
 
void deactivate ()
 Deactivate last focused input context. More...
 
void toggle ()
 Toggle between the first input method and active input method.
 
void resetInputMethodList ()
 Reset the input method configuration and recreate based on system language. More...
 
int state ()
 Return a fcitx5-remote compatible value for the state.
 
void reloadConfig ()
 Reload global config.
 
void reloadAddonConfig (const std::string &addonName)
 Reload certain addon config.
 
void refresh ()
 Load newly installed input methods and addons.
 
std::string currentInputMethod ()
 Return the current input method of last focused input context.
 
void setCurrentInputMethod (const std::string &imName)
 Set the input method of last focused input context.
 
void setCurrentInputMethod (InputContext *ic, const std::string &imName, bool local)
 Set the input method of given input context. More...
 
FCITXCORE_DEPRECATED bool enumerateGroup (bool forward)
 
void enumerate (bool forward)
 Enumerate input method with in current group.
 
FocusGroupdefaultFocusGroup (const std::string &displayHint={})
 Get the default focus group with given display hint. More...
 
void setXkbParameters (const std::string &display, const std::string &rule, const std::string &model, const std::string &options)
 Set xkb RLVMO tuple for given display. More...
 
void updateXkbStateMask (const std::string &display, uint32_t depressed_mods, uint32_t latched_mods, uint32_t locked_mods)
 Update xkb state mask for given display.
 
void clearXkbStateMask (const std::string &display)
 Clear xkb state mask for given display.
 
void showInputMethodInformation (InputContext *ic)
 Show a small popup with input popup window with current input method information. More...
 
void showCustomInputMethodInformation (InputContext *ic, const std::string &message)
 Show a small popup with input popup window with current input method information. More...
 
bool checkUpdate () const
 Check if need to invoke Instance::refresh. More...
 
void save ()
 Save everything including input method profile and addon data. More...
 
void initialize ()
 Initialize fcitx. More...
 
void setRunning (bool running)
 Let other know that event loop is already running. More...
 
bool isRunning () const
 Whether event loop is started and still running. More...
 
InputMethodMode inputMethodMode () const
 The current global input method mode. More...
 
void setInputMethodMode (InputMethodMode mode)
 Set the current global input method mode. More...
 
bool isRestartRequested () const
 Whether restart is requested. More...
 
bool virtualKeyboardAutoShow () const
 
void setVirtualKeyboardAutoShow (bool autoShow)
 
bool virtualKeyboardAutoHide () const
 
void setVirtualKeyboardAutoHide (bool autoHide)
 
VirtualKeyboardFunctionMode virtualKeyboardFunctionMode () const
 
void setVirtualKeyboardFunctionMode (VirtualKeyboardFunctionMode mode)
 
void setBinaryMode ()
 Set if this instance is running as fcitx5 binary. More...
 
bool canRestart () const
 Check if fcitx 5 can safely restart by itself. More...
 
- Public Member Functions inherited from fcitx::ConnectableObject
template<typename SignalType , typename F >
Connection connect (F &&func)
 
template<typename SignalType >
void disconnectAll ()
 

Static Public Member Functions

static const char * version ()
 Return the version string of Fcitx.
 

Protected Member Functions

InstancePrivate * privateData ()
 
- Protected Member Functions inherited from fcitx::ConnectableObject
void destroy ()
 Allow user to notify the destroy event earlier. More...
 
template<typename SignalType , typename... Args>
auto emit (Args &&...args)
 
template<typename SignalType , typename... Args>
auto emit (Args &&...args) const
 
template<typename SignalType , typename Combiner = LastValue<typename std::function< typename SignalType::signalType>::result_type>>
void registerSignal ()
 
template<typename SignalType >
void unregisterSignal ()
 

Detailed Description

An instance represents a standalone Fcitx instance.

Usually there is only one of such object.

Fcitx Instance provides the access to all the addons and sub components. It also provides a event pipeline for handling input method related event.

Definition at line 88 of file instance.h.

Constructor & Destructor Documentation

◆ Instance()

fcitx::Instance::Instance ( int  argc,
char *  argv[] 
)

A main function like construct to be used to create Fcitx Instance.

For more details, see –help of fcitx5 command.

Parameters
argcnumber of argument
argvcommand line arguments

Definition at line 660 of file instance.cpp.

Member Function Documentation

◆ canRestart()

bool fcitx::Instance::canRestart ( ) const

Check if fcitx 5 can safely restart by itself.

When the existing fcitx 5 instance returns false, fcitx5 -r, or Instance::restart will just be no-op.

Returns
whether it is safe for fcitx to restart on its own.
See also
AddonInstance::setCanRestart
Since
5.1.6

Definition at line 1564 of file instance.cpp.

◆ checkUpdate()

bool fcitx::Instance::checkUpdate ( ) const

Check if need to invoke Instance::refresh.

Returns
need update
See also
Instance::refresh

Definition at line 2540 of file instance.cpp.

◆ commitFilter()

std::string fcitx::Instance::commitFilter ( InputContext inputContext,
const std::string &  orig 
)

Update the commit string to frontend.

This function should be not be used directly since it is already used internally by InputContext::commitString.

Parameters
inputContextinput context
origoriginal string
Returns
the updated string.
See also
InputContext::commitString

Definition at line 2340 of file instance.cpp.

◆ deactivate()

void fcitx::Instance::deactivate ( )

Deactivate last focused input context.

(Switch to the first input method)

Definition at line 1987 of file instance.cpp.

◆ defaultFocusGroup()

FocusGroup * fcitx::Instance::defaultFocusGroup ( const std::string &  displayHint = {})

Get the default focus group with given display hint.

This function is used by frontend to assign a focus group from an unknown display server.

Parameters
displayHintDisplay server hint, it can something like be x11: / wayland:
Returns
focus group

Definition at line 2412 of file instance.cpp.

◆ eventDispatcher()

EventDispatcher & fcitx::Instance::eventDispatcher ( )

Return a shared event dispatcher that is already attached to instance's event loop.

Returns
shared event dispatcher.
Since
5.1.9

Definition at line 1588 of file instance.cpp.

◆ exec()

int fcitx::Instance::exec ( )

Start the event loop of Fcitx.

Returns
return value that can be used as main function return code.

Definition at line 1481 of file instance.cpp.

◆ exiting()

bool fcitx::Instance::exiting ( ) const

Check whether fcitx is in exiting process.

Returns

Definition at line 1392 of file instance.cpp.

◆ exitWhenMainDisplayDisconnected()

bool fcitx::Instance::exitWhenMainDisplayDisconnected ( ) const

Check whether command line specify whether to keep fcitx running.

There could be multiple display server, such as X/Wayland/etc. Fcitx usually will exit when the connection is closed. Command line -k can override this behavior and keep Fcitx running.

Returns
whether to exit after main display is disconnected.

Definition at line 1387 of file instance.cpp.

◆ FCITX_DECLARE_SIGNAL()

fcitx::Instance::FCITX_DECLARE_SIGNAL ( Instance  ,
CheckUpdate  ,
bool()   
)

◆ flushUI()

void fcitx::Instance::flushUI ( )

All user interface update is batched internally.

This function will flush all the batched UI update immediately.

Definition at line 2381 of file instance.cpp.

◆ initialize()

void fcitx::Instance::initialize ( )

Initialize fcitx.

This is only intended to be used if you want to handle event loop on your own. Otherwise you should use Instance::exec().

Since
5.0.14

Definition at line 1415 of file instance.cpp.

◆ inputMethodEngine()

InputMethodEngine * fcitx::Instance::inputMethodEngine ( const std::string &  name)

Return the input method engine object for given unique input method name.

Definition at line 1766 of file instance.cpp.

◆ inputMethodIcon()

std::string fcitx::Instance::inputMethodIcon ( InputContext ic)

Return the input method icon for input context.

It will fallback to input-keyboard by default if no input method is available.

Parameters
icinput context
Returns
icon name.
See also
InputMethodEngine::subModeIcon

Definition at line 1776 of file instance.cpp.

◆ inputMethodLabel()

std::string fcitx::Instance::inputMethodLabel ( InputContext ic)

Return the input method label for input context.

Parameters
icinput context
Returns
label.
See also
InputMethodEngine::subModeLabel
Since
5.0.11

Definition at line 1793 of file instance.cpp.

◆ inputMethodMode()

InputMethodMode fcitx::Instance::inputMethodMode ( ) const

The current global input method mode.

It may affect the user interface and behavior of certain key binding.

Since
5.1.0

Definition at line 1509 of file instance.cpp.

◆ isRestartRequested()

bool fcitx::Instance::isRestartRequested ( ) const

Whether restart is requested.

Since
5.0.18

Definition at line 1523 of file instance.cpp.

◆ isRunning()

bool fcitx::Instance::isRunning ( ) const

Whether event loop is started and still running.

Since
5.0.14

Definition at line 1504 of file instance.cpp.

◆ mostRecentInputContext()

InputContext * fcitx::Instance::mostRecentInputContext ( )

Return the most recent focused input context.

If there isn't such ic, return the last unfocused input context.

Definition at line 2376 of file instance.cpp.

◆ outputFilter()

Text fcitx::Instance::outputFilter ( InputContext inputContext,
const Text orig 
)

Update the string that will be displayed in user interface.

This function should only be used by frontend for client preedit, or user interface, for the other field in input panel.

See also
InputPanel
Parameters
inputContextinput context
origorig text
Returns
fcitx::Text

Definition at line 2347 of file instance.cpp.

◆ postEvent()

bool fcitx::Instance::postEvent ( Event event) const

Put a event to the event pipe line.

Parameters
eventInput method event
Returns
return the value of event.accepted()

Definition at line 1627 of file instance.cpp.

◆ processCompose()

uint32_t fcitx::Instance::processCompose ( InputContext ic,
KeySym  keysym 
)

Handle current XCompose state.

Parameters
icinput context.
keysymkey symbol.
Returns
unicode
See also
processComposeString

Definition at line 1808 of file instance.cpp.

◆ processComposeString()

std::optional< std::string > fcitx::Instance::processComposeString ( InputContext ic,
KeySym  keysym 
)

Handle current XCompose state.

Parameters
icinput context.
keysymkey symbol.
Returns
the composed string, if it returns nullopt, it means compose is invalid.
See also
processComposeString
Since
5.0.4

Definition at line 1856 of file instance.cpp.

◆ resetInputMethodList()

void fcitx::Instance::resetInputMethodList ( )

Reset the input method configuration and recreate based on system language.

Definition at line 2060 of file instance.cpp.

◆ restart()

void fcitx::Instance::restart ( )

Restart fcitx instance, this should only be used within a regular Fcitx server, not within embedded mode.

Definition at line 2065 of file instance.cpp.

◆ save()

void fcitx::Instance::save ( )

Save everything including input method profile and addon data.

It also reset the idle save timer.

Since
5.0.14

Definition at line 1940 of file instance.cpp.

◆ setBinaryMode()

void fcitx::Instance::setBinaryMode ( )

Set if this instance is running as fcitx5 binary.

This will affect return value of Instance::canRestart.

See also
Instance::canRestart
Since
5.1.6

Definition at line 1559 of file instance.cpp.

◆ setCurrentInputMethod()

void fcitx::Instance::setCurrentInputMethod ( InputContext ic,
const std::string &  imName,
bool  local 
)

Set the input method of given input context.

The input method need to be within the current group. Local parameter can be used to set the input method only for this input context.

Parameters
icinput context
imNameunique name of a input method
local

Definition at line 2078 of file instance.cpp.

◆ setInputMethodMode()

void fcitx::Instance::setInputMethodMode ( InputMethodMode  mode)

Set the current global input method mode.

See also
InputMethodMode
InputMethodModeChanged
Since
5.1.0

Definition at line 1514 of file instance.cpp.

◆ setRunning()

void fcitx::Instance::setRunning ( bool  running)

Let other know that event loop is already running.

This should only be used if you run event loop on your own.

Since
5.0.14

Definition at line 1499 of file instance.cpp.

◆ setSignalPipe()

void fcitx::Instance::setSignalPipe ( int  fd)

Set the pipe forwarding unix signal information.

Fcitx Instance is running within its own thread, usually main thread. In order to make it handle signal correctly in a thread-safe way, it is possible to set a file descriptor that write the signal number received by the signal handler. Usually this is done through a self-pipe. This is already handled by Fcitx default server implementation, normal addon user should not touch this. The common usecase is when you want to embed Fcitx into your own program.

Parameters
fdfile descriptor

Definition at line 1368 of file instance.cpp.

◆ setXkbParameters()

void fcitx::Instance::setXkbParameters ( const std::string &  display,
const std::string &  rule,
const std::string &  model,
const std::string &  options 
)

Set xkb RLVMO tuple for given display.

Parameters
displaydisplay name
rulexkb rule name
modelxkb model name
optionsxkb option

Definition at line 2548 of file instance.cpp.

◆ showCustomInputMethodInformation()

void fcitx::Instance::showCustomInputMethodInformation ( InputContext ic,
const std::string &  message 
)

Show a small popup with input popup window with current input method information.

The popup will be hidden after certain amount of time. The popup will always be displayed, regardless of the showInputMethodInformation in global config.

This is useful for input method that has internal switches.

Parameters
icinput context.
messagemessage string to be displayed
Since
5.1.11

Definition at line 2532 of file instance.cpp.

◆ showInputMethodInformation()

void fcitx::Instance::showInputMethodInformation ( InputContext ic)

Show a small popup with input popup window with current input method information.

The popup will be hidden after certain amount of time.

This is useful for input method that has multiple sub modes. It can be called with switching sub modes within the input method.

The behavior is controlled by global config.

Parameters
icinput context.

Definition at line 2523 of file instance.cpp.

◆ watchEvent()

std::unique_ptr< HandlerTableEntry< EventHandler > > fcitx::Instance::watchEvent ( EventType  type,
EventWatcherPhase  phase,
EventHandler  callback 
)

Add a callback to for certain event type.

Parameters
typeevent type
phasethe stage that callback will be executed.
callbackcallback function.
Returns
Handle to the callback, the callback will be removed when it is deleted.

Definition at line 1692 of file instance.cpp.

◆ willTryReplace()

bool fcitx::Instance::willTryReplace ( ) const

Check whether command line specify if it will replace an existing fcitx server.

This function is only useful if your addon provides a way to replace existing fcitx server. Basically it is checking whether -r is passed to fcitx command line.

Returns
whether to replace existing fcitx server. Default value is false.

Definition at line 1382 of file instance.cpp.


The documentation for this class was generated from the following files: