From 1e7eb3a5a5419f97b61a3403880b161c85dd7b17 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 28 Feb 2024 23:14:50 +0000 Subject: [PATCH] xdg: check for floating conditions before sending tiled size hint ref #4871 --- src/config/ConfigManager.cpp | 2 +- src/events/Windows.cpp | 23 ++++++++++++++++++++--- src/managers/XWaylandManager.cpp | 16 ++++++++-------- src/managers/XWaylandManager.hpp | 2 +- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 151347ad..716882cf 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -946,7 +946,7 @@ SWorkspaceRule CConfigManager::getWorkspaceRuleFor(CWorkspace* pWorkspace) { } std::vector CConfigManager::getMatchingRules(CWindow* pWindow, bool dynamic) { - if (!g_pCompositor->windowValidMapped(pWindow)) + if (!g_pCompositor->windowExists(pWindow)) return std::vector(); std::vector returns; diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index d6241fa4..6ea0bb0c 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -806,9 +806,26 @@ void Events::listener_commitWindow(void* owner, void* data) { CWindow* PWINDOW = (CWindow*)owner; if (!PWINDOW->m_bIsX11 && PWINDOW->m_uSurface.xdg->initial_commit) { - const auto PREDSIZE = g_pLayoutManager->getCurrentLayout()->predictSizeForNewWindow(); - Debug::log(LOG, "Layout predicts size {} for {}", PREDSIZE, PWINDOW); - wlr_xdg_toplevel_set_size(PWINDOW->m_uSurface.xdg->toplevel, PREDSIZE.x, PREDSIZE.y); + Vector2D predSize = g_pLayoutManager->getCurrentLayout()->predictSizeForNewWindow(); + + if (g_pXWaylandManager->shouldBeFloated(PWINDOW, true)) + predSize = {}; + + Vector2D maxSize = Vector2D{PWINDOW->m_uSurface.xdg->toplevel->pending.max_width, PWINDOW->m_uSurface.xdg->toplevel->pending.max_height}; + + if ((maxSize.x > 0 && maxSize.x < predSize.x) || (maxSize.y > 0 && maxSize.y < predSize.y)) + predSize = {}; + + for (auto& r : g_pConfigManager->getMatchingRules(PWINDOW)) { + if (r.szRule == "float") { + predSize = {}; + break; + } + } + + Debug::log(LOG, "Layout predicts size {} for {}", predSize, PWINDOW); + + wlr_xdg_toplevel_set_size(PWINDOW->m_uSurface.xdg->toplevel, predSize.x, predSize.y); return; } diff --git a/src/managers/XWaylandManager.cpp b/src/managers/XWaylandManager.cpp index b46004e6..a7e869cb 100644 --- a/src/managers/XWaylandManager.cpp +++ b/src/managers/XWaylandManager.cpp @@ -98,11 +98,11 @@ void CHyprXWaylandManager::getGeometryForWindow(CWindow* pWindow, CBox* pbox) { } std::string CHyprXWaylandManager::getTitle(CWindow* pWindow) { - if (!pWindow->m_bIsMapped) - return ""; - try { if (pWindow->m_bIsX11) { + if (!pWindow->m_bIsMapped && pWindow->m_iX11Type != 1) + return ""; + if (pWindow->m_uSurface.xwayland && pWindow->m_uSurface.xwayland->title) { return std::string(pWindow->m_uSurface.xwayland->title); } @@ -119,11 +119,11 @@ std::string CHyprXWaylandManager::getTitle(CWindow* pWindow) { } std::string CHyprXWaylandManager::getAppIDClass(CWindow* pWindow) { - if (!pWindow->m_bIsMapped) - return ""; - try { if (pWindow->m_bIsX11) { + if (!pWindow->m_bIsMapped && pWindow->m_iX11Type != 1) + return ""; + if (pWindow->m_uSurface.xwayland && pWindow->m_uSurface.xwayland->_class) { return std::string(pWindow->m_uSurface.xwayland->_class); } @@ -198,7 +198,7 @@ wlr_surface* CHyprXWaylandManager::surfaceAt(CWindow* pWindow, const Vector2D& c return wlr_xdg_surface_surface_at(pWindow->m_uSurface.xdg, client.x, client.y, &surface.x, &surface.y); } -bool CHyprXWaylandManager::shouldBeFloated(CWindow* pWindow) { +bool CHyprXWaylandManager::shouldBeFloated(CWindow* pWindow, bool pending) { if (pWindow->m_bIsX11) { for (size_t i = 0; i < pWindow->m_uSurface.xwayland->window_type_len; i++) if (pWindow->m_uSurface.xwayland->window_type[i] == HYPRATOMS["_NET_WM_WINDOW_TYPE_DIALOG"] || @@ -243,7 +243,7 @@ bool CHyprXWaylandManager::shouldBeFloated(CWindow* pWindow) { if (SIZEHINTS && (pWindow->m_uSurface.xwayland->parent || ((SIZEHINTS->min_width == SIZEHINTS->max_width) && (SIZEHINTS->min_height == SIZEHINTS->max_height)))) return true; } else { - const auto PSTATE = &pWindow->m_uSurface.xdg->toplevel->current; + const auto PSTATE = pending ? &pWindow->m_uSurface.xdg->toplevel->pending : &pWindow->m_uSurface.xdg->toplevel->current; if ((PSTATE->min_width != 0 && PSTATE->min_height != 0 && (PSTATE->min_width == PSTATE->max_width || PSTATE->min_height == PSTATE->max_height)) || pWindow->m_uSurface.xdg->toplevel->parent) diff --git a/src/managers/XWaylandManager.hpp b/src/managers/XWaylandManager.hpp index e41313e0..9fa9f46e 100644 --- a/src/managers/XWaylandManager.hpp +++ b/src/managers/XWaylandManager.hpp @@ -23,7 +23,7 @@ class CHyprXWaylandManager { void setWindowStyleTiled(CWindow*, uint32_t); void setWindowFullscreen(CWindow*, bool); wlr_surface* surfaceAt(CWindow*, const Vector2D&, Vector2D&); - bool shouldBeFloated(CWindow*); + bool shouldBeFloated(CWindow*, bool pending = false); void moveXWaylandWindow(CWindow*, const Vector2D&); void checkBorders(CWindow*); Vector2D getMaxSizeForWindow(CWindow*);