diff options
| author | vaxerski <43317083+vaxerski@users.noreply.github.com> | 2022-03-27 17:25:20 +0200 |
|---|---|---|
| committer | vaxerski <43317083+vaxerski@users.noreply.github.com> | 2022-03-27 17:25:20 +0200 |
| commit | ad36a9dc9ed032e6e34c06f78995bca0045f85b0 (patch) | |
| tree | 933cfc71255a9cfbe1211f187d7d101a4e30ffc8 /src/events | |
| parent | 4c3b9ae207967bf06b973cc6b49db58887f1af6b (diff) | |
rework popups completely
Diffstat (limited to 'src/events')
| -rw-r--r-- | src/events/Events.hpp | 18 | ||||
| -rw-r--r-- | src/events/Layers.cpp | 81 | ||||
| -rw-r--r-- | src/events/Popups.cpp | 163 | ||||
| -rw-r--r-- | src/events/Windows.cpp | 55 |
4 files changed, 85 insertions, 232 deletions
diff --git a/src/events/Events.hpp b/src/events/Events.hpp index b7fac9d6..bcd3d87b 100644 --- a/src/events/Events.hpp +++ b/src/events/Events.hpp @@ -1,6 +1,12 @@ #pragma once #include "../defines.hpp" +// +// LISTEN_NAME -> the wl_listener +// +// LISTENER_NAME -> the wl_listener.notify function +// + namespace Events { // Monitor events LISTENER(change); @@ -14,19 +20,15 @@ namespace Events { LISTENER(commitLayerSurface); // Subsurfaces - LISTENER(newSubsurface); + LISTENER(newSubsurfaceNode); + LISTENER(destroySubsurfaceNode); LISTENER(mapSubsurface); LISTENER(unmapSubsurface); LISTENER(destroySubsurface); LISTENER(commitSubsurface); // Popups - LISTENER(newPopup); - LISTENER(newPopupFromPopup); - LISTENER(mapPopup); - LISTENER(unmapPopup); - LISTENER(destroyPopup); - LISTENER(commitPopup); + LISTENER(newPopup); // LayerSurface LISTENER(newPopupXDG); LISTENER(mapPopupXDG); @@ -49,7 +51,7 @@ namespace Events { LISTENER(configureX11); // Window subsurfaces - LISTENER(newSubsurfaceWindow); + // LISTENER(newSubsurfaceWindow); // Input events LISTENER(mouseMove); diff --git a/src/events/Layers.cpp b/src/events/Layers.cpp index 6b4f0a1a..4fc9848f 100644 --- a/src/events/Layers.cpp +++ b/src/events/Layers.cpp @@ -44,7 +44,6 @@ void Events::listener_newLayerSurface(wl_listener* listener, void* data) { wl_signal_add(&WLRLAYERSURFACE->events.map, &layerSurface->listen_mapLayerSurface); wl_signal_add(&WLRLAYERSURFACE->events.unmap, &layerSurface->listen_unmapLayerSurface); wl_signal_add(&WLRLAYERSURFACE->events.new_popup, &layerSurface->listen_newPopup); - wl_signal_add(&WLRLAYERSURFACE->surface->events.new_subsurface, &layerSurface->listen_newSubsurface); layerSurface->layerSurface = WLRLAYERSURFACE; layerSurface->layer = WLRLAYERSURFACE->current.layer; @@ -108,6 +107,8 @@ void Events::listener_mapLayerSurface(wl_listener* listener, void* data) { if (layersurface->layerSurface->current.keyboard_interactive) g_pCompositor->focusSurface(layersurface->layerSurface->surface); + + layersurface->position = Vector2D(layersurface->geometry.x, layersurface->geometry.y); } void Events::listener_unmapLayerSurface(wl_listener* listener, void* data) { @@ -152,82 +153,6 @@ void Events::listener_commitLayerSurface(wl_listener* listener, void* data) { } g_pLayoutManager->getCurrentLayout()->recalculateMonitor(PMONITOR->ID); -} - -// -// Subsurfaces -// - -void createSubsurface(wlr_subsurface* pSubSurface, SLayerSurface* pLayerSurface) { - if (!pSubSurface || !pLayerSurface) - return; - - Debug::log(LOG, "Subsurface %x created", pSubSurface); - - g_pCompositor->m_lSubsurfaces.push_back(SSubsurface()); - const auto PNEWSUBSURFACE = &g_pCompositor->m_lSubsurfaces.back(); - - PNEWSUBSURFACE->subsurface = pSubSurface; - PNEWSUBSURFACE->pParentSurface = pLayerSurface; - - wl_signal_add(&pSubSurface->events.map, &PNEWSUBSURFACE->listen_mapSubsurface); - wl_signal_add(&pSubSurface->events.unmap, &PNEWSUBSURFACE->listen_unmapSubsurface); - wl_signal_add(&pSubSurface->events.destroy, &PNEWSUBSURFACE->listen_destroySubsurface); - wl_signal_add(&pSubSurface->surface->events.commit, &PNEWSUBSURFACE->listen_commitSubsurface); -} - -void damageSubsurface(SSubsurface* subSurface, bool all = false) { - if (!subSurface->pParentSurface->layerSurface->output) - return; - - const auto PMONITOR = g_pCompositor->getMonitorFromOutput(subSurface->pParentSurface->layerSurface->output); - - if (!PMONITOR) - return; // wut? - - int x = subSurface->subsurface->current.x + subSurface->pParentSurface->geometry.x; - int y = subSurface->subsurface->current.y + subSurface->pParentSurface->geometry.y; - - g_pHyprRenderer->damageSurface(PMONITOR, x, y, subSurface->subsurface->surface, &all); -} - -void Events::listener_newSubsurface(wl_listener* listener, void* data) { - SLayerSurface* layersurface = wl_container_of(listener, layersurface, listen_newSubsurface); - - createSubsurface((wlr_subsurface*)data, layersurface); -} - -void Events::listener_mapSubsurface(wl_listener* listener, void* data) { - SSubsurface* subsurface = wl_container_of(listener, subsurface, listen_mapSubsurface); - - Debug::log(LOG, "Subsurface %x mapped", subsurface); - - damageSubsurface(subsurface, true); -} - -void Events::listener_unmapSubsurface(wl_listener* listener, void* data) { - SSubsurface* subsurface = wl_container_of(listener, subsurface, listen_unmapSubsurface); - - Debug::log(LOG, "Subsurface %x unmapped", subsurface); - - damageSubsurface(subsurface, true); -} - -void Events::listener_commitSubsurface(wl_listener* listener, void* data) { - SSubsurface* subsurface = wl_container_of(listener, subsurface, listen_commitSubsurface); - - damageSubsurface(subsurface, false); -} - -void Events::listener_destroySubsurface(wl_listener* listener, void* data) { - SSubsurface* subsurface = wl_container_of(listener, subsurface, listen_destroySubsurface); - - Debug::log(LOG, "Subsurface %x destroyed", subsurface); - - wl_list_remove(&subsurface->listen_mapSubsurface.link); - wl_list_remove(&subsurface->listen_unmapSubsurface.link); - wl_list_remove(&subsurface->listen_destroySubsurface.link); - wl_list_remove(&subsurface->listen_commitSubsurface.link); - g_pCompositor->m_lSubsurfaces.remove(*subsurface); + layersurface->position = Vector2D(layersurface->geometry.x, layersurface->geometry.y); }
\ No newline at end of file diff --git a/src/events/Popups.cpp b/src/events/Popups.cpp index 78d841fe..a85fa4b5 100644 --- a/src/events/Popups.cpp +++ b/src/events/Popups.cpp @@ -15,32 +15,49 @@ // // // --------------------------------------------- // -void createNewPopup(wlr_xdg_popup* popup, void* parent, bool parentIsLayer) { +void addPopupGlobalCoords(void* pPopup, int* x, int* y) { + SXDGPopup *const PPOPUP = (SXDGPopup*)pPopup; + + int px = 0; + int py = 0; + + auto curPopup = PPOPUP; + while (true) { + px += curPopup->popup->geometry.x; + py += curPopup->popup->geometry.y; + + if (curPopup->parentPopup) { + curPopup = curPopup->parentPopup; + } else { + break; + } + } + + px += *PPOPUP->lx; + py += *PPOPUP->ly; - if (!popup) - return; + *x += px; + *y += py; +} - g_pCompositor->m_lLayerPopups.push_back(SLayerPopup()); - const auto PNEWPOPUP = &g_pCompositor->m_lLayerPopups.back(); +void createNewPopup(wlr_xdg_popup* popup, SXDGPopup* pHyprPopup) { + pHyprPopup->popup = popup; - PNEWPOPUP->popup = popup; - if (parentIsLayer) - PNEWPOPUP->parentSurface = (SLayerSurface*)parent; - else - PNEWPOPUP->parentPopup = (wlr_xdg_popup*)parent; + pHyprPopup->listen_mapPopupXDG.notify = Events::listener_mapPopupXDG; + pHyprPopup->listen_unmapPopupXDG.notify = Events::listener_unmapPopupXDG; + pHyprPopup->listen_destroyPopupXDG.notify = Events::listener_destroyPopupXDG; + pHyprPopup->listen_newPopupFromPopupXDG.notify = Events::listener_newPopupXDG; - wl_signal_add(&popup->base->events.map, &PNEWPOPUP->listen_mapPopup); - wl_signal_add(&popup->base->events.unmap, &PNEWPOPUP->listen_unmapPopup); - wl_signal_add(&popup->base->events.destroy, &PNEWPOPUP->listen_destroyPopup); - wl_signal_add(&popup->base->events.new_popup, &PNEWPOPUP->listen_newPopupFromPopup); - wl_signal_add(&popup->base->surface->events.commit, &PNEWPOPUP->listen_commitPopup); + wl_signal_add(&popup->base->events.map, &pHyprPopup->listen_mapPopupXDG); + wl_signal_add(&popup->base->events.unmap, &pHyprPopup->listen_unmapPopupXDG); + wl_signal_add(&popup->base->surface->events.destroy, &pHyprPopup->listen_destroyPopupXDG); + wl_signal_add(&popup->base->events.new_popup, &pHyprPopup->listen_newPopupFromPopupXDG); - const auto PLAYER = g_pCompositor->getLayerForPopup(PNEWPOPUP); - const auto PMONITOR = g_pCompositor->getMonitorFromOutput(PLAYER->layerSurface->output); + const auto PMONITOR = g_pCompositor->m_pLastMonitor; wlr_box box = {.x = PMONITOR->vecPosition.x, .y = PMONITOR->vecPosition.y, .width = PMONITOR->vecSize.x, .height = PMONITOR->vecSize.y}; - wlr_xdg_popup_unconstrain_from_box(PNEWPOPUP->popup, &box); + wlr_xdg_popup_unconstrain_from_box(popup, &box); } void Events::listener_newPopup(wl_listener* listener, void* data) { @@ -50,81 +67,13 @@ void Events::listener_newPopup(wl_listener* listener, void* data) { const auto WLRPOPUP = (wlr_xdg_popup*)data; - createNewPopup(WLRPOPUP, layersurface, true); -} - -void Events::listener_newPopupFromPopup(wl_listener* listener, void* data) { - SLayerPopup* layerPopup = wl_container_of(listener, layerPopup, listen_newPopupFromPopup); - - Debug::log(LOG, "New layer popup created from popup %x", layerPopup); - - const auto WLRPOPUP = (wlr_xdg_popup*)data; - - createNewPopup(WLRPOPUP, layerPopup, true); -} - -void Events::listener_destroyPopup(wl_listener* listener, void* data) { - SLayerPopup* layerPopup = wl_container_of(listener, layerPopup, listen_destroyPopup); - - Debug::log(LOG, "Destroyed popup %x", layerPopup); - - wl_list_remove(&layerPopup->listen_mapPopup.link); - wl_list_remove(&layerPopup->listen_unmapPopup.link); - wl_list_remove(&layerPopup->listen_destroyPopup.link); - wl_list_remove(&layerPopup->listen_commitPopup.link); - - g_pCompositor->m_lLayerPopups.remove(*layerPopup); -} - -void Events::listener_mapPopup(wl_listener* listener, void* data) { - SLayerPopup* layerPopup = wl_container_of(listener, layerPopup, listen_mapPopup); - - Debug::log(LOG, "Mapped popup %x", layerPopup); - - const auto PLAYER = g_pCompositor->getLayerForPopup(layerPopup); - - wlr_surface_send_enter(layerPopup->popup->base->surface, PLAYER->layerSurface->output); -} - -void Events::listener_unmapPopup(wl_listener* listener, void* data) { - SLayerPopup* layerPopup = wl_container_of(listener, layerPopup, listen_unmapPopup); - - Debug::log(LOG, "LayerPopup %x unmapped", layerPopup); -} - -void Events::listener_commitPopup(wl_listener* listener, void* data) { - SLayerPopup* layerPopup = wl_container_of(listener, layerPopup, listen_commitPopup); - -} - -void createNewPopupXDG(wlr_xdg_popup* popup, void* parent, bool parentIsWindow) { - if (!popup) - return; - - Debug::log(LOG, "New XDG Popup %x created", popup); - g_pCompositor->m_lXDGPopups.push_back(SXDGPopup()); const auto PNEWPOPUP = &g_pCompositor->m_lXDGPopups.back(); - PNEWPOPUP->popup = popup; - if (parentIsWindow) - PNEWPOPUP->parentWindow = (CWindow*)parent; - else { - PNEWPOPUP->parentPopup = (wlr_xdg_popup*)parent; - PNEWPOPUP->parentWindow = g_pCompositor->getWindowForPopup((wlr_xdg_popup*)parent); - } - - - wl_signal_add(&popup->base->events.map, &PNEWPOPUP->listen_mapPopupXDG); - wl_signal_add(&popup->base->events.unmap, &PNEWPOPUP->listen_unmapPopupXDG); - wl_signal_add(&popup->base->events.destroy, &PNEWPOPUP->listen_destroyPopupXDG); - wl_signal_add(&popup->base->events.new_popup, &PNEWPOPUP->listen_newPopupFromPopupXDG); - - const auto PMONITOR = g_pCompositor->getMonitorFromID(PNEWPOPUP->parentWindow->m_iMonitorID); - - wlr_box box = {.x = PMONITOR->vecPosition.x, .y = PMONITOR->vecPosition.y, .width = PMONITOR->vecSize.x, .height = PMONITOR->vecSize.y}; - - wlr_xdg_popup_unconstrain_from_box(PNEWPOPUP->popup, &box); + PNEWPOPUP->popup = WLRPOPUP; + PNEWPOPUP->lx = &layersurface->position.x; + PNEWPOPUP->ly = &layersurface->position.y; + createNewPopup(WLRPOPUP, PNEWPOPUP); } void Events::listener_newPopupXDG(wl_listener* listener, void* data) { @@ -134,7 +83,13 @@ void Events::listener_newPopupXDG(wl_listener* listener, void* data) { const auto WLRPOPUP = (wlr_xdg_popup*)data; - createNewPopupXDG(WLRPOPUP, PWINDOW, true); + g_pCompositor->m_lXDGPopups.push_back(SXDGPopup()); + const auto PNEWPOPUP = &g_pCompositor->m_lXDGPopups.back(); + + PNEWPOPUP->popup = WLRPOPUP; + PNEWPOPUP->lx = &PWINDOW->m_vEffectivePosition.x; + PNEWPOPUP->ly = &PWINDOW->m_vEffectivePosition.y; + createNewPopup(WLRPOPUP, PNEWPOPUP); } void Events::listener_newPopupFromPopupXDG(wl_listener* listener, void* data) { @@ -144,15 +99,32 @@ void Events::listener_newPopupFromPopupXDG(wl_listener* listener, void* data) { const auto WLRPOPUP = (wlr_xdg_popup*)data; - createNewPopupXDG(WLRPOPUP, PPOPUP, true); + g_pCompositor->m_lXDGPopups.push_back(SXDGPopup()); + const auto PNEWPOPUP = &g_pCompositor->m_lXDGPopups.back(); + + PNEWPOPUP->popup = WLRPOPUP; + PNEWPOPUP->parentPopup = PPOPUP; + PNEWPOPUP->lx = PPOPUP->lx; + PNEWPOPUP->ly = PPOPUP->ly; + + createNewPopup(WLRPOPUP, PNEWPOPUP); } void Events::listener_mapPopupXDG(wl_listener* listener, void* data) { + SXDGPopup* PPOPUP = wl_container_of(listener, PPOPUP, listen_mapPopupXDG); + Debug::log(LOG, "New XDG Popup mapped"); + + PPOPUP->pSurfaceTree = SubsurfaceTree::createTreeRoot(PPOPUP->popup->base->surface, addPopupGlobalCoords, PPOPUP); } void Events::listener_unmapPopupXDG(wl_listener* listener, void* data) { + SXDGPopup* PPOPUP = wl_container_of(listener, PPOPUP, listen_unmapPopupXDG); Debug::log(LOG, "XDG Popup unmapped"); + + SubsurfaceTree::destroySurfaceTree(PPOPUP->pSurfaceTree); + + PPOPUP->pSurfaceTree = nullptr; } void Events::listener_destroyPopupXDG(wl_listener* listener, void* data) { @@ -160,9 +132,10 @@ void Events::listener_destroyPopupXDG(wl_listener* listener, void* data) { Debug::log(LOG, "Destroyed popup XDG %x", PPOPUP); - wl_list_remove(&PPOPUP->listen_mapPopupXDG.link); - wl_list_remove(&PPOPUP->listen_unmapPopupXDG.link); - wl_list_remove(&PPOPUP->listen_destroyPopupXDG.link); + if (PPOPUP->pSurfaceTree) { + SubsurfaceTree::destroySurfaceTree(PPOPUP->pSurfaceTree); + PPOPUP->pSurfaceTree = nullptr; + } g_pCompositor->m_lXDGPopups.remove(*PPOPUP); }
\ No newline at end of file diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 59446df4..217fdf57 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -34,7 +34,7 @@ void Events::listener_mapWindow(wl_listener* listener, void* data) { return; } - wl_signal_add(&PWINDOWSURFACE->events.new_subsurface, &PWINDOW->listen_newSubsurfaceWindow); + // wl_signal_add(&PWINDOWSURFACE->events.new_subsurface, &PWINDOW->listen_newSubsurfaceWindow); if (g_pXWaylandManager->shouldBeFloated(PWINDOW)) PWINDOW->m_bIsFloating = true; @@ -131,11 +131,7 @@ void Events::listener_unmapWindow(wl_listener* listener, void* data) { PWINDOW->m_bIsMapped = false; // refocus on a new window - // TODO: investigate. - // If a parent window has focus, any popups (XWayland) will be broken (they will disappear instantly) - // This might be way more sinister in nature and have a problem more deeply - // rooted in the code. - // g_pInputManager->refocus(); + g_pInputManager->refocus(); } void Events::listener_commitWindow(wl_listener* listener, void* data) { @@ -152,25 +148,8 @@ void Events::listener_destroyWindow(wl_listener* listener, void* data) { if (g_pXWaylandManager->getWindowSurface(PWINDOW) == g_pCompositor->m_pLastFocus) g_pCompositor->m_pLastFocus = nullptr; - // TODO: - // We sometimes get invalid pointers here (stack ones) - // this obviously means we tainted wlroots. - // Investigate - g_pLayoutManager->getCurrentLayout()->onWindowRemoved(PWINDOW); - wl_list_remove(&PWINDOW->listen_mapWindow.link); - wl_list_remove(&PWINDOW->listen_unmapWindow.link); - wl_list_remove(&PWINDOW->listen_destroyWindow.link); - wl_list_remove(&PWINDOW->listen_setTitleWindow.link); - wl_list_remove(&PWINDOW->listen_fullscreenWindow.link); - if (PWINDOW->m_bIsX11) { - wl_list_remove(&PWINDOW->listen_activateX11.link); - wl_list_remove(&PWINDOW->listen_configureX11.link); - } else { - wl_list_remove(&PWINDOW->listen_commitWindow.link); - } - g_pCompositor->removeWindowFromVectorSafe(PWINDOW); } @@ -254,31 +233,5 @@ void Events::listener_newXDGSurface(wl_listener* listener, void* data) { wl_signal_add(&XDGSURFACE->events.destroy, &PNEWWINDOW->listen_destroyWindow); wl_signal_add(&XDGSURFACE->toplevel->events.set_title, &PNEWWINDOW->listen_setTitleWindow); wl_signal_add(&XDGSURFACE->toplevel->events.request_fullscreen, &PNEWWINDOW->listen_fullscreenWindow); -} - -// -// Subsurfaces -// - -void createSubsurface(CWindow* pWindow, wlr_subsurface* pSubsurface) { - if (!pWindow || !pSubsurface) - return; - - Debug::log(LOG, "New Window Subsurface %x created", pSubsurface); - - g_pCompositor->m_lSubsurfaces.push_back(SSubsurface()); - const auto PNEWSUBSURFACE = &g_pCompositor->m_lSubsurfaces.back(); - - wl_signal_add(&pSubsurface->events.destroy, &PNEWSUBSURFACE->listen_destroySubsurface); - wl_signal_add(&pSubsurface->events.map, &PNEWSUBSURFACE->listen_mapSubsurface); - wl_signal_add(&pSubsurface->events.unmap, &PNEWSUBSURFACE->listen_unmapSubsurface); - wl_signal_add(&pSubsurface->surface->events.commit, &PNEWSUBSURFACE->listen_commitSubsurface); -} - -void Events::listener_newSubsurfaceWindow(wl_listener* listener, void* data) { - CWindow* PWINDOW = wl_container_of(listener, PWINDOW, listen_newSubsurfaceWindow); - - const auto PSUBSURFACE = (wlr_subsurface*)data; - - createSubsurface(PWINDOW, PSUBSURFACE); -} + wl_signal_add(&XDGSURFACE->events.new_popup, &PNEWWINDOW->listen_newPopupXDG); +}
\ No newline at end of file |
