Add Keyboard input and enter support for text editor.
This commit is contained in:
parent
cf9bace272
commit
9301769d58
23 changed files with 315 additions and 121 deletions
|
@ -16,16 +16,32 @@ std::unique_ptr<XcbEventInterface> XcbEventInterface::Create()
|
|||
std::unique_ptr<KeyboardEvent> XcbEventInterface::ConvertKeyPress(xcb_key_press_event_t* event, Keyboard* keyboard) const
|
||||
{
|
||||
auto ui_event = KeyboardEvent::Create();
|
||||
ui_event->SetAction(KeyboardEvent::Action::Pressed);
|
||||
ui_event->SetKeyString(keyboard->getKeyString(event->detail));
|
||||
ui_event->setAction(KeyboardEvent::Action::Pressed);
|
||||
|
||||
if (auto function = keyboard->getFunction(event->detail); function != Keyboard::Function::UNSET)
|
||||
{
|
||||
ui_event->setFunction(function);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui_event->setKeyString(keyboard->getKeyString(event->detail));
|
||||
}
|
||||
return ui_event;
|
||||
}
|
||||
|
||||
std::unique_ptr<KeyboardEvent> XcbEventInterface::ConvertKeyRelease(xcb_key_press_event_t* event, Keyboard* keyboard) const
|
||||
{
|
||||
auto ui_event = KeyboardEvent::Create();
|
||||
ui_event->SetAction(KeyboardEvent::Action::Released);
|
||||
ui_event->SetKeyString(keyboard->getKeyString(event->detail));
|
||||
ui_event->setAction(KeyboardEvent::Action::Released);
|
||||
|
||||
if (auto function = keyboard->getFunction(event->detail); function != Keyboard::Function::UNSET)
|
||||
{
|
||||
ui_event->setFunction(function);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui_event->setKeyString(keyboard->getKeyString(event->detail));
|
||||
}
|
||||
return ui_event;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
class XcbExtensionInterface
|
||||
{
|
||||
public:
|
||||
|
||||
void initialize(xcb_connection_t* connection);
|
||||
|
||||
bool isXkBEvent(unsigned responseType) const;
|
||||
|
|
|
@ -34,6 +34,25 @@ void XcbKeyboard::updateState(xcb_xkb_state_notify_event_t *state)
|
|||
state->lockedGroup);
|
||||
}
|
||||
|
||||
Keyboard::Function XcbKeyboard::getFunction(Keyboard::KeyCode code)
|
||||
{
|
||||
if (!mXkbState)
|
||||
{
|
||||
getKeyMap();
|
||||
}
|
||||
|
||||
xkb_keysym_t sym = xkb_state_key_get_one_sym(mXkbState, code);
|
||||
if (sym == XKB_KEY_Return)
|
||||
{
|
||||
return Keyboard::Function::ENTER;
|
||||
}
|
||||
else if(sym == XKB_KEY_BackSpace)
|
||||
{
|
||||
return Keyboard::Function::BACKSPACE;
|
||||
}
|
||||
return Keyboard::Function::UNSET;
|
||||
}
|
||||
|
||||
std::string XcbKeyboard::getKeyString(KeyCode keyCode)
|
||||
{
|
||||
if (!mXkbState)
|
||||
|
|
|
@ -15,6 +15,8 @@ public:
|
|||
|
||||
std::string getKeyString(KeyCode keyCode) override;
|
||||
|
||||
Function getFunction(KeyCode code) override;
|
||||
|
||||
void updateState(xcb_xkb_state_notify_event_t *state);
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue