diff --git a/apps/sample-gui/text_editor/TextEditorView.cpp b/apps/sample-gui/text_editor/TextEditorView.cpp index 051b052..d376999 100644 --- a/apps/sample-gui/text_editor/TextEditorView.cpp +++ b/apps/sample-gui/text_editor/TextEditorView.cpp @@ -25,6 +25,7 @@ void TextEditorView::Initialize() label->setMargin(1); auto textBox = TextBox::Create(); + textBox->setName("Text Box"); mTextBox = textBox.get(); auto saveButton = Button::Create(); diff --git a/src/client/TabbedPanelWidget.cpp b/src/client/TabbedPanelWidget.cpp index 5ac5486..6fda26d 100644 --- a/src/client/TabbedPanelWidget.cpp +++ b/src/client/TabbedPanelWidget.cpp @@ -49,6 +49,8 @@ void TabbedPanelWidget::addPanel(WidgetUPtr panel, const std::string& label) button->setOnClickFunction(onClick); mStack->addWidget(std::move(panel)); + mStack->showChild(rawPanel); + mNavPanel->addWidget(std::move(button)); } diff --git a/src/core/StringUtils.cpp b/src/core/StringUtils.cpp index a0faf38..b845cff 100644 --- a/src/core/StringUtils.cpp +++ b/src/core/StringUtils.cpp @@ -20,6 +20,17 @@ bool StringUtils::IsSpace(char c) return std::isspace(c, loc); } +std::vector StringUtils::toLines(const std::string& input) +{ + auto result = std::vector{}; + auto ss = std::stringstream{input}; + for (std::string line; std::getline(ss, line, '\n');) + { + result.push_back(line); + } + return result; +} + std::string StringUtils::strip(const std::string& input) { if (input.empty()) diff --git a/src/core/StringUtils.h b/src/core/StringUtils.h index 14f50c1..45db271 100644 --- a/src/core/StringUtils.h +++ b/src/core/StringUtils.h @@ -23,5 +23,8 @@ public: static std::string ToPaddedString(unsigned numBytes, unsigned entry); static std::vector split(const std::string& input); static std::string strip(const std::string& input); + + static std::vector toLines(const std::string& input); + static std::string stripQuotes(const std::string& input); }; diff --git a/src/fonts/FontItem.h b/src/fonts/FontItem.h index 25da69e..c50877f 100644 --- a/src/fonts/FontItem.h +++ b/src/fonts/FontItem.h @@ -38,6 +38,17 @@ public: return mSize; } + bool operator==(const FontItem& rhs) const + { + return (mSize == rhs.mSize) + && (mFaceName == rhs.mFaceName); + } + + bool operator!=(const FontItem& rhs) const + { + return !operator==(rhs); + } + private: unsigned mSize{16}; std::string mFaceName; diff --git a/src/graphics/opengl/OpenGlTextPainter.cpp b/src/graphics/opengl/OpenGlTextPainter.cpp index 727bf05..74ea0f3 100644 --- a/src/graphics/opengl/OpenGlTextPainter.cpp +++ b/src/graphics/opengl/OpenGlTextPainter.cpp @@ -44,13 +44,16 @@ void OpenGlTextPainter::initializeShader() void OpenGlTextPainter::initializeTextures(const TextData& textData, DrawingContext* context) { - for (auto c : textData.mContent) + for (auto line : textData.mLines) { - if (auto iter = mFontTextures.find(c); iter == mFontTextures.end()) + for (auto c : line) { - auto glyph = context->getFontsManager()->getGlyph(textData.mFont.getFaceName(), textData.mFont.getSize(), c); - auto new_texture = std::make_unique(glyph); - mFontTextures[c] = std::move(new_texture); + if (auto iter = mFontTextures.find(c); iter == mFontTextures.end()) + { + auto glyph = context->getFontsManager()->getGlyph(textData.mFont.getFaceName(), textData.mFont.getSize(), c); + auto new_texture = std::make_unique(glyph); + mFontTextures[c] = std::move(new_texture); + } } } } @@ -104,36 +107,43 @@ void OpenGlTextPainter::paint(SceneText* text, DrawingContext* context) auto transform = text->getTransform(); - float x = transform.getLocation().getX(); - const float y = height - transform.getLocation().getY(); - for (auto c : text_data.mContent) + float line_delta = 20; + float line_offset = 0; + for (auto line : text_data.mLines) { - auto texture = mFontTextures[c].get(); + float x = transform.getLocation().getX(); + const float y = height - line_offset - transform.getLocation().getY(); + for (auto c : line) + { + auto texture = mFontTextures[c].get(); - float xpos = x + texture->getGlyph()->getBearingX(); - float ypos = y - (texture->getGlyph()->getHeight() - texture->getGlyph()->getBearingY()); + float xpos = x + texture->getGlyph()->getBearingX(); + float ypos = y - (texture->getGlyph()->getHeight() - texture->getGlyph()->getBearingY()); - float w = texture->getGlyph()->getWidth(); - float h = texture->getGlyph()->getHeight(); - float vertices[6][4] = { - { xpos, ypos + h, 0.0f, 0.0f }, - { xpos, ypos, 0.0f, 1.0f }, - { xpos + w, ypos, 1.0f, 1.0f }, + float w = texture->getGlyph()->getWidth(); + float h = texture->getGlyph()->getHeight(); + float vertices[6][4] = { + { xpos, ypos + h, 0.0f, 0.0f }, + { xpos, ypos, 0.0f, 1.0f }, + { xpos + w, ypos, 1.0f, 1.0f }, - { xpos, ypos + h, 0.0f, 0.0f }, - { xpos + w, ypos, 1.0f, 1.0f }, - { xpos + w, ypos + h, 1.0f, 0.0f } - }; + { xpos, ypos + h, 0.0f, 0.0f }, + { xpos + w, ypos, 1.0f, 1.0f }, + { xpos + w, ypos + h, 1.0f, 0.0f } + }; - glBindTexture(GL_TEXTURE_2D, texture->getHandle()); + glBindTexture(GL_TEXTURE_2D, texture->getHandle()); - glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer); - glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices); - glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer); + glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices); + glBindBuffer(GL_ARRAY_BUFFER, 0); - glDrawArrays(GL_TRIANGLES, 0, 6); + glDrawArrays(GL_TRIANGLES, 0, 6); - x += (texture->getGlyph()->getAdvanceX() >> 6); // bitshift by 6 to get value in pixels (2^6 = 64) + x += (texture->getGlyph()->getAdvanceX() >> 6); // bitshift by 6 to get value in pixels (2^6 = 64) + } + + line_offset += line_delta; } glBindVertexArray(0); diff --git a/src/ui_elements/desktop_elements/Keyboard.cpp b/src/ui_elements/desktop_elements/Keyboard.cpp index 457f988..758529b 100644 --- a/src/ui_elements/desktop_elements/Keyboard.cpp +++ b/src/ui_elements/desktop_elements/Keyboard.cpp @@ -10,3 +10,13 @@ std::unique_ptr Keyboard::Create() return std::make_unique(); } +std::string Keyboard::getKeyString(KeyCode code) +{ + return ""; +} + +Keyboard::Function Keyboard::getFunction(KeyCode code) +{ + return Function::UNSET; +} + diff --git a/src/ui_elements/desktop_elements/Keyboard.h b/src/ui_elements/desktop_elements/Keyboard.h index bebdc8e..45f3e07 100644 --- a/src/ui_elements/desktop_elements/Keyboard.h +++ b/src/ui_elements/desktop_elements/Keyboard.h @@ -6,6 +6,15 @@ class Keyboard { public: + + enum class Function + { + UNSET, + ENTER, + BACKSPACE, + TAB + }; + using KeyCode = unsigned; using KeyState = unsigned; @@ -16,10 +25,10 @@ public: static std::unique_ptr Create(); - virtual std::string getKeyString(KeyCode code) - { - return ""; - } + virtual std::string getKeyString(KeyCode code); + + virtual Function getFunction(KeyCode code); + }; using KeyboardUPtr = std::unique_ptr; diff --git a/src/ui_elements/ui_events/KeyboardEvent.cpp b/src/ui_elements/ui_events/KeyboardEvent.cpp index 06e3280..6d81123 100644 --- a/src/ui_elements/ui_events/KeyboardEvent.cpp +++ b/src/ui_elements/ui_events/KeyboardEvent.cpp @@ -18,22 +18,37 @@ std::unique_ptr KeyboardEvent::Create() return std::make_unique(); } -void KeyboardEvent::SetKeyString(const std::string& key) +void KeyboardEvent::setKeyString(const std::string& key) { mKeyString = key; } -std::string KeyboardEvent::GetKeyString() const +std::string KeyboardEvent::getKeyString() const { return mKeyString; } -void KeyboardEvent::SetAction(Action action) +void KeyboardEvent::setAction(Action action) { mAction = action; } -KeyboardEvent::Action KeyboardEvent::GetAction() const +KeyboardEvent::Action KeyboardEvent::getAction() const { return mAction; } + +bool KeyboardEvent::isFunctionKey() const +{ + return mFunction != Keyboard::Function::UNSET; +} + +Keyboard::Function KeyboardEvent::getFunction() const +{ + return mFunction; +} + +void KeyboardEvent::setFunction(Keyboard::Function function) +{ + mFunction = function; +} diff --git a/src/ui_elements/ui_events/KeyboardEvent.h b/src/ui_elements/ui_events/KeyboardEvent.h index 9dcc8f5..cdffb2b 100644 --- a/src/ui_elements/ui_events/KeyboardEvent.h +++ b/src/ui_elements/ui_events/KeyboardEvent.h @@ -4,6 +4,7 @@ #include #include "UiEvent.h" +#include "Keyboard.h" class KeyboardEvent : public UiEvent { @@ -14,11 +15,6 @@ public: Released }; -private: - - Action mAction; - std::string mKeyString; - public: KeyboardEvent(); @@ -27,13 +23,25 @@ public: static std::unique_ptr Create(); - void SetKeyString(const std::string& key); + void setKeyString(const std::string& key); - std::string GetKeyString() const; + std::string getKeyString() const; - void SetAction(Action action); + void setAction(Action action); - Action GetAction() const; + Action getAction() const; + + bool isFunctionKey() const; + + Keyboard::Function getFunction() const; + + void setFunction(Keyboard::Function function); + +private: + + Keyboard::Function mFunction{Keyboard::Function::UNSET}; + Action mAction; + std::string mKeyString; }; using KeyboardEventUPtr = std::unique_ptr; diff --git a/src/ui_elements/widgets/Button.cpp b/src/ui_elements/widgets/Button.cpp index 8db6b47..267076c 100644 --- a/src/ui_elements/widgets/Button.cpp +++ b/src/ui_elements/widgets/Button.cpp @@ -75,12 +75,16 @@ void Button::updateLabel(const PaintEvent* event) mTextNode = TextNode::Create(mLabel, middle); mTextNode->setName(mName + "_TextNode"); mTextNode->setContent(mLabel); + mTextNode->setWidth(mSize.mWidth); + mTextNode->setHeight(mSize.mHeight); mRootNode->addChild(mTextNode.get()); } if (mTransformDirty) { mTextNode->setLocation(middle); + mTextNode->setWidth(mSize.mWidth); + mTextNode->setHeight(mSize.mHeight); } if (mMaterialDirty) diff --git a/src/ui_elements/widgets/Label.cpp b/src/ui_elements/widgets/Label.cpp index f29b99d..2f64d73 100644 --- a/src/ui_elements/widgets/Label.cpp +++ b/src/ui_elements/widgets/Label.cpp @@ -44,6 +44,8 @@ void Label::updateLabel(const PaintEvent* event) if (!mTextNode) { mTextNode = TextNode::Create(mLabel, middle); + mTextNode->setWidth(mSize.mWidth); + mTextNode->setHeight(mSize.mHeight); mRootNode->addChild(mTextNode.get()); } @@ -55,6 +57,8 @@ void Label::updateLabel(const PaintEvent* event) if (mTransformDirty) { mTextNode->setLocation(middle); + mTextNode->setWidth(mSize.mWidth); + mTextNode->setHeight(mSize.mHeight); } if (mContentDirty) diff --git a/src/ui_elements/widgets/TextBox.cpp b/src/ui_elements/widgets/TextBox.cpp index 2232973..66cec27 100644 --- a/src/ui_elements/widgets/TextBox.cpp +++ b/src/ui_elements/widgets/TextBox.cpp @@ -13,7 +13,7 @@ TextBox::TextBox() mCaps(false) { mBackgroundColor = Color(250, 250, 250); - mPadding = {10, 0, 10, 0}; + mPadding = {20, 0, 20, 0}; } std::unique_ptr TextBox::Create() @@ -40,72 +40,28 @@ void TextBox::appendContent(const std::string& text) bool TextBox::onMyKeyboardEvent(const KeyboardEvent* event) { - if(!event) return false; + if(!event or !mVisible) return false; - const auto keyString = event->GetKeyString(); - if (keyString == "KEY_RETURN") + if(event->isFunctionKey()) { - appendContent("\n"); - } - else if (keyString == "KEY_BACK") - { - mContent = mContent.substr(0, mContent.size()-1); - } - else if (keyString == "KEY_SPACE") - { - appendContent(" "); - } - else if (keyString == "KEY_CAPS") - { - mCaps = !mCaps; + if (event->getFunction() == Keyboard::Function::ENTER) + { + appendContent("\n"); + } + else if(event->getFunction() == Keyboard::Function::BACKSPACE) + { + mContent = mContent.substr(0, mContent.size()-1); + mContentDirty = true; + } } else { - if (mCaps && !keyString.empty()) - { - const char c = std::toupper(keyString[0]); - appendContent(std::string(&c)); - } - else - { - appendContent(keyString); - } + const auto keyString = event->getKeyString(); + appendContent(keyString); } return true; } -/* -void TextBox::onPaintEvent(const PaintEvent* event) -{ - mMyLayers.clear(); - addBackground(event); - - double offset = 0; - if(!mContent.empty()) - { - std::stringstream stream(mContent); - std::string segment; - std::vector seglist; - while(std::getline(stream, segment, '\n')) - { - seglist.push_back(segment); - } - for(const auto& line : seglist) - { - auto loc = DiscretePoint(mLocation.GetX() + mPadding.mLeft, - mLocation.GetY() + mPadding.mTop + unsigned(offset)); - auto textLayer = VisualLayer::Create(); - auto textElement = TextNode::Create(line, loc); - textElement->setFillColor(mBackgroundColor); - textLayer->setTextNode(std::move(textElement)); - mMyLayers.push_back(std::move(textLayer)); - offset += 20; - } - } - addMyLayers(); -} -*/ - bool TextBox::isDirty() const { return Widget::isDirty() || mContentDirty; @@ -119,12 +75,13 @@ void TextBox::doPaint(const PaintEvent* event) void TextBox::updateLabel(const PaintEvent* event) { - unsigned fontOffset = unsigned(mContent.size()) * 4; - auto middle = DiscretePoint(mLocation.GetX() + mSize.mWidth/2 - fontOffset, mLocation.GetY() + mSize.mHeight/2 + 4); + auto loc = DiscretePoint(mLocation.GetX() + mPadding.mLeft, mLocation.GetY() + mPadding.mTop + unsigned(0)); if (!mTextNode) { - mTextNode = TextNode::Create(mContent, middle); + mTextNode = TextNode::Create(mContent, loc); + mTextNode->setWidth(mSize.mWidth); + mTextNode->setHeight(mSize.mHeight); mRootNode->addChild(mTextNode.get()); } @@ -133,6 +90,13 @@ void TextBox::updateLabel(const PaintEvent* event) mTextNode->setFillColor(mBackgroundColor); } + if (mTransformDirty) + { + mTextNode->setLocation(loc); + mTextNode->setWidth(mSize.mWidth); + mTextNode->setHeight(mSize.mHeight); + } + if (mContentDirty) { mTextNode->setContent(mContent); diff --git a/src/ui_elements/widgets/Widget.h b/src/ui_elements/widgets/Widget.h index 95af36f..b73beba 100644 --- a/src/ui_elements/widgets/Widget.h +++ b/src/ui_elements/widgets/Widget.h @@ -1,6 +1,7 @@ #pragma once #include "DiscretePoint.h" +#include "FontItem.h" #include "Color.h" #include @@ -149,6 +150,8 @@ protected: std::string mName; std::vector mPendingChildNodes; + + FontItem mDefaultFont; }; using WidgetUPtr = std::unique_ptr; diff --git a/src/visual_elements/SceneText.cpp b/src/visual_elements/SceneText.cpp index 379c45e..5ab4822 100644 --- a/src/visual_elements/SceneText.cpp +++ b/src/visual_elements/SceneText.cpp @@ -15,11 +15,11 @@ const TextData& SceneText::getTextData() const return mTextData; } -void SceneText::setContent(const std::string& content) +void SceneText::setTextData(const TextData& data) { - if (mTextData.mContent != content) + if (mTextData != data) { mTextGeometryIsDirty = true; - mTextData.mContent = content; + mTextData = data; } } diff --git a/src/visual_elements/SceneText.h b/src/visual_elements/SceneText.h index 0cb2ade..59ec840 100644 --- a/src/visual_elements/SceneText.h +++ b/src/visual_elements/SceneText.h @@ -12,7 +12,7 @@ public: const TextData& getTextData() const; - void setContent(const std::string& content); + void setTextData(const TextData& content); private: bool mTextGeometryIsDirty{true}; diff --git a/src/visual_elements/TextData.h b/src/visual_elements/TextData.h index a94a6f3..a445e13 100644 --- a/src/visual_elements/TextData.h +++ b/src/visual_elements/TextData.h @@ -3,10 +3,27 @@ #include "Color.h" #include "FontItem.h" +#include + class TextData { +public: + bool operator==(const TextData& rhs) const + { + return (mContent == rhs.mContent) + && (mLines == rhs.mLines) + && (mFont == rhs.mFont); + } + + bool operator!=(const TextData& rhs) const + { + return !operator==(rhs); + } + + public: TextData() = default; std::string mContent; + std::vector mLines; FontItem mFont; }; diff --git a/src/visual_elements/TextNode.cpp b/src/visual_elements/TextNode.cpp index 907a324..0db5832 100644 --- a/src/visual_elements/TextNode.cpp +++ b/src/visual_elements/TextNode.cpp @@ -5,17 +5,20 @@ #include "IFontEngine.h" #include "MeshPrimitives.h" #include "FontItem.h" +#include "FontGlyph.h" #include "SceneText.h" #include "Color.h" +#include "StringUtils.h" + #include TextNode::TextNode(const std::string& content, const DiscretePoint& loc) : MaterialNode(loc) { - mContent= content; + mTextData.mContent= content; } TextNode::~TextNode() @@ -35,18 +38,82 @@ std::string TextNode::getFontLabel() const std::string TextNode::getContent() const { - return mContent; + return mTextData.mContent; +} + +unsigned TextNode::getWidth() const +{ + return mWidth; +} + +unsigned TextNode::getHeight() const +{ + return mHeight; +} + +void TextNode::setWidth(unsigned width) +{ + if (mWidth != width) + { + mTransformIsDirty = true; + mWidth = width; + } +} + +void TextNode::setHeight(unsigned height) +{ + if (mHeight != height) + { + mTransformIsDirty = true; + mHeight = height; + } } void TextNode::setContent(const std::string& content) { - if (mContent != content) + if (mTextData.mContent != content) { - mContent = content; + mTextData.mContent = content; mContentIsDirty = true; } } +void TextNode::updateLines(FontsManager* fontsManager) +{ + auto original_count = mTextData.mLines.size(); + std::vector lines = StringUtils::toLines(mTextData.mContent); + std::vector output_lines; + for (auto line : lines) + { + double running_width{0}; + std::string working_line; + for (auto c : line) + { + auto glyph_advance = fontsManager->getGlyph(mTextData.mFont.getFaceName(), mTextData.mFont.getSize(), c)->getAdvanceX(); + if (false) + //if (running_width + glyph_advance > mWidth) + { + output_lines.push_back(working_line); + working_line = c; + running_width = glyph_advance; + } + else + { + working_line += c; + running_width += glyph_advance; + } + } + output_lines.push_back(working_line); + running_width = 0; + } + mTextData.mLines = output_lines; + + if (original_count != mTextData.mLines.size()) + { + mLinesAreDirty = true; + } +} + void TextNode::update(FontsManager* fontsManager) { if (!mSceneItem) @@ -55,10 +122,16 @@ void TextNode::update(FontsManager* fontsManager) mSceneItem->setName(mName + "_SceneText"); } - if (mContentIsDirty) + if (mTransformIsDirty || mContentIsDirty) { - dynamic_cast(mSceneItem.get())->setContent(mContent); + updateLines(fontsManager); + } + + if (mContentIsDirty || mLinesAreDirty) + { + dynamic_cast(mSceneItem.get())->setTextData(mTextData); mContentIsDirty = false; + mLinesAreDirty = false; } if (mTransformIsDirty) diff --git a/src/visual_elements/TextNode.h b/src/visual_elements/TextNode.h index 5995b2d..15ccea8 100644 --- a/src/visual_elements/TextNode.h +++ b/src/visual_elements/TextNode.h @@ -20,12 +20,25 @@ public: std::string getContent() const; std::string getFontLabel() const; + unsigned getWidth() const; + unsigned getHeight() const; + + void setWidth(unsigned width); + void setHeight(unsigned height); + void setContent(const std::string& content); void update(FontsManager* fontsManager) override; private: - std::string mContent; + + void updateLines(FontsManager* fontsManager); + + TextData mTextData; bool mContentIsDirty{true}; + bool mLinesAreDirty{true}; + + unsigned mWidth{1}; + unsigned mHeight{1}; }; using TextNodetr = std::unique_ptr; diff --git a/src/windows/ui_interfaces/x11/XcbEventInterface.cpp b/src/windows/ui_interfaces/x11/XcbEventInterface.cpp index afa0a55..f790f88 100644 --- a/src/windows/ui_interfaces/x11/XcbEventInterface.cpp +++ b/src/windows/ui_interfaces/x11/XcbEventInterface.cpp @@ -16,16 +16,32 @@ std::unique_ptr XcbEventInterface::Create() std::unique_ptr 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 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; } diff --git a/src/windows/ui_interfaces/x11/XcbExtensionInterface.h b/src/windows/ui_interfaces/x11/XcbExtensionInterface.h index 941e7a6..5b4da7f 100644 --- a/src/windows/ui_interfaces/x11/XcbExtensionInterface.h +++ b/src/windows/ui_interfaces/x11/XcbExtensionInterface.h @@ -8,7 +8,6 @@ class XcbExtensionInterface { public: - void initialize(xcb_connection_t* connection); bool isXkBEvent(unsigned responseType) const; diff --git a/src/windows/ui_interfaces/x11/XcbKeyboard.cpp b/src/windows/ui_interfaces/x11/XcbKeyboard.cpp index a698ea3..9d8776f 100644 --- a/src/windows/ui_interfaces/x11/XcbKeyboard.cpp +++ b/src/windows/ui_interfaces/x11/XcbKeyboard.cpp @@ -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) diff --git a/src/windows/ui_interfaces/x11/XcbKeyboard.h b/src/windows/ui_interfaces/x11/XcbKeyboard.h index 38c010a..aaaf5a2 100644 --- a/src/windows/ui_interfaces/x11/XcbKeyboard.h +++ b/src/windows/ui_interfaces/x11/XcbKeyboard.h @@ -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: