7 #ifndef _FCITX_EVENT_H_ 8 #define _FCITX_EVENT_H_ 18 #include <fcitx-utils/macros.h> 19 #include <fcitx/fcitxcore_export.h> 33 enum class ResetReason {
34 ChangeByInactivate FCITXCORE_DEPRECATED,
35 LostFocus FCITXCORE_DEPRECATED,
36 SwitchIM FCITXCORE_DEPRECATED,
62 enum class InputMethodMode { PhysicalKeyboard, OnScreenKeyboard };
68 EventTypeFlag = 0xfffff000,
69 UserTypeFlag = 0xffff0000,
71 InputContextEventFlag = 0x0001000,
73 InputMethodEventFlag = 0x0002000,
79 InputContextCreated = InputContextEventFlag | 0x1,
80 InputContextDestroyed = InputContextEventFlag | 0x2,
117 InputContextSurroundingTextUpdated = InputContextEventFlag | 0x7,
118 InputContextCapabilityChanged = InputContextEventFlag | 0x8,
119 InputContextCursorRectChanged = InputContextEventFlag | 0x9,
120 InputContextCapabilityAboutToChange = InputContextEventFlag | 0xD,
132 InputContextInputMethodActivated = InputContextEventFlag | 0xB,
133 InputContextInputMethodDeactivated = InputContextEventFlag | 0xC,
143 InputContextVirtualKeyboardEvent = InputContextEventFlag | 0xF,
145 InputContextForwardKey = InputMethodEventFlag | 0x1,
146 InputContextCommitString = InputMethodEventFlag | 0x2,
147 InputContextDeleteSurroundingText = InputMethodEventFlag | 0x3,
148 InputContextUpdatePreedit = InputMethodEventFlag | 0x4,
149 InputContextUpdateUI = InputMethodEventFlag | 0x5,
150 InputContextCommitStringWithCursor = InputMethodEventFlag | 0x6,
151 InputContextFlushUI = InputMethodEventFlag | 0x7,
211 template <EventType T>
214 template <EventType T>
217 #define FCITX_DEFINE_EVENT_TYPE(KLASS, TYPE) \ 219 struct EventForType<EventType::TYPE> { \ 220 using type = KLASS; \ 238 void accept() { accepted_ =
true; }
263 auto flag =
static_cast<uint32_t
>(EventType::InputContextEventFlag);
264 auto mask =
static_cast<uint32_t
>(EventType::EventTypeFlag);
265 return (static_cast<uint32_t>(type_) & mask) == flag;
270 bool accepted_ =
false;
276 :
Event(type), ic_(context) {}
326 bool isRelease =
false,
int time = 0);
383 bool isRelease()
const {
return isRelease_; }
384 int time()
const {
return time_; }
412 bool check(
const Key &key,
426 bool checkKeyList(std::span<const Key> keys,
431 Key key_, origKey_, rawKey_;
434 bool forward_ =
false;
444 void filter() { filtered_ =
true; }
445 bool filtered()
const override {
return filtered_; }
446 void filterAndAccept() {
452 bool filtered_ =
false;
464 void setKey(
Key key);
465 const Key &key()
const;
467 void setPosition(
float x,
float y);
471 void setLongPress(
bool longPress);
472 bool isLongPress()
const;
474 void setUserAction(uint64_t actionId);
475 uint64_t userAction()
const;
477 void setText(std::string text);
478 const std::string &text()
const;
480 std::unique_ptr<KeyEvent> toKeyEvent()
const;
484 std::unique_ptr<VirtualKeyboardEventPrivate> d_ptr;
491 :
KeyEventBase(EventType::InputContextForwardKey, context, rawKey,
501 const std::string &text()
const {
return text_; }
518 EventType::InputContextCommitStringWithCursor),
519 text_(std::move(text)), cursor_(cursor) {}
521 const std::string &text()
const {
return text_; }
522 size_t cursor()
const {
return cursor_; }
531 enum class Action { LeftClick, RightClick };
534 action_(action), cursor_(cursor) {}
536 Action action()
const {
return action_; }
537 int cursor()
const {
return cursor_; }
543 bool filtered()
const override {
return filtered_; }
548 bool filtered_ =
false;
555 const std::string &oldIM,
558 reason_(reason), oldInputMethod_(oldIM) {}
561 const std::string &oldInputMethod()
const {
return oldInputMethod_; }
565 std::string oldInputMethod_;
575 reason_(ResetReason::Client) {}
577 FCITXCORE_DEPRECATED ResetReason reason()
const {
return reason_; }
588 component_(component), immediate_(immediate) {}
591 bool immediate()
const {
return immediate_; }
608 component_(component) {}
628 const std::string &name()
const {
return name_; }
639 EventType::InputContextInputMethodActivated, name, context) {}
647 EventType::InputContextInputMethodDeactivated, name, context) {}
650 #define FCITX_DEFINE_SIMPLE_EVENT(NAME, TYPE, ARGS...) \ 651 struct FCITXCORE_EXPORT NAME##Event : public InputContextEvent { \ 652 NAME##Event(InputContext *ic) \ 653 : InputContextEvent(ic, EventType::TYPE) {} \ 656 FCITX_DEFINE_SIMPLE_EVENT(InputContextCreated, InputContextCreated);
657 FCITX_DEFINE_SIMPLE_EVENT(InputContextDestroyed, InputContextDestroyed);
660 FCITX_DEFINE_SIMPLE_EVENT(SurroundingTextUpdated,
661 InputContextSurroundingTextUpdated);
662 FCITX_DEFINE_SIMPLE_EVENT(CursorRectChanged, InputContextCursorRectChanged);
663 FCITX_DEFINE_SIMPLE_EVENT(UpdatePreedit, InputContextUpdatePreedit);
692 bool filtered()
const override {
return filtered_; }
695 bool filtered_ =
false;
708 oldFocus_(oldFocus), newFocus_(newFocus) {}
747 newFlags_(newFlags) {}
749 auto oldFlags()
const {
return oldFlags_; }
750 auto newFlags()
const {
return newFlags_; }
762 oldFlags, newFlags) {}
770 oldFlags, newFlags) {}
780 InputContextSurroundingTextUpdated);
784 InputContextCapabilityAboutToChange);
788 InputContextInputMethodActivated);
790 InputContextInputMethodDeactivated);
798 InputContextCommitStringWithCursor);
813 #endif // _FCITX_EVENT_H_ InputMethodGroupAboutToChangeEvent is generated when input method group is about to be changed...
bool accepted() const
Return value used by Instance::postEvent.
Match the original key event.
EventType
Type of input method events.
Switched by alternative trigger key.
void setHasUpdate()
Make checking update short circuit.
FocusInEvent is generated when client gets focused.
Notify a focus change for focus group.
Switched by activate key.
This is generated when input method group changed.
when user switch to a different input method by hand such as ctrl+shift by default, or by ui, default behavior is reset IM.
InputMethodSwitchedReason
The reason why input method is switched to another.
void setKey(const Key &key)
It will automatically be called if input method layout does not match the system keyboard layout...
Key key() const
Normalized key event.
Match the original key event before layout conversion, after normalization.
bool isVirtual() const
Whether this key event is derived from a virtual keyboard.
virtual bool filtered() const
Whether a event is filtered by handler.
Switched by group change.
bool filtered() const override
Whether a event is filtered by handler.
Base class for fcitx event.
Virtual keyboard visibility changed.
Enum type for input context capability.
Switched by capability change (e.g. password field)
Base class for User Interface addon.
KeyEventMatchingMode
Key event matching mode.
Global config is reloaded.
Events triggered that user interface manager that flush the UI update.
InvokeAction event is generated when client click on the preedit.
bool filtered() const override
Whether a event is filtered by handler.
FocusGroupFocusChanged is posted when a focus group changed its focused input context.
Match the normalized key event.
Key rawKey() const
Key event after layout conversion.
CheckUpdateEvent is posted when the Instance is requested to check for newly installed addons and inp...
Input method mode changed.
bool filtered() const override
Whether a event is filtered by handler.
bool isInputContextEvent() const
A helper function to check if a event is input context event.
UIChangedEvent is posted when the UI implementation is changed.
Key origKey() const
Key event regardless of keyboard layout conversion.
Class provides bit flag support for Enum.
Event for commit string with cursor.
Helper template class to make easier to use type safe enum flags.
EventType type() const
Type of event, can be used to decide event class.
An input context represents a client of Fcitx.
Key event is generated when client press or release a key.
Class to represent a key.
void setRawKey(const Key &key)
It is designed for faking the key event.
Switched by deactivate key.
bool forward() const
If true, the key that produce character will commit a string.
void setForward(bool forward)
It is designed for overriding the key forward option.
Notify the global config is reloaded.
when using lost focus this might be variance case to case.
Switched by enumerate key.
Key normalize() const
Normalize a key, usually used when key is from frontend.