From 53b4e1a5841269d1ad647689e1d2660c4150cc1b Mon Sep 17 00:00:00 2001 From: jeon Date: Fri, 28 Aug 2020 16:50:55 +0900 Subject: [PATCH] DSTextInput: Add a TextInput API to get current TextInput window Change-Id: If73ce8395a909588e1fbd4df39303fceb21b582a --- src/DSTextInput/DSTextInput.cpp | 5 ++++ src/DSTextInput/DSTextInputPrivate.h | 1 + src/DSWaylandServer/DSWaylandInputPanel.cpp | 29 ++++++++++++++++++++-- src/DSWaylandServer/DSWaylandInputPanel.h | 1 + .../DSWaylandInputPanelSurfacePrivate.h | 1 + src/DSWaylandServer/DSWaylandTextInput.cpp | 15 ++++++++++- src/DSWaylandServer/DSWaylandTextInput.h | 2 ++ src/DSWaylandServer/DSWaylandTextInputManager.h | 2 ++ src/DSWaylandServer/DSWaylandTextInputPrivate.h | 2 +- tests/DSWaylandInputPanel-test.cpp | 12 +++++++++ tests/DSWaylandTextInput-test.cpp | 14 +++++++++++ tests/DSWaylandTextInputManager-test.cpp | 12 +++++++++ 12 files changed, 92 insertions(+), 4 deletions(-) diff --git a/src/DSTextInput/DSTextInput.cpp b/src/DSTextInput/DSTextInput.cpp index 83e4eb7..9f61c9a 100644 --- a/src/DSTextInput/DSTextInput.cpp +++ b/src/DSTextInput/DSTextInput.cpp @@ -174,6 +174,11 @@ void DSTextInputPrivate::setGeometryUpdated(bool updated) __wlTextInputManager->setGeometryUpdated(updated); } +DSWaylandSurface *DSTextInputPrivate::getTextInputSurface() +{ + return __wlTextInputManager->getTextInputSurface(); +} + void DSTextInputPrivate::contextCommitString(unsigned int serial, std::string text) { diff --git a/src/DSTextInput/DSTextInputPrivate.h b/src/DSTextInput/DSTextInputPrivate.h index ae1199a..d99726a 100644 --- a/src/DSTextInput/DSTextInputPrivate.h +++ b/src/DSTextInput/DSTextInputPrivate.h @@ -83,6 +83,7 @@ public: void predictionHintData(std::string key, std::string value); void updateTextInputPanelState(bool state); void setGeometryUpdated(bool updated); + DSWaylandSurface *getTextInputSurface(); /* DSWaylandInputMethodContext request */ void contextCommitString(unsigned int serial, std::string text); diff --git a/src/DSWaylandServer/DSWaylandInputPanel.cpp b/src/DSWaylandServer/DSWaylandInputPanel.cpp index 51ef817..77c65a0 100644 --- a/src/DSWaylandServer/DSWaylandInputPanel.cpp +++ b/src/DSWaylandServer/DSWaylandInputPanel.cpp @@ -256,6 +256,13 @@ void DSWaylandInputPanel::updateTextInputPanelState(bool state) __dsTextInputPrivate->updateTextInputPanelState(state); } +DSWaylandSurface *DSWaylandInputPanel::getTextInputSurface() +{ + if (!__dsTextInputPrivate) return nullptr; + + return __dsTextInputPrivate->getTextInputSurface(); +} + void DSWaylandInputPanel::__onEventIdleEnterer(void *data) { } @@ -274,8 +281,7 @@ DSWaylandInputPanelSurfacePrivate::~DSWaylandInputPanelSurfacePrivate() void DSWaylandInputPanelSurfacePrivate::createGlobal(void *client, void *inputPanelResource, unsigned int id, void *surface) { Resource *resource = add((struct ::wl_client *)client, id, 1); - DSWaylandInputPanelSurfaceData *data = new DSWaylandInputPanelSurfaceData(resource, inputPanelResource, surface); - __dataMap.insert(std::pair(resource, data)); + __appendSurface(resource, inputPanelResource, surface); } void DSWaylandInputPanelSurfacePrivate::clearGlobals(void *inputPanelResource) @@ -571,6 +577,25 @@ void DSWaylandInputPanelSurfacePrivate::__updateSurfaceVisibility(DSWaylandInput } } +void DSWaylandInputPanelSurfacePrivate::__appendSurface(Resource *resource, void *inputPanelResource, void *surface) +{ + DS_GET_PUB(DSWaylandInputPanelSurface); + DSWaylandInputPanelSurfaceData *data = new DSWaylandInputPanelSurfaceData(resource, inputPanelResource, surface); + __dataMap.insert(std::pair(resource, data)); + + DSWaylandSurface *textInputSurface = pub->__inputPanel->getTextInputSurface(); + + if (textInputSurface) + { + //TODO: transparent set + } + + if (pub->__inputPanel->getRerunPanelShow()) + { + pub->__inputPanel->changeVisibility(true); + } +} + DSWaylandInputPanelSurface::DSWaylandInputPanelSurface(DSWaylandCompositor *compositor, DSWaylandInputPanel *inputPanel) : DSObject(), _d_ptr(std::make_unique(this, compositor)), diff --git a/src/DSWaylandServer/DSWaylandInputPanel.h b/src/DSWaylandServer/DSWaylandInputPanel.h index 4217502..f456580 100644 --- a/src/DSWaylandServer/DSWaylandInputPanel.h +++ b/src/DSWaylandServer/DSWaylandInputPanel.h @@ -63,6 +63,7 @@ public: DSWaylandInputPanelFloating *getFloatingData(); stGeometry getSurfaceGeometry(DSWaylandSurface *wlSurface); void updateTextInputPanelState(bool state); + DSWaylandSurface *getTextInputSurface(); private: DSWaylandCompositor *__compositor; diff --git a/src/DSWaylandServer/DSWaylandInputPanelSurfacePrivate.h b/src/DSWaylandServer/DSWaylandInputPanelSurfacePrivate.h index 6644229..4896e3c 100644 --- a/src/DSWaylandServer/DSWaylandInputPanelSurfacePrivate.h +++ b/src/DSWaylandServer/DSWaylandInputPanelSurfacePrivate.h @@ -68,6 +68,7 @@ private: std::multimap __dataMap; void __updateSurfaceVisibility(DSWaylandInputPanelSurfaceData *surfaceData); + void __appendSurface(Resource *resource, void *inputPanelResource, void *surface); }; } diff --git a/src/DSWaylandServer/DSWaylandTextInput.cpp b/src/DSWaylandServer/DSWaylandTextInput.cpp index e062cb0..743d57c 100644 --- a/src/DSWaylandServer/DSWaylandTextInput.cpp +++ b/src/DSWaylandServer/DSWaylandTextInput.cpp @@ -25,6 +25,7 @@ #include "DSWaylandTextInputManagerPrivate.h" #include "DSWaylandTextInput.h" #include "DSWaylandTextInputPrivate.h" +#include "DSWaylandSurface.h" namespace display_server { @@ -203,6 +204,11 @@ void DSWaylandTextInputManager::setGeometryUpdated(bool updated) __textInput->setGeometryUpdated(updated); } +DSWaylandSurface* DSWaylandTextInputManager::getTextInputSurface() +{ + return __textInput->getClientSurface(); +} + DSWaylandTextInputPrivate::DSWaylandTextInputPrivate(DSWaylandTextInput *p_ptr, DSWaylandCompositor *compositor) : DSObjectPrivate(p_ptr), @@ -297,7 +303,7 @@ void DSWaylandTextInputPrivate::text_input_activate(Resource *resource, struct : pub->__dsTextInputPrivate->activateTextInput(pub, id); __activatedResource = resource; - __clientSurface = surface; + __clientSurface = DSWaylandSurface::fromWlResource(surface); } void DSWaylandTextInputPrivate::text_input_deactivate(Resource *resource, struct ::wl_resource *seat) @@ -1107,4 +1113,11 @@ void DSWaylandTextInput::setGeometryUpdated(bool updated) __geometryUpdated = updated; } +DSWaylandSurface* DSWaylandTextInput::getClientSurface() +{ + DS_GET_PRIV(DSWaylandTextInput); + + return priv->__clientSurface; +} + } diff --git a/src/DSWaylandServer/DSWaylandTextInput.h b/src/DSWaylandServer/DSWaylandTextInput.h index 7f56414..c6b738b 100644 --- a/src/DSWaylandServer/DSWaylandTextInput.h +++ b/src/DSWaylandServer/DSWaylandTextInput.h @@ -33,6 +33,7 @@ namespace display_server class DSWaylandTextInputPrivate; class DSTextInputPrivate; +class DSWaylandSurface; class DS_DECL_EXPORT DSWaylandTextInput : public DSObject { @@ -69,6 +70,7 @@ public: void updatePanelState(bool state); void setGeometryUpdated(bool updated); + DSWaylandSurface* getClientSurface(); protected: diff --git a/src/DSWaylandServer/DSWaylandTextInputManager.h b/src/DSWaylandServer/DSWaylandTextInputManager.h index 8523e10..c19519f 100644 --- a/src/DSWaylandServer/DSWaylandTextInputManager.h +++ b/src/DSWaylandServer/DSWaylandTextInputManager.h @@ -34,6 +34,7 @@ namespace display_server class DSWaylandTextInputManagerPrivate; class DSWaylandTextInput; +class DSWaylansSurface; class DS_DECL_EXPORT DSWaylandTextInputManager : public DSObject { @@ -71,6 +72,7 @@ public: void updateTextInputPanelState(bool state); void setGeometryUpdated(bool updated); + DSWaylandSurface* getTextInputSurface(); protected: diff --git a/src/DSWaylandServer/DSWaylandTextInputPrivate.h b/src/DSWaylandServer/DSWaylandTextInputPrivate.h index bf9ef9d..55fb499 100644 --- a/src/DSWaylandServer/DSWaylandTextInputPrivate.h +++ b/src/DSWaylandServer/DSWaylandTextInputPrivate.h @@ -103,7 +103,7 @@ private: std::multimap __resourceIdMap; struct ::wl_client *__showClient; Resource *__activatedResource; - struct ::wl_resource *__clientSurface; + DSWaylandSurface *__clientSurface; }; } diff --git a/tests/DSWaylandInputPanel-test.cpp b/tests/DSWaylandInputPanel-test.cpp index 7e9b421..04d72a2 100644 --- a/tests/DSWaylandInputPanel-test.cpp +++ b/tests/DSWaylandInputPanel-test.cpp @@ -204,3 +204,15 @@ TEST_F(DSWaylandInputPanelTest, UpdateTextInputPanelState) DSWaylandCompositor::releaseInstance(); } +TEST_F(DSWaylandInputPanelTest, GetTextInputSurface) +{ + DSWaylandCompositor *comp = DSWaylandCompositor::getInstance(); + DSWaylandInputPanel *inputPanel = new DSWaylandInputPanel(comp); + EXPECT_TRUE(inputPanel != nullptr); + + (void)inputPanel->getTextInputSurface(); + + delete inputPanel; + DSWaylandCompositor::releaseInstance(); +} + diff --git a/tests/DSWaylandTextInput-test.cpp b/tests/DSWaylandTextInput-test.cpp index 0befd84..5a3e18e 100644 --- a/tests/DSWaylandTextInput-test.cpp +++ b/tests/DSWaylandTextInput-test.cpp @@ -389,3 +389,17 @@ TEST_F(DSWaylandTextInputTest, SetGeometryUpdated) DSWaylandCompositor::releaseInstance(); } +TEST_F(DSWaylandTextInputTest, GetClientSurface) +{ + DSWaylandCompositor *comp = DSWaylandCompositor::getInstance(); + DSWaylandTextInputManager *textInputManager = new DSWaylandTextInputManager(comp); + DSWaylandTextInput *textInput = new DSWaylandTextInput(comp, textInputManager); + EXPECT_TRUE(textInput != nullptr); + + (void)textInput->getClientSurface(); + + delete textInput; + delete textInputManager; + DSWaylandCompositor::releaseInstance(); +} + diff --git a/tests/DSWaylandTextInputManager-test.cpp b/tests/DSWaylandTextInputManager-test.cpp index 4f74e7f..abca02b 100644 --- a/tests/DSWaylandTextInputManager-test.cpp +++ b/tests/DSWaylandTextInputManager-test.cpp @@ -338,3 +338,15 @@ TEST_F(DSWaylandTextInputManagerTest, SetGeometryUpdated) DSWaylandCompositor::releaseInstance(); } +TEST_F(DSWaylandTextInputManagerTest, GetTextInputSurface) +{ + DSWaylandCompositor *comp = DSWaylandCompositor::getInstance(); + DSWaylandTextInputManager *textInputManager = new DSWaylandTextInputManager(comp); + EXPECT_TRUE(textInputManager != nullptr); + + (void)textInputManager->getTextInputSurface(); + + delete textInputManager; + DSWaylandCompositor::releaseInstance(); +} + -- 2.7.4