Virtual keyboard Event should also support key press event and key release event

1. There are two kinds of virtual keyboard at least.

2. First, the virtual keyboard is the same as the physical
   keyboard except that the virtual keyboard is displayed
   on the screen while the physical keyboard not. So, the
   virtual keyboard and the physical keyboard should use
   the same logic of input method engine.

3. Second, the virtual keyboard use a different logic of
   input method engine which is dedicated to the virtual
   keyboard. In this case, the press event and the release
   event may not be so important.
This commit is contained in:
liulinsong 2023-03-02 09:15:05 +08:00 committed by hanteng
parent f20de9fe15
commit bbae9fc7f6
3 changed files with 10 additions and 6 deletions

View File

@ -11,9 +11,11 @@ namespace fcitx {
class VirtualKeyboardEventPrivate { class VirtualKeyboardEventPrivate {
public: public:
VirtualKeyboardEventPrivate(int time) : time_(time) {} VirtualKeyboardEventPrivate(bool isRelease, int time)
: isRelease_(isRelease), time_(time) {}
Key key_; Key key_;
bool isRelease_ = false;
int time_ = 0; int time_ = 0;
uint64_t userAction_ = 0; uint64_t userAction_ = 0;
std::string text_; std::string text_;
@ -28,9 +30,10 @@ KeyEventBase::KeyEventBase(EventType type, InputContext *context, Key rawKey,
: InputContextEvent(context, type), key_(rawKey.normalize()), : InputContextEvent(context, type), key_(rawKey.normalize()),
origKey_(rawKey), rawKey_(rawKey), isRelease_(isRelease), time_(time) {} origKey_(rawKey), rawKey_(rawKey), isRelease_(isRelease), time_(time) {}
VirtualKeyboardEvent::VirtualKeyboardEvent(InputContext *context, int time) VirtualKeyboardEvent::VirtualKeyboardEvent(InputContext *context,
bool isRelease, int time)
: InputContextEvent(context, EventType::InputContextVirtualKeyboardEvent), : InputContextEvent(context, EventType::InputContextVirtualKeyboardEvent),
d_ptr(std::make_unique<VirtualKeyboardEventPrivate>(time)) {} d_ptr(std::make_unique<VirtualKeyboardEventPrivate>(isRelease, time)) {}
FCITX_DEFINE_DEFAULT_DTOR(VirtualKeyboardEvent); FCITX_DEFINE_DEFAULT_DTOR(VirtualKeyboardEvent);
@ -58,7 +61,8 @@ std::unique_ptr<KeyEvent> fcitx::VirtualKeyboardEvent::toKeyEvent() const {
Key key{d->key_.sym(), d->key_.states() | KeyState::Virtual, Key key{d->key_.sym(), d->key_.states() | KeyState::Virtual,
d->key_.code()}; d->key_.code()};
return std::make_unique<KeyEvent>(inputContext(), key, false, time()); return std::make_unique<KeyEvent>(inputContext(), key, d->isRelease_,
time());
} }
} // namespace fcitx } // namespace fcitx

View File

@ -339,7 +339,7 @@ class VirtualKeyboardEventPrivate;
class FCITXCORE_EXPORT VirtualKeyboardEvent : public InputContextEvent { class FCITXCORE_EXPORT VirtualKeyboardEvent : public InputContextEvent {
public: public:
VirtualKeyboardEvent(InputContext *context, int time = 0); VirtualKeyboardEvent(InputContext *context, bool isRelease, int time = 0);
~VirtualKeyboardEvent(); ~VirtualKeyboardEvent();
int time() const; int time() const;

View File

@ -153,7 +153,7 @@ void VirtualKeyboardBackend::processKeyEvent(uint32_t keyval, uint32_t keycode,
return; return;
} }
VirtualKeyboardEvent event(inputContext, time); VirtualKeyboardEvent event(inputContext, isRelease, time);
event.setKey(Key(static_cast<KeySym>(keyval), KeyStates(state), keycode)); event.setKey(Key(static_cast<KeySym>(keyval), KeyStates(state), keycode));
auto eventConsumed = inputContext->virtualKeyboardEvent(event); auto eventConsumed = inputContext->virtualKeyboardEvent(event);