Skip to content

Commit

Permalink
clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski committed Mar 19, 2024
1 parent 516061f commit 01f26f6
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 50 deletions.
5 changes: 2 additions & 3 deletions src/helpers/WLClasses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,15 +336,14 @@ struct SSwipeGesture {
struct STextInputV1;

struct STextInput {
wlr_text_input_v3* pWlrInput = nullptr;
STextInputV1* pV1Input = nullptr;
wlr_text_input_v3* pWlrInput = nullptr;
STextInputV1* pV1Input = nullptr;
wlr_surface* focusedSurface = nullptr;

DYNLISTENER(textInputEnable);
DYNLISTENER(textInputDisable);
DYNLISTENER(textInputCommit);
DYNLISTENER(textInputDestroy);

};

struct SIMEKbGrab {
Expand Down
51 changes: 23 additions & 28 deletions src/managers/input/InputMethodRelay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) {

if (PTI)
onTextInputEnter(PTI->focusedSurface);

},
this, "IMERelay");

Expand Down Expand Up @@ -141,7 +140,6 @@ void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) {

if (const auto PTI = getFocusedTextInput(); PTI)
onTextInputEnter(PTI->focusedSurface);

}

wlr_surface* CInputMethodRelay::focusedSurface(STextInput* pTI) {
Expand Down Expand Up @@ -322,13 +320,13 @@ void CInputMethodRelay::onNewTextInput(wlr_text_input_v3* pInput) {

void CInputMethodRelay::createNewTextInput(wlr_text_input_v3* pInput, STextInputV1* pTIV1) {
// if client already has a version, reject
if(pInput){
if(!setTextInputVersion(wl_resource_get_client(pInput->resource), 3))
if (pInput) {
if (!setTextInputVersion(wl_resource_get_client(pInput->resource), 3))
//reject
return;

}else{
if(!setTextInputVersion(pTIV1->client, 1))
} else {
if (!setTextInputVersion(pTIV1->client, 1))
// reject
return;
}
Expand All @@ -352,11 +350,11 @@ void CInputMethodRelay::createNewTextInput(wlr_text_input_v3* pInput, STextInput
}

// v1 only, map surface to PTI
if(PINPUT->pV1Input) {
wlr_surface* pSurface = wlr_surface_from_resource((wl_resource*)data);
if (PINPUT->pV1Input) {
wlr_surface* pSurface = wlr_surface_from_resource((wl_resource*)data);
PINPUT->focusedSurface = pSurface;
setSurfaceToPTI(pSurface, PINPUT);
if(m_pFocusedSurface == pSurface)
if (m_pFocusedSurface == pSurface)
onTextInputEnter(pSurface);
}

Expand Down Expand Up @@ -474,11 +472,11 @@ void CInputMethodRelay::onKeyboardFocus(wlr_surface* pSurface) {
if (!m_pWLRIME)
return;

if(pSurface == m_pFocusedSurface)
if (pSurface == m_pFocusedSurface)
return;

// say goodbye to the last focused surface
if (STextInput* lastTI = getTextInput(m_pFocusedSurface); lastTI){
if (STextInput* lastTI = getTextInput(m_pFocusedSurface); lastTI) {
wlr_input_method_v2_send_deactivate(m_pWLRIME);
commitIMEState(lastTI);
onTextInputLeave(m_pFocusedSurface);
Expand All @@ -492,20 +490,19 @@ void CInputMethodRelay::onKeyboardFocus(wlr_surface* pSurface) {
* POSSIBLE BUG here: if one client has multiple STextInput and multiple surfaces, for any pSurface we can only record the last found ti.
* since original code has the same problem, it may not be a big deal.
*/
if(getTextInputVersion(wl_resource_get_client(pSurface->resource)) == 3){
if (!getTextInput(pSurface)){
if (getTextInputVersion(wl_resource_get_client(pSurface->resource)) == 3) {
if (!getTextInput(pSurface)) {
auto client = [](STextInput* pTI) -> wl_client* { return pTI->pWlrInput ? wl_resource_get_client(pTI->pWlrInput->resource) : pTI->pV1Input->client; };
for (auto& ti : m_lTextInputs)
if (client(&ti) == wl_resource_get_client(pSurface->resource) && ti.pWlrInput)
if (client(&ti) == wl_resource_get_client(pSurface->resource) && ti.pWlrInput)
setSurfaceToPTI(pSurface, &ti);
}
}

onTextInputEnter(m_pFocusedSurface);
}


void CInputMethodRelay::onTextInputLeave(wlr_surface *pSurface){
void CInputMethodRelay::onTextInputLeave(wlr_surface* pSurface) {
if (!pSurface)
return;

Expand All @@ -522,7 +519,7 @@ void CInputMethodRelay::onKeyboardFocus(wlr_surface* pSurface) {
}
}

void CInputMethodRelay::onTextInputEnter(wlr_surface *pSurface){
void CInputMethodRelay::onTextInputEnter(wlr_surface* pSurface) {
if (!pSurface)
return;

Expand All @@ -539,23 +536,21 @@ void CInputMethodRelay::onTextInputEnter(wlr_surface *pSurface){
}
}

void CInputMethodRelay::setSurfaceToPTI(wlr_surface* pSurface, STextInput* pInput){
if(pSurface){
void CInputMethodRelay::setSurfaceToPTI(wlr_surface* pSurface, STextInput* pInput) {
if (pSurface) {
m_mSurfaceToTextInput[pSurface] = pInput;
pInput->focusedSurface = pSurface;
pInput->focusedSurface = pSurface;
}
}


void CInputMethodRelay::removeSurfaceToPTI(STextInput* pInput){
if(pInput->focusedSurface){
void CInputMethodRelay::removeSurfaceToPTI(STextInput* pInput) {
if (pInput->focusedSurface) {
m_mSurfaceToTextInput.erase(pInput->focusedSurface);
pInput->focusedSurface = nullptr;
}
}


STextInput* CInputMethodRelay::getTextInput(wlr_surface* pSurface){
STextInput* CInputMethodRelay::getTextInput(wlr_surface* pSurface) {
auto result = m_mSurfaceToTextInput.find(pSurface);
if (result != m_mSurfaceToTextInput.end())
return result->second;
Expand All @@ -564,22 +559,22 @@ STextInput* CInputMethodRelay::getTextInput(wlr_surface* pSurface){
}

int CInputMethodRelay::setTextInputVersion(wl_client* pClient, int version) {
if(int v = getTextInputVersion(pClient); v != 0 && v != version){
if (int v = getTextInputVersion(pClient); v != 0 && v != version) {
Debug::log(WARN, "Client attempt to register text-input-v{}, but it has already registered text-input-v{}, ignored", version, v);
return 0;
}
m_mClientTextInputVersion.insert({pClient, version});
return 1;
}

int CInputMethodRelay::getTextInputVersion(wl_client* pClient) {
int CInputMethodRelay::getTextInputVersion(wl_client* pClient) {
auto result = m_mClientTextInputVersion.find(pClient);
if (result != m_mClientTextInputVersion.end())
return result->second;

return 0;
}

void CInputMethodRelay::removeTextInputVersion(wl_client* pClient){
void CInputMethodRelay::removeTextInputVersion(wl_client* pClient) {
m_mClientTextInputVersion.erase(pClient);
}
31 changes: 13 additions & 18 deletions src/managers/input/InputMethodRelay.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class CInputMethodRelay {

STextInput* getFocusedTextInput();


SIMEKbGrab* getIMEKeyboardGrab(SKeyboard*);

void setIMEPopupFocus(SIMEPopup*, wlr_surface*);
Expand All @@ -42,26 +41,22 @@ class CInputMethodRelay {
DYNLISTENER(IMEGrab);
DYNLISTENER(IMENewPopup);

void createNewTextInput(wlr_text_input_v3*, STextInputV1* tiv1 = nullptr);
void createNewTextInput(wlr_text_input_v3*, STextInputV1* tiv1 = nullptr);

wlr_surface* focusedSurface(STextInput* pInput);
wlr_surface* m_pFocusedSurface;
void onTextInputLeave(wlr_surface* pSurface);
void onTextInputEnter(wlr_surface* pSurface);
wlr_surface* focusedSurface(STextInput* pInput);
wlr_surface* m_pFocusedSurface;
void onTextInputLeave(wlr_surface* pSurface);
void onTextInputEnter(wlr_surface* pSurface);

std::unordered_map<wlr_surface*, STextInput*> m_mSurfaceToTextInput;
void setSurfaceToPTI(wlr_surface* pSurface,STextInput* pInput);
STextInput* getTextInput(wlr_surface* pSurface);
void removeSurfaceToPTI(STextInput* pInput);

std::unordered_map<wl_client*, int> m_mClientTextInputVersion;
int setTextInputVersion(wl_client* pClient, int version);
int getTextInputVersion(wl_client* pClient);
void removeTextInputVersion(wl_client* pClient);




void setSurfaceToPTI(wlr_surface* pSurface, STextInput* pInput);
STextInput* getTextInput(wlr_surface* pSurface);
void removeSurfaceToPTI(STextInput* pInput);

std::unordered_map<wl_client*, int> m_mClientTextInputVersion;
int setTextInputVersion(wl_client* pClient, int version);
int getTextInputVersion(wl_client* pClient);
void removeTextInputVersion(wl_client* pClient);

friend class CHyprRenderer;
friend class CInputManager;
Expand Down
2 changes: 1 addition & 1 deletion src/protocols/TextInputV1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ void CTextInputV1ProtocolManager::createTI(wl_client* client, wl_resource* resou

void CTextInputV1ProtocolManager::handleActivate(wl_client* client, wl_resource* resource, wl_resource* seat, wl_resource* surface) {
const auto PTI = tiFromResource(resource);
if(!surface){
if (!surface) {
Debug::log(WARN, "Text-input-v1 PTI{:x}: No surface to activate text input on!", (uintptr_t)PTI);
return;
}
Expand Down

0 comments on commit 01f26f6

Please sign in to comment.