anr: add xwayland support (#9456)

Adds XWayland support to ANR dialogs
This commit is contained in:
Vaxry 2025-02-21 21:26:53 +01:00 committed by GitHub
parent 0e24f9c0d5
commit f4b148df1e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 184 additions and 58 deletions

View file

@ -2,6 +2,7 @@
#include "XWayland.hpp"
#include "../protocols/XWaylandShell.hpp"
#include "../protocols/core/Compositor.hpp"
#include "../managers/ANRManager.hpp"
#ifndef NO_XWAYLAND
@ -243,6 +244,28 @@ void CXWaylandSurface::setWithdrawn(bool withdrawn_) {
xcb_change_property(g_pXWayland->pWM->connection, XCB_PROP_MODE_REPLACE, xID, HYPRATOMS["WM_STATE"], HYPRATOMS["WM_STATE"], 32, props.size(), props.data());
}
void CXWaylandSurface::ping() {
bool supportsPing = std::ranges::find(protocols, HYPRATOMS["_NET_WM_PING"]) != protocols.end();
if (!supportsPing) {
Debug::log(TRACE, "CXWaylandSurface: XID {} does not support ping, just sending an instant reply", xID);
g_pANRManager->onResponse(self.lock());
return;
}
timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
xcb_client_message_data_t msg = {};
msg.data32[0] = HYPRATOMS["_NET_WM_PING"];
msg.data32[1] = now.tv_sec * 1000 + now.tv_nsec / 1000000;
msg.data32[2] = xID;
lastPingSeq = msg.data32[1];
g_pXWayland->pWM->sendWMMessage(self.lock(), &msg, XCB_EVENT_MASK_PROPERTY_CHANGE);
}
#else
CXWaylandSurface::CXWaylandSurface(uint32_t xID_, CBox geometry_, bool OR) : xID(xID_), geometry(geometry_), overrideRedirect(OR) {
@ -297,4 +320,8 @@ void CXWaylandSurface::setWithdrawn(bool withdrawn) {
;
}
void CXWaylandSurface::ping() {
;
}
#endif

View file

@ -69,10 +69,11 @@ class CXWaylandSurface {
std::optional<bool> requestsMinimize;
} state;
uint32_t xID = 0;
uint64_t wlID = 0;
uint64_t wlSerial = 0;
pid_t pid = 0;
uint32_t xID = 0;
uint64_t wlID = 0;
uint64_t wlSerial = 0;
uint32_t lastPingSeq = 0;
pid_t pid = 0;
CBox geometry;
bool overrideRedirect = false;
bool withdrawn = false;
@ -88,7 +89,7 @@ class CXWaylandSurface {
UP<xcb_icccm_wm_hints_t> hints;
UP<xcb_size_hints_t> sizeHints;
std::vector<uint32_t> atoms;
std::vector<uint32_t> atoms, protocols;
std::string role = "";
bool transient = false;
@ -99,6 +100,7 @@ class CXWaylandSurface {
void setMinimized(bool mz);
void restackToTop();
void close();
void ping();
private:
CXWaylandSurface(uint32_t xID, CBox geometry, bool OR);

View file

@ -15,6 +15,7 @@
#include "../protocols/core/Seat.hpp"
#include "../managers/eventLoop/EventLoopManager.hpp"
#include "../managers/SeatManager.hpp"
#include "../managers/ANRManager.hpp"
#include "../protocols/XWaylandShell.hpp"
#include "../protocols/core/Compositor.hpp"
using namespace Hyprutils::OS;
@ -283,6 +284,16 @@ void CXWM::readProp(SP<CXWaylandSurface> XSURF, uint32_t atom, xcb_get_property_
XSURF->sizeHints->max_height = -1;
}
}
} else if (atom == HYPRATOMS["WM_PROTOCOLS"]) {
if (reply->type == XCB_ATOM_ATOM) {
auto atoms = (xcb_atom_t*)xcb_get_property_value(reply);
std::vector<uint32_t> vec;
vec.reserve(reply->value_len);
for (size_t i = 0; i < reply->value_len; ++i) {
vec.emplace_back(atoms[i]);
}
XSURF->protocols = vec;
}
} else {
Debug::log(TRACE, "[xwm] Unhandled prop {} -> {}", atom, propName);
return;
@ -315,16 +326,14 @@ void CXWM::handleClientMessage(xcb_client_message_event_t* e) {
if (!XSURF)
return;
std::string propName = "?";
for (auto const& ha : HYPRATOMS) {
if (ha.second != e->type)
continue;
std::string propName = getAtomName(e->type);
propName = ha.first;
break;
}
if (e->type == HYPRATOMS["WL_SURFACE_ID"]) {
if (e->type == HYPRATOMS["WM_PROTOCOLS"]) {
if (e->data.data32[1] == XSURF->lastPingSeq && e->data.data32[0] == HYPRATOMS["_NET_WM_PING"]) {
g_pANRManager->onResponse(XSURF);
return;
}
} else if (e->type == HYPRATOMS["WL_SURFACE_ID"]) {
if (XSURF->surface) {
Debug::log(WARN, "[xwm] Re-assignment of WL_SURFACE_ID");
dissociate(XSURF);
@ -1056,9 +1065,10 @@ void CXWM::onNewResource(SP<CXWaylandSurfaceResource> resource) {
}
void CXWM::readWindowData(SP<CXWaylandSurface> surf) {
const std::array<xcb_atom_t, 8> interestingProps = {
const std::array<xcb_atom_t, 9> interestingProps = {
XCB_ATOM_WM_CLASS, XCB_ATOM_WM_NAME, XCB_ATOM_WM_TRANSIENT_FOR, HYPRATOMS["WM_HINTS"],
HYPRATOMS["_NET_WM_STATE"], HYPRATOMS["_NET_WM_NAME"], HYPRATOMS["_NET_WM_WINDOW_TYPE"], HYPRATOMS["WM_NORMAL_HINTS"],
HYPRATOMS["WM_PROTOCOLS"],
};
for (size_t i = 0; i < interestingProps.size(); i++) {

View file

@ -83,6 +83,7 @@ inline std::unordered_map<std::string, uint32_t> HYPRATOMS = {
HYPRATOM("_NET_WORKAREA"),
HYPRATOM("_NET_WM_ICON"),
HYPRATOM("_NET_WM_CM_S0"),
HYPRATOM("_NET_WM_PING"),
HYPRATOM("WM_PROTOCOLS"),
HYPRATOM("WM_HINTS"),
HYPRATOM("WM_DELETE_WINDOW"),