7 #ifndef _FCITX_EVENT_H_ 8 #define _FCITX_EVENT_H_ 17 #include <fcitx-utils/macros.h> 18 #include <fcitx/fcitxcore_export.h> 20 #include "fcitx/inputmethodgroup.h" 32 enum class ResetReason {
33 ChangeByInactivate FCITXCORE_DEPRECATED,
34 LostFocus FCITXCORE_DEPRECATED,
35 SwitchIM FCITXCORE_DEPRECATED,
61 enum class InputMethodMode { PhysicalKeyboard, OnScreenKeyboard };
67 EventTypeFlag = 0xfffff000,
68 UserTypeFlag = 0xffff0000,
70 InputContextEventFlag = 0x0001000,
72 InputMethodEventFlag = 0x0002000,
78 InputContextCreated = InputContextEventFlag | 0x1,
79 InputContextDestroyed = InputContextEventFlag | 0x2,
116 InputContextSurroundingTextUpdated = InputContextEventFlag | 0x7,
117 InputContextCapabilityChanged = InputContextEventFlag | 0x8,
118 InputContextCursorRectChanged = InputContextEventFlag | 0x9,
119 InputContextCapabilityAboutToChange = InputContextEventFlag | 0xD,
131 InputContextInputMethodActivated = InputContextEventFlag | 0xB,
132 InputContextInputMethodDeactivated = InputContextEventFlag | 0xC,
142 InputContextVirtualKeyboardEvent = InputContextEventFlag | 0xF,
144 InputContextForwardKey = InputMethodEventFlag | 0x1,
145 InputContextCommitString = InputMethodEventFlag | 0x2,
146 InputContextDeleteSurroundingText = InputMethodEventFlag | 0x3,
147 InputContextUpdatePreedit = InputMethodEventFlag | 0x4,
148 InputContextUpdateUI = InputMethodEventFlag | 0x5,
149 InputContextCommitStringWithCursor = InputMethodEventFlag | 0x6,
150 InputContextFlushUI = InputMethodEventFlag | 0x7,
210 template <EventType T>
213 template <EventType T>
216 #define FCITX_DEFINE_EVENT_TYPE(KLASS, TYPE) \ 218 struct EventForType<EventType::TYPE> { \ 219 using type = KLASS; \ 237 void accept() { accepted_ =
true; }
262 auto flag =
static_cast<uint32_t
>(EventType::InputContextEventFlag);
263 auto mask =
static_cast<uint32_t
>(EventType::EventTypeFlag);
264 return (static_cast<uint32_t>(type_) & mask) == flag;
269 bool accepted_ =
false;
275 :
Event(type), ic_(context) {}
286 bool isRelease =
false,
int time = 0);
343 bool isRelease()
const {
return isRelease_; }
344 int time()
const {
return time_; }
364 Key key_, origKey_, rawKey_;
367 bool forward_ =
false;
377 void filter() { filtered_ =
true; }
378 bool filtered()
const override {
return filtered_; }
379 void filterAndAccept() {
385 bool filtered_ =
false;
397 void setKey(
Key key);
398 const Key &key()
const;
400 void setPosition(
float x,
float y);
404 void setLongPress(
bool longPress);
405 bool isLongPress()
const;
407 void setUserAction(uint64_t actionId);
408 uint64_t userAction()
const;
410 void setText(std::string text);
411 const std::string &text()
const;
413 std::unique_ptr<KeyEvent> toKeyEvent()
const;
417 std::unique_ptr<VirtualKeyboardEventPrivate> d_ptr;
424 :
KeyEventBase(EventType::InputContextForwardKey, context, rawKey,
434 const std::string &text()
const {
return text_; }
451 EventType::InputContextCommitStringWithCursor),
452 text_(std::move(text)), cursor_(cursor) {}
454 const std::string &text()
const {
return text_; }
455 size_t cursor()
const {
return cursor_; }
464 enum class Action { LeftClick, RightClick };
467 action_(action), cursor_(cursor) {}
469 Action action()
const {
return action_; }
470 int cursor()
const {
return cursor_; }
476 bool filtered()
const override {
return filtered_; }
481 bool filtered_ =
false;
488 const std::string &oldIM,
491 reason_(reason), oldInputMethod_(oldIM) {}
494 const std::string &oldInputMethod()
const {
return oldInputMethod_; }
498 std::string oldInputMethod_;
508 reason_(ResetReason::Client) {}
510 FCITXCORE_DEPRECATED ResetReason reason()
const {
return reason_; }
521 component_(component), immediate_(immediate) {}
524 bool immediate()
const {
return immediate_; }
541 component_(component) {}
561 const std::string &name()
const {
return name_; }
572 EventType::InputContextInputMethodActivated, name, context) {}
580 EventType::InputContextInputMethodDeactivated, name, context) {}
583 #define FCITX_DEFINE_SIMPLE_EVENT(NAME, TYPE, ARGS...) \ 584 struct FCITXCORE_EXPORT NAME##Event : public InputContextEvent { \ 585 NAME##Event(InputContext *ic) \ 586 : InputContextEvent(ic, EventType::TYPE) {} \ 589 FCITX_DEFINE_SIMPLE_EVENT(InputContextCreated, InputContextCreated);
590 FCITX_DEFINE_SIMPLE_EVENT(InputContextDestroyed, InputContextDestroyed);
593 FCITX_DEFINE_SIMPLE_EVENT(SurroundingTextUpdated,
594 InputContextSurroundingTextUpdated);
595 FCITX_DEFINE_SIMPLE_EVENT(CursorRectChanged, InputContextCursorRectChanged);
596 FCITX_DEFINE_SIMPLE_EVENT(UpdatePreedit, InputContextUpdatePreedit);
625 bool filtered()
const override {
return filtered_; }
628 bool filtered_ =
false;
641 oldFocus_(oldFocus), newFocus_(newFocus) {}
680 newFlags_(newFlags) {}
682 auto oldFlags()
const {
return oldFlags_; }
683 auto newFlags()
const {
return newFlags_; }
695 oldFlags, newFlags) {}
703 oldFlags, newFlags) {}
713 InputContextSurroundingTextUpdated);
717 InputContextCapabilityAboutToChange);
721 InputContextInputMethodActivated);
723 InputContextInputMethodDeactivated);
731 InputContextCommitStringWithCursor);
746 #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.
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.
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.
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.
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.
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.