From bef1321f00e260ee3031aecd02faf4f53bcb5c66 Mon Sep 17 00:00:00 2001 From: Jasson Date: Wed, 18 Jun 2025 04:16:22 -0400 Subject: [PATCH] xwayland: fix minor errors in previous refactor (#10763) --- src/xwayland/XWM.cpp | 75 +++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 36 deletions(-) diff --git a/src/xwayland/XWM.cpp b/src/xwayland/XWM.cpp index 4618fa2f4..b48c43e79 100644 --- a/src/xwayland/XWM.cpp +++ b/src/xwayland/XWM.cpp @@ -20,6 +20,8 @@ #include "../managers/ANRManager.hpp" #include "../protocols/XWaylandShell.hpp" #include "../protocols/core/Compositor.hpp" +using Hyprutils::Memory::CUniquePointer; + using namespace Hyprutils::OS; #define XCB_EVENT_RESPONSE_TYPE_MASK 0x7f @@ -29,6 +31,15 @@ static int onX11Event(int fd, uint32_t mask, void* data) { return g_pXWayland->m_wm->onEvent(fd, mask); } +struct SFreeDeleter { + void operator()(void* ptr) const { + std::free(ptr); + } +}; + +template +using XCBReplyPtr = std::unique_ptr; + SP CXWM::windowForXID(xcb_window_t wid) { for (auto const& s : m_surfaces) { if (s->m_xID == wid) @@ -182,9 +193,8 @@ std::string CXWM::getAtomName(uint32_t atom) { } // Get the name of the atom - const auto cookie = xcb_get_atom_name(m_connection, atom); - using ReplyPtr = std::unique_ptr; - ReplyPtr reply(xcb_get_atom_name_reply(m_connection, cookie, nullptr), &free); + const auto cookie = xcb_get_atom_name(m_connection, atom); + XCBReplyPtr reply(xcb_get_atom_name_reply(m_connection, cookie, nullptr)); if (!reply) return "Unknown"; @@ -332,9 +342,8 @@ void CXWM::handlePropertyNotify(xcb_property_notify_event_t* e) { if (!XSURF) return; - xcb_get_property_cookie_t cookie = xcb_get_property(m_connection, 0, XSURF->m_xID, e->atom, XCB_ATOM_ANY, 0, 2048); - using ReplyPtr = std::unique_ptr; - ReplyPtr reply(xcb_get_property_reply(m_connection, cookie, nullptr), &free); + xcb_get_property_cookie_t cookie = xcb_get_property(m_connection, 0, XSURF->m_xID, e->atom, XCB_ATOM_ANY, 0, 2048); + XCBReplyPtr reply(xcb_get_property_reply(m_connection, cookie, nullptr)); if (!reply) { Debug::log(ERR, "[xwm] Failed to read property notify cookie"); @@ -573,12 +582,11 @@ xcb_atom_t CXWM::mimeToAtom(const std::string& mime) { if (mime == "text/plain") return HYPRATOMS["TEXT"]; - xcb_intern_atom_cookie_t cookie = xcb_intern_atom(m_connection, 0, mime.length(), mime.c_str()); - using ReplyPtr = std::unique_ptr; - ReplyPtr reply(xcb_intern_atom_reply(m_connection, cookie, nullptr), &free); + xcb_intern_atom_cookie_t cookie = xcb_intern_atom(m_connection, 0, mime.length(), mime.c_str()); + XCBReplyPtr reply(xcb_intern_atom_reply(m_connection, cookie, nullptr)); if (!reply.get()) return XCB_ATOM_NONE; - xcb_atom_t atom = reply.get()->atom; + xcb_atom_t atom = reply->atom; return atom; } @@ -589,9 +597,8 @@ std::string CXWM::mimeFromAtom(xcb_atom_t atom) { if (atom == HYPRATOMS["TEXT"]) return "text/plain"; - xcb_get_atom_name_cookie_t cookie = xcb_get_atom_name(m_connection, atom); - using ReplyPtr = std::unique_ptr; - ReplyPtr reply(xcb_get_atom_name_reply(m_connection, cookie, nullptr), &free); + xcb_get_atom_name_cookie_t cookie = xcb_get_atom_name(m_connection, atom); + XCBReplyPtr reply(xcb_get_atom_name_reply(m_connection, cookie, nullptr)); if (!reply) return "INVALID"; size_t len = xcb_get_atom_name_name_length(reply.get()); @@ -839,9 +846,8 @@ void CXWM::gatherResources() { xcb_prefetch_extension_data(m_connection, &xcb_res_id); for (auto& ATOM : HYPRATOMS) { - xcb_intern_atom_cookie_t cookie = xcb_intern_atom(m_connection, 0, ATOM.first.length(), ATOM.first.c_str()); - using ReplyPtr = std::unique_ptr; - ReplyPtr reply(xcb_intern_atom_reply(m_connection, cookie, nullptr), &free); + xcb_intern_atom_cookie_t cookie = xcb_intern_atom(m_connection, 0, ATOM.first.length(), ATOM.first.c_str()); + XCBReplyPtr reply(xcb_intern_atom_reply(m_connection, cookie, nullptr)); if (!reply) { Debug::log(ERR, "[xwm] Atom failed: {}", ATOM.first); @@ -856,29 +862,27 @@ void CXWM::gatherResources() { if (!m_xfixes || !m_xfixes->present) Debug::log(WARN, "XFixes not available"); - xcb_xfixes_query_version_cookie_t xfixes_cookie; - using ReplyPtr = std::unique_ptr; + auto xfixes_cookie = xcb_xfixes_query_version(m_connection, XCB_XFIXES_MAJOR_VERSION, XCB_XFIXES_MINOR_VERSION); + XCBReplyPtr xfixes_reply(xcb_xfixes_query_version_reply(m_connection, xfixes_cookie, nullptr)); - xfixes_cookie = xcb_xfixes_query_version(m_connection, XCB_XFIXES_MAJOR_VERSION, XCB_XFIXES_MINOR_VERSION); - ReplyPtr xfixes_reply(xcb_xfixes_query_version_reply(m_connection, xfixes_cookie, nullptr), &free); + if (xfixes_reply) { + Debug::log(LOG, "xfixes version: {}.{}", xfixes_reply->major_version, xfixes_reply->minor_version); + m_xfixesMajor = xfixes_reply->major_version; + } - Debug::log(LOG, "xfixes version: {}.{}", xfixes_reply->major_version, xfixes_reply->minor_version); - m_xfixesMajor = xfixes_reply->major_version; - - const xcb_query_extension_reply_t* xresReply1 = xcb_get_extension_data(m_connection, &xcb_res_id); + const auto* xresReply1 = xcb_get_extension_data(m_connection, &xcb_res_id); if (!xresReply1 || !xresReply1->present) return; - xcb_res_query_version_cookie_t xres_cookie = xcb_res_query_version(m_connection, XCB_RES_MAJOR_VERSION, XCB_RES_MINOR_VERSION); - xcb_res_query_version_reply_t* xres_reply = xcb_res_query_version_reply(m_connection, xres_cookie, nullptr); - if (xres_reply == nullptr) + auto xres_cookie = xcb_res_query_version(m_connection, XCB_RES_MAJOR_VERSION, XCB_RES_MINOR_VERSION); + XCBReplyPtr xres_reply(xcb_res_query_version_reply(m_connection, xres_cookie, nullptr)); + if (!xres_reply) return; Debug::log(LOG, "xres version: {}.{}", xres_reply->server_major, xres_reply->server_minor); if (xres_reply->server_major > 1 || (xres_reply->server_major == 1 && xres_reply->server_minor >= 2)) { m_xres = xresReply1; } - free(xres_reply); } void CXWM::getVisual() { @@ -909,16 +913,16 @@ void CXWM::getVisual() { } void CXWM::getRenderFormat() { - xcb_render_query_pict_formats_cookie_t cookie = xcb_render_query_pict_formats(m_connection); - using ReplyPtr = std::unique_ptr; - ReplyPtr reply(xcb_render_query_pict_formats_reply(m_connection, cookie, nullptr), &free); + auto cookie = xcb_render_query_pict_formats(m_connection); + XCBReplyPtr reply(xcb_render_query_pict_formats_reply(m_connection, cookie, nullptr)); if (!reply) { Debug::log(LOG, "xwm: No xcb_render_query_pict_formats_reply_t reply"); return; } - xcb_render_pictforminfo_iterator_t iter = xcb_render_query_pict_formats_formats_iterator(reply.get()); - xcb_render_pictforminfo_t* format = nullptr; + + auto iter = xcb_render_query_pict_formats_formats_iterator(reply.get()); + xcb_render_pictforminfo_t* format = nullptr; while (iter.rem > 0) { if (iter.data->depth == 32) { format = iter.data; @@ -1105,9 +1109,8 @@ void CXWM::readWindowData(SP surf) { }; for (size_t i = 0; i < interestingProps.size(); i++) { - xcb_get_property_cookie_t cookie = xcb_get_property(m_connection, 0, surf->m_xID, interestingProps[i], XCB_ATOM_ANY, 0, 2048); - using ReplyPtr = std::unique_ptr; - ReplyPtr reply(xcb_get_property_reply(m_connection, cookie, nullptr), &free); + xcb_get_property_cookie_t cookie = xcb_get_property(m_connection, 0, surf->m_xID, interestingProps[i], XCB_ATOM_ANY, 0, 2048); + XCBReplyPtr reply(xcb_get_property_reply(m_connection, cookie, nullptr)); if (!reply) { Debug::log(ERR, "[xwm] Failed to get window property"); continue;