xwayland: minor cleanups and fixes (#8076)

This commit is contained in:
Jasson 2024-10-11 07:07:25 -04:00 committed by GitHub
parent d655a10381
commit 178a300eea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,14 +5,13 @@
#include "../protocols/XDGShell.hpp" #include "../protocols/XDGShell.hpp"
#include "../protocols/core/Compositor.hpp" #include "../protocols/core/Compositor.hpp"
#include "../xwayland/XWayland.hpp" #include "../xwayland/XWayland.hpp"
#include <hyprutils/math/Vector2D.hpp>
#define OUTPUT_MANAGER_VERSION 3 #define OUTPUT_MANAGER_VERSION 3
#define OUTPUT_DONE_DEPRECATED_SINCE_VERSION 3 #define OUTPUT_DONE_DEPRECATED_SINCE_VERSION 3
#define OUTPUT_DESCRIPTION_MUTABLE_SINCE_VERSION 3 #define OUTPUT_DESCRIPTION_MUTABLE_SINCE_VERSION 3
CHyprXWaylandManager::CHyprXWaylandManager() { CHyprXWaylandManager::CHyprXWaylandManager() = default;
;
}
CHyprXWaylandManager::~CHyprXWaylandManager() { CHyprXWaylandManager::~CHyprXWaylandManager() {
#ifndef NO_XWAYLAND #ifndef NO_XWAYLAND
@ -21,7 +20,7 @@ CHyprXWaylandManager::~CHyprXWaylandManager() {
} }
SP<CWLSurfaceResource> CHyprXWaylandManager::getWindowSurface(PHLWINDOW pWindow) { SP<CWLSurfaceResource> CHyprXWaylandManager::getWindowSurface(PHLWINDOW pWindow) {
return pWindow->m_pWLSurface->resource(); return pWindow ? pWindow->m_pWLSurface->resource() : nullptr;
} }
void CHyprXWaylandManager::activateSurface(SP<CWLSurfaceResource> pSurface, bool activate) { void CHyprXWaylandManager::activateSurface(SP<CWLSurfaceResource> pSurface, bool activate) {
@ -40,27 +39,31 @@ void CHyprXWaylandManager::activateSurface(SP<CWLSurfaceResource> pSurface, bool
return; return;
} }
if (PWINDOW->m_bIsX11 && PWINDOW->m_pXWaylandSurface) { if (PWINDOW->m_bIsX11) {
if (activate) { if (PWINDOW->m_pXWaylandSurface) {
PWINDOW->m_pXWaylandSurface->setMinimized(false); if (activate) {
PWINDOW->m_pXWaylandSurface->restackToTop(); PWINDOW->m_pXWaylandSurface->setMinimized(false);
PWINDOW->m_pXWaylandSurface->restackToTop();
}
PWINDOW->m_pXWaylandSurface->activate(activate);
} }
PWINDOW->m_pXWaylandSurface->activate(activate); } else if (PWINDOW->m_pXDGSurface)
} else if (!PWINDOW->m_bIsX11 && PWINDOW->m_pXDGSurface)
PWINDOW->m_pXDGSurface->toplevel->setActive(activate); PWINDOW->m_pXDGSurface->toplevel->setActive(activate);
} }
void CHyprXWaylandManager::activateWindow(PHLWINDOW pWindow, bool activate) { void CHyprXWaylandManager::activateWindow(PHLWINDOW pWindow, bool activate) {
if (pWindow->m_bIsX11) { if (pWindow->m_bIsX11) {
setWindowSize(pWindow, pWindow->m_vRealSize.value()); // update xwayland output pos
if (activate) { if (activate) {
setWindowSize(pWindow, pWindow->m_vRealSize.value()); // update xwayland output pos
pWindow->m_pXWaylandSurface->setMinimized(false); pWindow->m_pXWaylandSurface->setMinimized(false);
if (!pWindow->isX11OverrideRedirect()) if (!pWindow->isX11OverrideRedirect())
pWindow->m_pXWaylandSurface->restackToTop(); pWindow->m_pXWaylandSurface->restackToTop();
} }
pWindow->m_pXWaylandSurface->activate(activate); pWindow->m_pXWaylandSurface->activate(activate);
} else if (pWindow->m_pXDGSurface && pWindow->m_pXDGSurface->toplevel) } else if (pWindow->m_pXDGSurface && pWindow->m_pXDGSurface->toplevel)
pWindow->m_pXDGSurface->toplevel->setActive(activate); pWindow->m_pXDGSurface->toplevel->setActive(activate);
@ -74,6 +77,9 @@ void CHyprXWaylandManager::activateWindow(PHLWINDOW pWindow, bool activate) {
} }
void CHyprXWaylandManager::getGeometryForWindow(PHLWINDOW pWindow, CBox* pbox) { void CHyprXWaylandManager::getGeometryForWindow(PHLWINDOW pWindow, CBox* pbox) {
if (!pWindow)
return;
if (pWindow->m_bIsX11) { if (pWindow->m_bIsX11) {
const auto SIZEHINTS = pWindow->m_pXWaylandSurface->sizeHints.get(); const auto SIZEHINTS = pWindow->m_pXWaylandSurface->sizeHints.get();
@ -83,7 +89,10 @@ void CHyprXWaylandManager::getGeometryForWindow(PHLWINDOW pWindow, CBox* pbox) {
pbox->x = pWindow->m_pXWaylandSurface->geometry.x; pbox->x = pWindow->m_pXWaylandSurface->geometry.x;
pbox->y = pWindow->m_pXWaylandSurface->geometry.y; pbox->y = pWindow->m_pXWaylandSurface->geometry.y;
if ((SIZEHINTS->flags & 0x2 /* ICCCM USSize */) || (SIZEHINTS->flags & 0x8 /* ICCCM PSize */)) { constexpr int ICCCM_USSize = 0x2;
constexpr int ICCCM_PSize = 0x8;
if ((SIZEHINTS->flags & ICCCM_USSize) || (SIZEHINTS->flags & ICCCM_PSize)) {
pbox->w = SIZEHINTS->base_width; pbox->w = SIZEHINTS->base_width;
pbox->h = SIZEHINTS->base_height; pbox->h = SIZEHINTS->base_height;
} else { } else {
@ -117,34 +126,34 @@ void CHyprXWaylandManager::setWindowSize(PHLWINDOW pWindow, Vector2D size, bool
Vector2D windowPos = pWindow->m_vRealPosition.value(); Vector2D windowPos = pWindow->m_vRealPosition.value();
if (pWindow->m_bIsX11 && PMONITOR) { if (pWindow->m_bIsX11 && PMONITOR) {
windowPos = windowPos - PMONITOR->vecPosition; // normalize to monitor windowPos -= PMONITOR->vecPosition; // normalize to monitor
if (*PXWLFORCESCALEZERO) if (*PXWLFORCESCALEZERO)
windowPos = windowPos * PMONITOR->scale; // scale if applicable windowPos *= PMONITOR->scale; // scale if applicable
windowPos = windowPos + PMONITOR->vecXWaylandPosition; // move to correct position for xwayland windowPos += PMONITOR->vecXWaylandPosition; // move to correct position for xwayland
} }
if (!force && ((pWindow->m_vPendingReportedSize == size && windowPos == pWindow->m_vReportedPosition) || (pWindow->m_vPendingReportedSize == size && !pWindow->m_bIsX11))) if (!force && pWindow->m_vPendingReportedSize == size && (windowPos == pWindow->m_vReportedPosition || !pWindow->m_bIsX11))
return; return;
pWindow->m_vReportedPosition = windowPos; pWindow->m_vReportedPosition = windowPos;
pWindow->m_vPendingReportedSize = size; pWindow->m_vPendingReportedSize = size;
pWindow->m_fX11SurfaceScaledBy = 1.f; pWindow->m_fX11SurfaceScaledBy = 1.0f;
if (*PXWLFORCESCALEZERO && pWindow->m_bIsX11 && PMONITOR) { if (*PXWLFORCESCALEZERO && pWindow->m_bIsX11 && PMONITOR) {
size = size * PMONITOR->scale; size *= PMONITOR->scale;
pWindow->m_fX11SurfaceScaledBy = PMONITOR->scale; pWindow->m_fX11SurfaceScaledBy = PMONITOR->scale;
} }
if (pWindow->m_bIsX11) if (pWindow->m_bIsX11)
pWindow->m_pXWaylandSurface->configure({windowPos, size}); pWindow->m_pXWaylandSurface->configure({windowPos, size});
else if (pWindow->m_pXDGSurface->toplevel) else if (pWindow->m_pXDGSurface->toplevel)
pWindow->m_vPendingSizeAcks.push_back(std::make_pair<>(pWindow->m_pXDGSurface->toplevel->setSize(size), size.floor())); pWindow->m_vPendingSizeAcks.emplace_back(pWindow->m_pXDGSurface->toplevel->setSize(size), size.floor());
} }
bool CHyprXWaylandManager::shouldBeFloated(PHLWINDOW pWindow, bool pending) { bool CHyprXWaylandManager::shouldBeFloated(PHLWINDOW pWindow, bool pending) {
if (pWindow->m_bIsX11) { if (pWindow->m_bIsX11) {
for (auto const& a : pWindow->m_pXWaylandSurface->atoms) for (const auto& a : pWindow->m_pXWaylandSurface->atoms)
if (a == HYPRATOMS["_NET_WM_WINDOW_TYPE_DIALOG"] || a == HYPRATOMS["_NET_WM_WINDOW_TYPE_SPLASH"] || a == HYPRATOMS["_NET_WM_WINDOW_TYPE_TOOLBAR"] || if (a == HYPRATOMS["_NET_WM_WINDOW_TYPE_DIALOG"] || a == HYPRATOMS["_NET_WM_WINDOW_TYPE_SPLASH"] || a == HYPRATOMS["_NET_WM_WINDOW_TYPE_TOOLBAR"] ||
a == HYPRATOMS["_NET_WM_WINDOW_TYPE_UTILITY"] || a == HYPRATOMS["_NET_WM_WINDOW_TYPE_TOOLTIP"] || a == HYPRATOMS["_NET_WM_WINDOW_TYPE_POPUP_MENU"] || a == HYPRATOMS["_NET_WM_WINDOW_TYPE_UTILITY"] || a == HYPRATOMS["_NET_WM_WINDOW_TYPE_TOOLTIP"] || a == HYPRATOMS["_NET_WM_WINDOW_TYPE_POPUP_MENU"] ||
a == HYPRATOMS["_NET_WM_WINDOW_TYPE_DOCK"] || a == HYPRATOMS["_NET_WM_WINDOW_TYPE_DROPDOWN_MENU"] || a == HYPRATOMS["_NET_WM_WINDOW_TYPE_MENU"] || a == HYPRATOMS["_NET_WM_WINDOW_TYPE_DOCK"] || a == HYPRATOMS["_NET_WM_WINDOW_TYPE_DROPDOWN_MENU"] || a == HYPRATOMS["_NET_WM_WINDOW_TYPE_MENU"] ||
@ -157,16 +166,8 @@ bool CHyprXWaylandManager::shouldBeFloated(PHLWINDOW pWindow, bool pending) {
return true; return true;
} }
if (pWindow->isModal()) if (pWindow->isModal() || pWindow->m_pXWaylandSurface->transient ||
return true; (pWindow->m_pXWaylandSurface->role.contains("task_dialog") || pWindow->m_pXWaylandSurface->role.contains("pop-up")) || pWindow->m_pXWaylandSurface->overrideRedirect)
if (pWindow->m_pXWaylandSurface->transient)
return true;
if (pWindow->m_pXWaylandSurface->role.contains("task_dialog") || pWindow->m_pXWaylandSurface->role.contains("pop-up"))
return true;
if (pWindow->m_pXWaylandSurface->overrideRedirect)
return true; return true;
const auto SIZEHINTS = pWindow->m_pXWaylandSurface->sizeHints.get(); const auto SIZEHINTS = pWindow->m_pXWaylandSurface->sizeHints.get();
@ -203,6 +204,9 @@ void CHyprXWaylandManager::checkBorders(PHLWINDOW pWindow) {
} }
void CHyprXWaylandManager::setWindowFullscreen(PHLWINDOW pWindow, bool fullscreen) { void CHyprXWaylandManager::setWindowFullscreen(PHLWINDOW pWindow, bool fullscreen) {
if (!pWindow)
return;
if (pWindow->m_bIsX11) if (pWindow->m_bIsX11)
pWindow->m_pXWaylandSurface->setFullscreen(fullscreen); pWindow->m_pXWaylandSurface->setFullscreen(fullscreen);
else if (pWindow->m_pXDGSurface && pWindow->m_pXDGSurface->toplevel) else if (pWindow->m_pXDGSurface && pWindow->m_pXDGSurface->toplevel)
@ -210,37 +214,33 @@ void CHyprXWaylandManager::setWindowFullscreen(PHLWINDOW pWindow, bool fullscree
} }
Vector2D CHyprXWaylandManager::getMaxSizeForWindow(PHLWINDOW pWindow) { Vector2D CHyprXWaylandManager::getMaxSizeForWindow(PHLWINDOW pWindow) {
if (!validMapped(pWindow)) constexpr int NO_MAX_SIZE_LIMIT = 99999;
return Vector2D(99999, 99999); if (!validMapped(pWindow) ||
((pWindow->m_bIsX11 && !pWindow->m_pXWaylandSurface->sizeHints) || (!pWindow->m_bIsX11 && !pWindow->m_pXDGSurface->toplevel) ||
pWindow->m_sWindowData.noMaxSize.valueOrDefault()))
return Vector2D(NO_MAX_SIZE_LIMIT, NO_MAX_SIZE_LIMIT);
if ((pWindow->m_bIsX11 && !pWindow->m_pXWaylandSurface->sizeHints) || (!pWindow->m_bIsX11 && !pWindow->m_pXDGSurface->toplevel) || Vector2D maxSize = pWindow->m_bIsX11 ? Vector2D(pWindow->m_pXWaylandSurface->sizeHints->max_width, pWindow->m_pXWaylandSurface->sizeHints->max_height) :
pWindow->m_sWindowData.noMaxSize.valueOrDefault()) pWindow->m_pXDGSurface->toplevel->current.maxSize;
return Vector2D(99999, 99999);
auto MAXSIZE = pWindow->m_bIsX11 ? Vector2D(pWindow->m_pXWaylandSurface->sizeHints->max_width, pWindow->m_pXWaylandSurface->sizeHints->max_height) : if (maxSize.x < 5)
pWindow->m_pXDGSurface->toplevel->current.maxSize; maxSize.x = NO_MAX_SIZE_LIMIT;
if (maxSize.y < 5)
maxSize.y = NO_MAX_SIZE_LIMIT;
if (MAXSIZE.x < 5) return maxSize;
MAXSIZE.x = 99999;
if (MAXSIZE.y < 5)
MAXSIZE.y = 99999;
return MAXSIZE;
} }
Vector2D CHyprXWaylandManager::getMinSizeForWindow(PHLWINDOW pWindow) { Vector2D CHyprXWaylandManager::getMinSizeForWindow(PHLWINDOW pWindow) {
if (!validMapped(pWindow)) if (!validMapped(pWindow) || ((pWindow->m_bIsX11 && !pWindow->m_pXWaylandSurface->sizeHints) || (!pWindow->m_bIsX11 && !pWindow->m_pXDGSurface->toplevel)))
return Vector2D(0, 0); return Vector2D(0, 0);
if ((pWindow->m_bIsX11 && !pWindow->m_pXWaylandSurface->sizeHints) || (!pWindow->m_bIsX11 && !pWindow->m_pXDGSurface->toplevel)) Vector2D minSize = pWindow->m_bIsX11 ? Vector2D(pWindow->m_pXWaylandSurface->sizeHints->min_width, pWindow->m_pXWaylandSurface->sizeHints->min_height) :
return Vector2D(0, 0); pWindow->m_pXDGSurface->toplevel->current.minSize;
auto MINSIZE = pWindow->m_bIsX11 ? Vector2D(pWindow->m_pXWaylandSurface->sizeHints->min_width, pWindow->m_pXWaylandSurface->sizeHints->min_height) : minSize = minSize.clamp({1, 1});
pWindow->m_pXDGSurface->toplevel->current.minSize;
MINSIZE = MINSIZE.clamp({1, 1}); return minSize;
return MINSIZE;
} }
Vector2D CHyprXWaylandManager::xwaylandToWaylandCoords(const Vector2D& coord) { Vector2D CHyprXWaylandManager::xwaylandToWaylandCoords(const Vector2D& coord) {
@ -249,7 +249,7 @@ Vector2D CHyprXWaylandManager::xwaylandToWaylandCoords(const Vector2D& coord) {
CMonitor* pMonitor = nullptr; CMonitor* pMonitor = nullptr;
double bestDistance = __FLT_MAX__; double bestDistance = __FLT_MAX__;
for (auto const& m : g_pCompositor->m_vMonitors) { for (const auto& m : g_pCompositor->m_vMonitors) {
const auto SIZ = *PXWLFORCESCALEZERO ? m->vecTransformedSize : m->vecSize; const auto SIZ = *PXWLFORCESCALEZERO ? m->vecTransformedSize : m->vecSize;
double distance = double distance =
@ -268,9 +268,9 @@ Vector2D CHyprXWaylandManager::xwaylandToWaylandCoords(const Vector2D& coord) {
Vector2D result = coord - pMonitor->vecXWaylandPosition; Vector2D result = coord - pMonitor->vecXWaylandPosition;
// if scaled, unscale // if scaled, unscale
if (*PXWLFORCESCALEZERO) if (*PXWLFORCESCALEZERO)
result = result / pMonitor->scale; result /= pMonitor->scale;
// add pos // add pos
result = result + pMonitor->vecPosition; result += pMonitor->vecPosition;
return result; return result;
} }