Skip to content

Commit

Permalink
IME: fix IME popup mouse inputs (again)
Browse files Browse the repository at this point in the history
`lastBoxLocal`'s size should be the actual popup's size instead of the cursor
rectangle's size. Also, the rectangle position is now relative to the popup.
(Actually fixes #5255 imho.)

One thing #3922 missed was handling focus held by buttons. Let's hope I get
it right this time.
  • Loading branch information
MikeWalrus committed Apr 7, 2024
1 parent fbdaf74 commit 3edb182
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 41 deletions.
34 changes: 17 additions & 17 deletions src/managers/input/InputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,26 +171,26 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
updateDragIcon();

if (!m_sDrag.drag && !m_lCurrentlyHeldButtons.empty() && g_pCompositor->m_pLastFocus && m_pLastMouseSurface) {
if (m_bLastFocusOnLS) {
foundSurface = m_pLastMouseSurface;
pFoundLayerSurface = g_pCompositor->getLayerSurfaceFromSurface(foundSurface);
if (pFoundLayerSurface) {
surfacePos = g_pCompositor->getLayerSurfaceFromSurface(foundSurface)->position;
foundSurface = m_pLastMouseSurface;
pFoundLayerSurface = g_pCompositor->getLayerSurfaceFromSurface(foundSurface);
if (pFoundLayerSurface) {
surfacePos = pFoundLayerSurface->position;
m_bFocusHeldByButtons = true;
m_bRefocusHeldByButtons = refocus;
} else {
CInputPopup* foundPopup = m_sIMERelay.popupFromSurface(foundSurface);
if (foundPopup) {
surfacePos = foundPopup->globalBox().pos();
m_bFocusHeldByButtons = true;
m_bRefocusHeldByButtons = refocus;
} else {
// ?
foundSurface = nullptr;
pFoundLayerSurface = nullptr;
}
} else if (g_pCompositor->m_pLastWindow) {
foundSurface = m_pLastMouseSurface;
pFoundWindow = g_pCompositor->m_pLastWindow;

surfaceCoords = g_pCompositor->vectorToSurfaceLocal(mouseCoords, pFoundWindow, foundSurface);
} else if (g_pCompositor->m_pLastWindow) {
foundSurface = m_pLastMouseSurface;
pFoundWindow = g_pCompositor->m_pLastWindow;

m_bFocusHeldByButtons = true;
m_bRefocusHeldByButtons = refocus;
surfaceCoords = g_pCompositor->vectorToSurfaceLocal(mouseCoords, pFoundWindow, foundSurface);
m_bFocusHeldByButtons = true;
m_bRefocusHeldByButtons = refocus;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/managers/input/InputManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ class CInputManager {
// for some bugs in follow mouse 0
bool m_bLastFocusOnLS = false;

bool m_bLastFocusOnIMEPopup = false;

// for hiding cursor on touch
bool m_bLastInputTouch = false;

Expand Down
45 changes: 23 additions & 22 deletions src/managers/input/InputMethodPopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,8 @@ void CInputPopup::damageEntire() {
Debug::log(ERR, "BUG THIS: No owner in imepopup::damageentire");
return;
}

Vector2D pos = OWNER->getSurfaceBoxGlobal().value_or(CBox{0, 0, 0, 0}).pos() + lastBoxLocal.pos();
CBox global = {pos, lastPopupSize};

g_pHyprRenderer->damageBox(&global);
CBox box = globalBox();
g_pHyprRenderer->damageBox(&box);
}

void CInputPopup::damageSurface() {
Expand All @@ -98,7 +95,7 @@ void CInputPopup::damageSurface() {
return;
}

Vector2D pos = OWNER->getSurfaceBoxGlobal().value_or(CBox{0, 0, 0, 0}).pos() + lastBoxLocal.pos();
Vector2D pos = globalBox().pos();
g_pHyprRenderer->damageSurface(surface.wlr(), pos.x, pos.y);
}

Expand All @@ -112,8 +109,8 @@ void CInputPopup::updateBox() {
if (!PFOCUSEDTI)
return;

bool cursorRect = PFOCUSEDTI->hasCursorRectangle();
CBox cursorBoxLocal = PFOCUSEDTI->cursorBox();
bool cursorRect = PFOCUSEDTI->hasCursorRectangle();
CBox cursorBoxParent = PFOCUSEDTI->cursorBox();

CBox parentBox;

Expand All @@ -125,29 +122,32 @@ void CInputPopup::updateBox() {
if (!cursorRect) {
Vector2D coords = OWNER ? OWNER->getSurfaceBoxGlobal().value_or(CBox{0, 0, 500, 500}).pos() : Vector2D{0, 0};
parentBox = {coords, {500, 500}};
cursorBoxLocal = {0, 0, (int)parentBox.w, (int)parentBox.h};
cursorBoxParent = {0, 0, (int)parentBox.w, (int)parentBox.h};
}

Vector2D currentPopupSize = surface.getViewporterCorrectedSize();

if (cursorBoxLocal != lastBoxLocal || currentPopupSize != lastPopupSize)
damageEntire();
Vector2D currentPopupSize = surface.getViewporterCorrectedSize();

CMonitor* pMonitor = g_pCompositor->getMonitorFromVector(parentBox.middle());

if (cursorBoxLocal.y + parentBox.y + currentPopupSize.y + cursorBoxLocal.height > pMonitor->vecPosition.y + pMonitor->vecSize.y)
cursorBoxLocal.y -= currentPopupSize.y;
else
cursorBoxLocal.y += cursorBoxLocal.height;
Vector2D popupOffset(0, 0);

if (cursorBoxLocal.x + parentBox.x + currentPopupSize.x > pMonitor->vecPosition.x + pMonitor->vecSize.x)
cursorBoxLocal.x -= (cursorBoxLocal.x + parentBox.x + currentPopupSize.x) - (pMonitor->vecPosition.x + pMonitor->vecSize.x);
if (parentBox.y + cursorBoxParent.y + cursorBoxParent.height + currentPopupSize.y > pMonitor->vecPosition.y + pMonitor->vecSize.y)
popupOffset.y = -currentPopupSize.y;
else
popupOffset.y = cursorBoxParent.height;

lastBoxLocal = cursorBoxLocal;
lastPopupSize = currentPopupSize;
double popupOverflow = parentBox.x + cursorBoxParent.x + currentPopupSize.x - (pMonitor->vecPosition.x + pMonitor->vecSize.x);
if (popupOverflow > 0)
popupOffset.x -= popupOverflow;

CBox cursorBoxLocal({-popupOffset.x, -popupOffset.y}, cursorBoxParent.size());
wlr_input_popup_surface_v2_send_text_input_rectangle(pWlr, cursorBoxLocal.pWlr());

CBox popupBoxParent(cursorBoxParent.pos() + popupOffset, currentPopupSize);
if (popupBoxParent != lastBoxLocal) {
damageEntire();
lastBoxLocal = popupBoxParent;
}
damageSurface();

if (const auto PM = g_pCompositor->getMonitorFromCursor(); PM && PM->ID != lastMonitor) {
Expand All @@ -169,8 +169,9 @@ CBox CInputPopup::globalBox() {
Debug::log(ERR, "BUG THIS: No owner in imepopup::globalbox");
return {};
}
CBox parentBox = OWNER->getSurfaceBoxGlobal().value_or(CBox{0, 0, 500, 500});

return lastBoxLocal.copy().translate(OWNER->getSurfaceBoxGlobal().value_or(CBox{0, 0, 0, 0}).pos());
return lastBoxLocal.copy().translate(parentBox.pos());
}

bool CInputPopup::isVecInPopup(const Vector2D& point) {
Expand Down
3 changes: 1 addition & 2 deletions src/managers/input/InputMethodPopup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,10 @@ class CInputPopup {
wlr_input_popup_surface_v2* pWlr = nullptr;
CWLSurface surface;
CBox lastBoxLocal;
Vector2D lastPopupSize;
uint64_t lastMonitor = -1;

DYNLISTENER(mapPopup);
DYNLISTENER(unmapPopup);
DYNLISTENER(destroyPopup);
DYNLISTENER(commitPopup);
};
};
9 changes: 9 additions & 0 deletions src/managers/input/InputMethodRelay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,12 @@ CInputPopup* CInputMethodRelay::popupFromCoords(const Vector2D& point) {

return nullptr;
}

CInputPopup* CInputMethodRelay::popupFromSurface(const wlr_surface* surface) {
for (auto& p : m_vIMEPopups) {
if (p->getWlrSurface() == surface)
return p.get();
}

return nullptr;
}
1 change: 1 addition & 0 deletions src/managers/input/InputMethodRelay.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class CInputMethodRelay {
void removePopup(CInputPopup*);

CInputPopup* popupFromCoords(const Vector2D& point);
CInputPopup* popupFromSurface(const wlr_surface* surface);

void updateAllPopups();

Expand Down

0 comments on commit 3edb182

Please sign in to comment.