7 #ifndef _FCITX_EVENT_H_ 8 #define _FCITX_EVENT_H_ 14 #include "fcitxcore_export.h" 21 enum class ResetReason {
22 ChangeByInactivate FCITXCORE_DEPRECATED,
23 LostFocus FCITXCORE_DEPRECATED,
24 SwitchIM FCITXCORE_DEPRECATED,
31 enum class InputMethodSwitchedReason {
53 enum class EventType : uint32_t {
54 EventTypeFlag = 0xffff0000,
55 UserTypeFlag = 0xffff0000,
57 InputContextEventFlag = 0x0001000,
59 InputMethodEventFlag = 0x0002000,
64 InstanceEventFlag = 0x0003000,
65 InputContextCreated = InputContextEventFlag | 0x1,
66 InputContextDestroyed = InputContextEventFlag | 0x2,
72 InputContextFocusIn = InputContextEventFlag | 0x3,
92 InputContextFocusOut = InputContextEventFlag | 0x4,
97 InputContextKeyEvent = InputContextEventFlag | 0x5,
102 InputContextReset = InputContextEventFlag | 0x6,
103 InputContextSurroundingTextUpdated = InputContextEventFlag | 0x7,
104 InputContextCapabilityChanged = InputContextEventFlag | 0x8,
105 InputContextCursorRectChanged = InputContextEventFlag | 0x9,
106 InputContextCapabilityAboutToChange = InputContextEventFlag | 0xD,
112 InputContextSwitchInputMethod = InputContextEventFlag | 0xA,
118 InputContextInputMethodActivated = InputContextEventFlag | 0xB,
119 InputContextInputMethodDeactivated = InputContextEventFlag | 0xC,
127 InputContextInvokeAction = InputContextEventFlag | 0xE,
129 InputContextForwardKey = InputMethodEventFlag | 0x1,
130 InputContextCommitString = InputMethodEventFlag | 0x2,
131 InputContextDeleteSurroundingText = InputMethodEventFlag | 0x3,
132 InputContextUpdatePreedit = InputMethodEventFlag | 0x4,
133 InputContextUpdateUI = InputMethodEventFlag | 0x5,
139 InputMethodGroupChanged = InstanceEventFlag | 0x1,
146 InputMethodGroupAboutToChange = InstanceEventFlag | 0x2,
150 UIChanged = InstanceEventFlag | 0x3,
158 CheckUpdate = InstanceEventFlag | 0x4,
170 FocusGroupFocusChanged = InstanceEventFlag | 0x5,
178 Event(EventType type) : type_(type) {}
186 EventType
type()
const {
return type_; }
188 void accept() { accepted_ =
true; }
213 auto flag =
static_cast<uint32_t
>(EventType::InputContextEventFlag);
214 return (static_cast<uint32_t>(type_) & flag) == flag;
219 bool accepted_ =
false;
225 :
Event(type), ic_(context) {}
236 bool isRelease =
false,
int time = 0);
293 bool isRelease()
const {
return isRelease_; }
294 int time()
const {
return time_; }
306 Key key_, origKey_, rawKey_;
309 bool forward_ =
false;
316 :
KeyEventBase(EventType::InputContextKeyEvent, context, rawKey,
319 void filter() { filtered_ =
true; }
320 bool filtered()
const override {
return filtered_; }
321 void filterAndAccept() {
327 bool filtered_ =
false;
334 :
KeyEventBase(EventType::InputContextForwardKey, context, rawKey,
344 const std::string &text()
const {
return text_; }
352 enum class Action { LeftClick, RightClick };
355 action_(action), cursor_(cursor) {}
357 Action action()
const {
return action_; }
358 int cursor()
const {
return cursor_; }
364 bool filtered()
const override {
return filtered_; }
369 bool filtered_ =
false;
376 const std::string &oldIM,
379 reason_(reason), oldInputMethod_(oldIM) {}
381 InputMethodSwitchedReason reason()
const {
return reason_; }
382 const std::string &oldInputMethod()
const {
return oldInputMethod_; }
385 InputMethodSwitchedReason reason_;
386 std::string oldInputMethod_;
396 reason_(ResetReason::Client) {}
398 FCITXCORE_DEPRECATED ResetReason reason()
const {
return reason_; }
409 component_(component), immediate_(immediate) {}
412 bool immediate()
const {
return immediate_; }
425 const std::string &name()
const {
return name_; }
436 EventType::InputContextInputMethodActivated, name, context) {}
444 EventType::InputContextInputMethodDeactivated, name, context) {}
447 #define FCITX_DEFINE_SIMPLE_EVENT(NAME, TYPE, ARGS...) \ 448 struct FCITXCORE_EXPORT NAME##Event : public InputContextEvent { \ 449 NAME##Event(InputContext *ic) \ 450 : InputContextEvent(ic, EventType::TYPE) {} \ 453 FCITX_DEFINE_SIMPLE_EVENT(InputContextCreated, InputContextCreated);
454 FCITX_DEFINE_SIMPLE_EVENT(InputContextDestroyed, InputContextDestroyed);
455 FCITX_DEFINE_SIMPLE_EVENT(FocusIn, InputContextFocusIn);
456 FCITX_DEFINE_SIMPLE_EVENT(FocusOut, InputContextFocusOut);
457 FCITX_DEFINE_SIMPLE_EVENT(SurroundingTextUpdated,
458 InputContextSurroundingTextUpdated);
459 FCITX_DEFINE_SIMPLE_EVENT(CursorRectChanged, InputContextCursorRectChanged);
460 FCITX_DEFINE_SIMPLE_EVENT(UpdatePreedit, InputContextUpdatePreedit);
465 :
Event(EventType::InputMethodGroupChanged) {}
471 :
Event(EventType::InputMethodGroupAboutToChange) {}
489 bool filtered()
const override {
return filtered_; }
492 bool filtered_ =
false;
504 :
Event(EventType::FocusGroupFocusChanged), group_(group),
505 oldFocus_(oldFocus), newFocus_(newFocus) {}
522 newFlags_(newFlags) {}
524 auto oldFlags()
const {
return oldFlags_; }
525 auto newFlags()
const {
return newFlags_; }
537 oldFlags, newFlags) {}
545 oldFlags, newFlags) {}
549 #endif // _FCITX_EVENT_H_
EventType type() const
Type of event, can be used to decide event class.
void setHasUpdate()
Make checking update short circuit.
bool filtered() const override
Whether a event is filtered by handler.
Key origKey() const
Key event regardless of keyboard layout conversion.
Notify a focus change for focus group.
bool isInputContextEvent() const
A helper function to check if a event is input context event.
void setRawKey(const Key &key)
It is designed for faking the key event.
bool filtered() const override
Whether a event is filtered by handler.
Key key() const
Normalized key event.
bool forward() const
If true, the key that produce character will commit a string.
Base class for fcitx event.
void setForward(bool forward)
It is designed for overriding the key forward option.
Enum type for input context capability.
Key rawKey() const
Key event after layout conversion.
Base class for User Interface addon.
bool accepted() const
Return value used by Instance::postEvent.
bool filtered() const override
Whether a event is filtered by handler.
void setKey(const Key &key)
It will automatically be called if input method layout does not match the system keyboard layout...
virtual bool filtered() const
Whether a event is filtered by handler.
Class provides bit flag support for Enum.
An input context represents a client of Fcitx.
Class to represent a key.
Key normalize() const
Normalize a key, usually used when key is from frontend.