Fixed XWayland (GTK/?) popups focus

This commit is contained in:
vaxerski 2022-04-01 23:11:09 +02:00
parent a64943fd12
commit cd62eb5624
3 changed files with 39 additions and 13 deletions

View file

@ -289,6 +289,34 @@ CWindow* CCompositor::vectorToWindowIdeal(const Vector2D& pos) {
return nullptr; return nullptr;
} }
CWindow* CCompositor::vectorToWindowIdealExcludeWithSurface(const Vector2D& pos, CWindow* pWindow, wlr_surface** ppSurface) {
const auto PMONITOR = getMonitorFromVector(pos);
// first loop over floating cuz they're above
// TODO: make an actual Z-system
for (auto& w : m_lWindows) {
wlr_box box = {w.m_vRealPosition.x, w.m_vRealPosition.y, w.m_vRealSize.x, w.m_vRealSize.y};
if (&w != pWindow && w.m_bIsFloating && w.m_bIsMapped && wlr_box_contains_point(&box, m_sWLRCursor->x, m_sWLRCursor->y) && isWorkspaceVisible(w.m_iWorkspaceID)) {
double sx, sy;
if (ppSurface)
*ppSurface = wlr_surface_surface_at(g_pXWaylandManager->getWindowSurface(&w), pos.x - w.m_vRealPosition.x, pos.y - w.m_vRealPosition.y, &sx, &sy);
return &w;
}
}
for (auto& w : m_lWindows) {
wlr_box box = {w.m_vPosition.x, w.m_vPosition.y, w.m_vSize.x, w.m_vSize.y};
if (&w != pWindow && !w.m_bIsFloating && w.m_bIsMapped && wlr_box_contains_point(&box, pos.x, pos.y) && w.m_iWorkspaceID == PMONITOR->activeWorkspace){
double sx, sy;
if (ppSurface)
*ppSurface = wlr_surface_surface_at(g_pXWaylandManager->getWindowSurface(&w), pos.x - w.m_vRealPosition.x, pos.y - w.m_vRealPosition.y, &sx, &sy);
return &w;
}
}
return nullptr;
}
CWindow* CCompositor::windowFromCursor() { CWindow* CCompositor::windowFromCursor() {
const auto PMONITOR = getMonitorFromCursor(); const auto PMONITOR = getMonitorFromCursor();
@ -342,16 +370,17 @@ void CCompositor::focusWindow(CWindow* pWindow) {
} }
void CCompositor::focusSurface(wlr_surface* pSurface) { void CCompositor::focusSurface(wlr_surface* pSurface) {
if (m_sSeat.seat->keyboard_state.focused_surface == pSurface) if (m_pLastFocus == pSurface)
return; // Don't focus when already focused on this. return; // Don't focus when already focused on this.
if (!pSurface) if (!pSurface)
return; return;
// Unfocus last surface if should // Unfocus last surface if should
const auto PWINDOWATCURSOR = vectorToWindowIdeal(g_pInputManager->getMouseCoordsInternal()); if (m_pLastFocus && !wlr_surface_is_xwayland_surface(pSurface)) {
if (m_pLastFocus && !(PWINDOWATCURSOR && g_pXWaylandManager->getWindowSurface(PWINDOWATCURSOR) == m_pLastFocus))
g_pXWaylandManager->activateSurface(m_pLastFocus, false); g_pXWaylandManager->activateSurface(m_pLastFocus, false);
Debug::log(LOG, "Last focus %x deactivated", m_pLastFocus);
}
const auto KEYBOARD = wlr_seat_get_keyboard(m_sSeat.seat); const auto KEYBOARD = wlr_seat_get_keyboard(m_sSeat.seat);
@ -365,9 +394,9 @@ void CCompositor::focusSurface(wlr_surface* pSurface) {
g_pXWaylandManager->activateSurface(pSurface, true); g_pXWaylandManager->activateSurface(pSurface, true);
if (const auto PWINDOW = getWindowFromSurface(pSurface); PWINDOW) if (const auto PWINDOW = getWindowFromSurface(pSurface); PWINDOW)
Debug::log(LOG, "Set keyboard focus to surface %x, with window name: %s", pSurface, PWINDOW->m_szTitle.c_str()); Debug::log(LOG, "Set keyboard focus to surface %x, with window name: %s (%dx%d)", pSurface, PWINDOW->m_szTitle.c_str(), pSurface->current.width, pSurface->current.height);
else else
Debug::log(LOG, "Set keyboard focus to surface %x", pSurface); Debug::log(LOG, "Set keyboard focus to surface %x (%dx%d)", pSurface, pSurface->current.width, pSurface->current.height);
} }
bool CCompositor::windowValidMapped(CWindow* pWindow) { bool CCompositor::windowValidMapped(CWindow* pWindow) {

View file

@ -76,6 +76,7 @@ public:
bool windowValidMapped(CWindow*); bool windowValidMapped(CWindow*);
CWindow* vectorToWindow(const Vector2D&); CWindow* vectorToWindow(const Vector2D&);
CWindow* vectorToWindowIdeal(const Vector2D&); CWindow* vectorToWindowIdeal(const Vector2D&);
CWindow* vectorToWindowIdealExcludeWithSurface(const Vector2D&, CWindow*, wlr_surface**);
CWindow* vectorToWindowTiled(const Vector2D&); CWindow* vectorToWindowTiled(const Vector2D&);
wlr_surface* vectorToLayerSurface(const Vector2D&, std::list<SLayerSurface*>*, Vector2D*); wlr_surface* vectorToLayerSurface(const Vector2D&, std::list<SLayerSurface*>*, Vector2D*);
CWindow* windowFromCursor(); CWindow* windowFromCursor();

View file

@ -23,7 +23,6 @@ void CInputManager::mouseMoveUnified(uint32_t time) {
// update stuff // update stuff
updateDragIcon(); updateDragIcon();
// focus // focus
wlr_surface* foundSurface = nullptr; wlr_surface* foundSurface = nullptr;
Vector2D mouseCoords = getMouseCoordsInternal(); Vector2D mouseCoords = getMouseCoordsInternal();
@ -66,10 +65,9 @@ void CInputManager::mouseMoveUnified(uint32_t time) {
foundSurface = g_pCompositor->vectorToLayerSurface(mouseCoords, &PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_TOP], &surfaceCoords); foundSurface = g_pCompositor->vectorToLayerSurface(mouseCoords, &PMONITOR->m_aLayerSurfaceLists[ZWLR_LAYER_SHELL_V1_LAYER_TOP], &surfaceCoords);
// then windows // then windows
const auto PWINDOWIDEAL = g_pCompositor->vectorToWindowIdeal(mouseCoords); const auto PWINDOWIDEAL = g_pCompositor->vectorToWindowIdealExcludeWithSurface(mouseCoords, nullptr, &foundSurface);
if (!foundSurface && PWINDOWIDEAL) {
foundSurface = g_pXWaylandManager->getWindowSurface(PWINDOWIDEAL); if (foundSurface && PWINDOWIDEAL) {
if (foundSurface)
surfacePos = PWINDOWIDEAL->m_vRealPosition; surfacePos = PWINDOWIDEAL->m_vRealPosition;
} }
@ -124,8 +122,6 @@ void CInputManager::onMouseButton(wlr_pointer_button_event* e) {
break; break;
} }
refocus();
// notify app if we didnt handle it // notify app if we didnt handle it
if (g_pCompositor->doesSeatAcceptInput(g_pCompositor->m_pLastFocus)) { if (g_pCompositor->doesSeatAcceptInput(g_pCompositor->m_pLastFocus)) {
wlr_seat_pointer_notify_button(g_pCompositor->m_sSeat.seat, e->time_msec, e->button, e->state); wlr_seat_pointer_notify_button(g_pCompositor->m_sSeat.seat, e->time_msec, e->button, e->state);