mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-26 12:45: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();
|
updateDragIcon();
|
||||||
|
|
||||||
if (!m_sDrag.drag && !m_lCurrentlyHeldButtons.empty() && g_pCompositor->m_pLastFocus && m_pLastMouseSurface) {
|
if (!m_sDrag.drag && !m_lCurrentlyHeldButtons.empty() && g_pCompositor->m_pLastFocus && m_pLastMouseSurface) {
|
||||||
if (m_bLastFocusOnLS) {
|
foundSurface = m_pLastMouseSurface;
|
||||||
foundSurface = m_pLastMouseSurface;
|
pFoundLayerSurface = g_pCompositor->getLayerSurfaceFromSurface(foundSurface);
|
||||||
pFoundLayerSurface = g_pCompositor->getLayerSurfaceFromSurface(foundSurface);
|
if (pFoundLayerSurface) {
|
||||||
if (pFoundLayerSurface) {
|
surfacePos = pFoundLayerSurface->position;
|
||||||
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);
|
|
||||||
|
|
||||||
m_bFocusHeldByButtons = true;
|
m_bFocusHeldByButtons = true;
|
||||||
m_bRefocusHeldByButtons = refocus;
|
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
|
// for some bugs in follow mouse 0
|
||||||
bool m_bLastFocusOnLS = false;
|
bool m_bLastFocusOnLS = false;
|
||||||
|
|
||||||
|
bool m_bLastFocusOnIMEPopup = false;
|
||||||
|
|
||||||
// for hiding cursor on touch
|
// for hiding cursor on touch
|
||||||
bool m_bLastInputTouch = false;
|
bool m_bLastInputTouch = false;
|
||||||
|
|
||||||
|
|
|
@ -83,11 +83,8 @@ void CInputPopup::damageEntire() {
|
||||||
Debug::log(ERR, "BUG THIS: No owner in imepopup::damageentire");
|
Debug::log(ERR, "BUG THIS: No owner in imepopup::damageentire");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
CBox box = globalBox();
|
||||||
Vector2D pos = OWNER->getSurfaceBoxGlobal().value_or(CBox{0, 0, 0, 0}).pos() + lastBoxLocal.pos();
|
g_pHyprRenderer->damageBox(&box);
|
||||||
CBox global = {pos, lastPopupSize};
|
|
||||||
|
|
||||||
g_pHyprRenderer->damageBox(&global);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CInputPopup::damageSurface() {
|
void CInputPopup::damageSurface() {
|
||||||
|
@ -98,7 +95,7 @@ void CInputPopup::damageSurface() {
|
||||||
return;
|
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);
|
g_pHyprRenderer->damageSurface(surface.wlr(), pos.x, pos.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,8 +109,8 @@ void CInputPopup::updateBox() {
|
||||||
if (!PFOCUSEDTI)
|
if (!PFOCUSEDTI)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bool cursorRect = PFOCUSEDTI->hasCursorRectangle();
|
bool cursorRect = PFOCUSEDTI->hasCursorRectangle();
|
||||||
CBox cursorBoxLocal = PFOCUSEDTI->cursorBox();
|
CBox cursorBoxParent = PFOCUSEDTI->cursorBox();
|
||||||
|
|
||||||
CBox parentBox;
|
CBox parentBox;
|
||||||
|
|
||||||
|
@ -125,29 +122,32 @@ void CInputPopup::updateBox() {
|
||||||
if (!cursorRect) {
|
if (!cursorRect) {
|
||||||
Vector2D coords = OWNER ? OWNER->getSurfaceBoxGlobal().value_or(CBox{0, 0, 500, 500}).pos() : Vector2D{0, 0};
|
Vector2D coords = OWNER ? OWNER->getSurfaceBoxGlobal().value_or(CBox{0, 0, 500, 500}).pos() : Vector2D{0, 0};
|
||||||
parentBox = {coords, {500, 500}};
|
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();
|
Vector2D currentPopupSize = surface.getViewporterCorrectedSize();
|
||||||
|
|
||||||
if (cursorBoxLocal != lastBoxLocal || currentPopupSize != lastPopupSize)
|
|
||||||
damageEntire();
|
|
||||||
|
|
||||||
CMonitor* pMonitor = g_pCompositor->getMonitorFromVector(parentBox.middle());
|
CMonitor* pMonitor = g_pCompositor->getMonitorFromVector(parentBox.middle());
|
||||||
|
|
||||||
if (cursorBoxLocal.y + parentBox.y + currentPopupSize.y + cursorBoxLocal.height > pMonitor->vecPosition.y + pMonitor->vecSize.y)
|
Vector2D popupOffset(0, 0);
|
||||||
cursorBoxLocal.y -= currentPopupSize.y;
|
|
||||||
|
if (parentBox.y + cursorBoxParent.y + cursorBoxParent.height + currentPopupSize.y > pMonitor->vecPosition.y + pMonitor->vecSize.y)
|
||||||
|
popupOffset.y = -currentPopupSize.y;
|
||||||
else
|
else
|
||||||
cursorBoxLocal.y += cursorBoxLocal.height;
|
popupOffset.y = cursorBoxParent.height;
|
||||||
|
|
||||||
if (cursorBoxLocal.x + parentBox.x + currentPopupSize.x > pMonitor->vecPosition.x + pMonitor->vecSize.x)
|
double popupOverflow = parentBox.x + cursorBoxParent.x + currentPopupSize.x - (pMonitor->vecPosition.x + pMonitor->vecSize.x);
|
||||||
cursorBoxLocal.x -= (cursorBoxLocal.x + parentBox.x + currentPopupSize.x) - (pMonitor->vecPosition.x + pMonitor->vecSize.x);
|
if (popupOverflow > 0)
|
||||||
|
popupOffset.x -= popupOverflow;
|
||||||
lastBoxLocal = cursorBoxLocal;
|
|
||||||
lastPopupSize = currentPopupSize;
|
|
||||||
|
|
||||||
|
CBox cursorBoxLocal({-popupOffset.x, -popupOffset.y}, cursorBoxParent.size());
|
||||||
wlr_input_popup_surface_v2_send_text_input_rectangle(pWlr, cursorBoxLocal.pWlr());
|
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();
|
damageSurface();
|
||||||
|
|
||||||
if (const auto PM = g_pCompositor->getMonitorFromCursor(); PM && PM->ID != lastMonitor) {
|
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");
|
Debug::log(ERR, "BUG THIS: No owner in imepopup::globalbox");
|
||||||
return {};
|
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) {
|
bool CInputPopup::isVecInPopup(const Vector2D& point) {
|
||||||
|
|
|
@ -32,7 +32,6 @@ class CInputPopup {
|
||||||
wlr_input_popup_surface_v2* pWlr = nullptr;
|
wlr_input_popup_surface_v2* pWlr = nullptr;
|
||||||
CWLSurface surface;
|
CWLSurface surface;
|
||||||
CBox lastBoxLocal;
|
CBox lastBoxLocal;
|
||||||
Vector2D lastPopupSize;
|
|
||||||
uint64_t lastMonitor = -1;
|
uint64_t lastMonitor = -1;
|
||||||
|
|
||||||
DYNLISTENER(mapPopup);
|
DYNLISTENER(mapPopup);
|
||||||
|
|
|
@ -221,3 +221,12 @@ CInputPopup* CInputMethodRelay::popupFromCoords(const Vector2D& point) {
|
||||||
|
|
||||||
return nullptr;
|
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*);
|
void removePopup(CInputPopup*);
|
||||||
|
|
||||||
CInputPopup* popupFromCoords(const Vector2D& point);
|
CInputPopup* popupFromCoords(const Vector2D& point);
|
||||||
|
CInputPopup* popupFromSurface(const wlr_surface* surface);
|
||||||
|
|
||||||
void updateAllPopups();
|
void updateAllPopups();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue