From 491b99c61ea19f2e9048f215eace07e126af890b Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Fri, 8 Jul 2022 11:24:07 +0200 Subject: [PATCH] handle unmanaged X11 setGeometry --- src/Window.hpp | 1 + src/events/Events.hpp | 1 + src/events/Popups.cpp | 3 +++ src/events/Windows.cpp | 23 ++++++++++++++++++++++- src/layout/IHyprLayout.cpp | 10 ++++++---- src/managers/AnimationManager.cpp | 2 +- 6 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/Window.hpp b/src/Window.hpp index afe52f89..2e236322 100644 --- a/src/Window.hpp +++ b/src/Window.hpp @@ -28,6 +28,7 @@ public: DYNLISTENER(unmapWindow); DYNLISTENER(destroyWindow); DYNLISTENER(setTitleWindow); + DYNLISTENER(setGeometryX11U); DYNLISTENER(fullscreenWindow); DYNLISTENER(newPopupXDG); // DYNLISTENER(newSubsurfaceWindow); diff --git a/src/events/Events.hpp b/src/events/Events.hpp index de7f1d04..eefc55c7 100644 --- a/src/events/Events.hpp +++ b/src/events/Events.hpp @@ -49,6 +49,7 @@ namespace Events { DYNLISTENFUNC(fullscreenWindow); DYNLISTENFUNC(activateX11); DYNLISTENFUNC(configureX11); + DYNLISTENFUNC(unmanagedSetGeometry); // Window subsurfaces // LISTENER(newSubsurfaceWindow); diff --git a/src/events/Popups.cpp b/src/events/Popups.cpp index cfb92f9b..04064696 100644 --- a/src/events/Popups.cpp +++ b/src/events/Popups.cpp @@ -92,6 +92,9 @@ void Events::listener_newPopupXDG(void* owner, void* data) { ASSERT(PWINDOW); + if (!PWINDOW->m_bIsMapped) + return; + Debug::log(LOG, "New layer popup created from XDG window %x -> %s", PWINDOW, PWINDOW->m_szTitle.c_str()); const auto WLRPOPUP = (wlr_xdg_popup*)data; diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index de15799e..c245c626 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -250,6 +250,9 @@ void Events::listener_mapWindow(void* owner, void* data) { PWINDOW->hyprListener_activateX11.initCallback(&PWINDOW->m_uSurface.xwayland->events.request_activate, &Events::listener_activateX11, PWINDOW, "XWayland Window Late"); PWINDOW->hyprListener_configureX11.initCallback(&PWINDOW->m_uSurface.xwayland->events.request_configure, &Events::listener_configureX11, PWINDOW, "XWayland Window Late"); PWINDOW->hyprListener_setTitleWindow.initCallback(&PWINDOW->m_uSurface.xwayland->events.set_title, &Events::listener_setTitleWindow, PWINDOW, "XWayland Window Late"); + + if (PWINDOW->m_iX11Type == 2) + PWINDOW->hyprListener_setGeometryX11U.initCallback(&PWINDOW->m_uSurface.xwayland->events.set_geometry, &Events::listener_unmanagedSetGeometry, PWINDOW, "XWayland Window Late"); } // do the animation thing @@ -306,6 +309,7 @@ void Events::listener_unmapWindow(void* owner, void* data) { PWINDOW->hyprListener_activateX11.removeCallback(); PWINDOW->hyprListener_configureX11.removeCallback(); PWINDOW->hyprListener_setTitleWindow.removeCallback(); + PWINDOW->hyprListener_setGeometryX11U.removeCallback(); } if (PWINDOW->m_bIsFullscreen) { @@ -371,7 +375,7 @@ void Events::listener_unmapWindow(void* owner, void* data) { void Events::listener_commitWindow(void* owner, void* data) { CWindow* PWINDOW = (CWindow*)owner; - if (!g_pCompositor->windowValidMapped(PWINDOW)) + if (!PWINDOW->m_bMappedX11 || PWINDOW->m_bHidden || (PWINDOW->m_bIsX11 && !PWINDOW->m_bMappedX11)) return; g_pHyprRenderer->damageSurface(g_pXWaylandManager->getWindowSurface(PWINDOW), PWINDOW->m_vRealPosition.goalv().x, PWINDOW->m_vRealPosition.goalv().y); @@ -490,6 +494,23 @@ void Events::listener_configureX11(void* owner, void* data) { g_pHyprRenderer->damageWindow(PWINDOW); } +void Events::listener_unmanagedSetGeometry(void* owner, void* data) { + CWindow* PWINDOW = (CWindow*)owner; + + if (!PWINDOW->m_bMappedX11 || PWINDOW->m_bHidden) + return; + + const auto POS = PWINDOW->m_vRealPosition.goalv(); + + if (floor(POS.x) != PWINDOW->m_uSurface.xwayland->x || floor(POS.x) != PWINDOW->m_uSurface.xwayland->y) { + g_pHyprRenderer->damageWindow(PWINDOW); + PWINDOW->m_vRealPosition.setValueAndWarp(Vector2D(PWINDOW->m_uSurface.xwayland->x, PWINDOW->m_uSurface.xwayland->y)); + g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.vec()); + g_pCompositor->moveWindowToTop(PWINDOW); + g_pHyprRenderer->damageWindow(PWINDOW); + } +} + void Events::listener_surfaceXWayland(wl_listener* listener, void* data) { const auto XWSURFACE = (wlr_xwayland_surface*)data; diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index a7f2facf..73771e41 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -45,7 +45,7 @@ void IHyprLayout::onWindowCreatedFloating(CWindow* pWindow) { Vector2D middlePoint = Vector2D(desiredGeometry.x, desiredGeometry.y) + Vector2D(desiredGeometry.width, desiredGeometry.height) / 2.f; // TODO: detect a popup in a more consistent way. - if (!g_pCompositor->isPointOnAnyMonitor(middlePoint) || (desiredGeometry.x == 0 && desiredGeometry.y == 0)) { + if ((desiredGeometry.x == 0 && desiredGeometry.y == 0)) { // if it's not, fall back to the center placement pWindow->m_vRealPosition = PMONITOR->vecPosition + Vector2D((PMONITOR->vecSize.x - desiredGeometry.width) / 2.f, (PMONITOR->vecSize.y - desiredGeometry.height) / 2.f); } else { @@ -65,10 +65,12 @@ void IHyprLayout::onWindowCreatedFloating(CWindow* pWindow) { pWindow->m_vRealSize.setValue(pWindow->m_vRealSize.goalv()); } - g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize.goalv()); - g_pCompositor->fixXWaylandWindowsOnWorkspace(PMONITOR->activeWorkspace); + if (pWindow->m_iX11Type != 2) { + g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize.goalv()); + g_pCompositor->fixXWaylandWindowsOnWorkspace(PMONITOR->activeWorkspace); - g_pCompositor->moveWindowToTop(pWindow); + g_pCompositor->moveWindowToTop(pWindow); + } } void IHyprLayout::onBeginDragWindow() { diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index 96b667f9..82fb8392 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -191,7 +191,7 @@ void CAnimationManager::tick() { // set size and pos if valid, but only if damage policy entire (dont if border for example) - if (g_pCompositor->windowValidMapped(PWINDOW) && av->m_eDamagePolicy == AVARDAMAGE_ENTIRE) + if (g_pCompositor->windowValidMapped(PWINDOW) && av->m_eDamagePolicy == AVARDAMAGE_ENTIRE && PWINDOW->m_iX11Type != 2) g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.goalv()); // manually schedule a frame