mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-07 04:25:59 +01:00
IME: fix IME popup mouse inputs (again) (#5417)
`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.
This commit is contained in:
parent
f2a848cbcc
commit
d657b59f70
6 changed files with 54 additions and 42 deletions
|
@ -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;
|
||||
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);
|
||||
|
||||
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 if (g_pCompositor->m_pLastWindow) {
|
||||
foundSurface = m_pLastMouseSurface;
|
||||
pFoundWindow = g_pCompositor->m_pLastWindow;
|
||||
|
||||
surfaceCoords = g_pCompositor->vectorToSurfaceLocal(mouseCoords, pFoundWindow, foundSurface);
|
||||
m_bFocusHeldByButtons = true;
|
||||
m_bRefocusHeldByButtons = refocus;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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() {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
Vector2D popupOffset(0, 0);
|
||||
|
||||
if (parentBox.y + cursorBoxParent.y + cursorBoxParent.height + currentPopupSize.y > pMonitor->vecPosition.y + pMonitor->vecSize.y)
|
||||
popupOffset.y = -currentPopupSize.y;
|
||||
else
|
||||
cursorBoxLocal.y += cursorBoxLocal.height;
|
||||
popupOffset.y = cursorBoxParent.height;
|
||||
|
||||
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);
|
||||
|
||||
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) {
|
||||
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -221,3 +221,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;
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ class CInputMethodRelay {
|
|||
void removePopup(CInputPopup*);
|
||||
|
||||
CInputPopup* popupFromCoords(const Vector2D& point);
|
||||
CInputPopup* popupFromSurface(const wlr_surface* surface);
|
||||
|
||||
void updateAllPopups();
|
||||
|
||||
|
|
Loading…
Reference in a new issue