Skip to content

Commit

Permalink
xdg: check for floating conditions before sending tiled size hint
Browse files Browse the repository at this point in the history
ref #4871
  • Loading branch information
vaxerski committed Feb 28, 2024
1 parent 097f561 commit 1e7eb3a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,7 @@ SWorkspaceRule CConfigManager::getWorkspaceRuleFor(CWorkspace* pWorkspace) {
}

std::vector<SWindowRule> CConfigManager::getMatchingRules(CWindow* pWindow, bool dynamic) {
if (!g_pCompositor->windowValidMapped(pWindow))
if (!g_pCompositor->windowExists(pWindow))
return std::vector<SWindowRule>();

std::vector<SWindowRule> returns;
Expand Down
23 changes: 20 additions & 3 deletions src/events/Windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
16 changes: 8 additions & 8 deletions src/managers/XWaylandManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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"] ||
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/managers/XWaylandManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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*);
Expand Down

0 comments on commit 1e7eb3a

Please sign in to comment.