Skip to content

Commit bef1321

Browse files
xwayland: fix minor errors in previous refactor (#10763)
1 parent 0ece4af commit bef1321

File tree

1 file changed

+39
-36
lines changed

1 file changed

+39
-36
lines changed

src/xwayland/XWM.cpp

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "../managers/ANRManager.hpp"
2121
#include "../protocols/XWaylandShell.hpp"
2222
#include "../protocols/core/Compositor.hpp"
23+
using Hyprutils::Memory::CUniquePointer;
24+
2325
using namespace Hyprutils::OS;
2426

2527
#define XCB_EVENT_RESPONSE_TYPE_MASK 0x7f
@@ -29,6 +31,15 @@ static int onX11Event(int fd, uint32_t mask, void* data) {
2931
return g_pXWayland->m_wm->onEvent(fd, mask);
3032
}
3133

34+
struct SFreeDeleter {
35+
void operator()(void* ptr) const {
36+
std::free(ptr);
37+
}
38+
};
39+
40+
template <typename T>
41+
using XCBReplyPtr = std::unique_ptr<T, SFreeDeleter>;
42+
3243
SP<CXWaylandSurface> CXWM::windowForXID(xcb_window_t wid) {
3344
for (auto const& s : m_surfaces) {
3445
if (s->m_xID == wid)
@@ -182,9 +193,8 @@ std::string CXWM::getAtomName(uint32_t atom) {
182193
}
183194

184195
// Get the name of the atom
185-
const auto cookie = xcb_get_atom_name(m_connection, atom);
186-
using ReplyPtr = std::unique_ptr<xcb_get_atom_name_reply_t, decltype(&free)>;
187-
ReplyPtr reply(xcb_get_atom_name_reply(m_connection, cookie, nullptr), &free);
196+
const auto cookie = xcb_get_atom_name(m_connection, atom);
197+
XCBReplyPtr<xcb_get_atom_name_reply_t> reply(xcb_get_atom_name_reply(m_connection, cookie, nullptr));
188198

189199
if (!reply)
190200
return "Unknown";
@@ -332,9 +342,8 @@ void CXWM::handlePropertyNotify(xcb_property_notify_event_t* e) {
332342
if (!XSURF)
333343
return;
334344

335-
xcb_get_property_cookie_t cookie = xcb_get_property(m_connection, 0, XSURF->m_xID, e->atom, XCB_ATOM_ANY, 0, 2048);
336-
using ReplyPtr = std::unique_ptr<xcb_get_property_reply_t, decltype(&free)>;
337-
ReplyPtr reply(xcb_get_property_reply(m_connection, cookie, nullptr), &free);
345+
xcb_get_property_cookie_t cookie = xcb_get_property(m_connection, 0, XSURF->m_xID, e->atom, XCB_ATOM_ANY, 0, 2048);
346+
XCBReplyPtr<xcb_get_property_reply_t> reply(xcb_get_property_reply(m_connection, cookie, nullptr));
338347

339348
if (!reply) {
340349
Debug::log(ERR, "[xwm] Failed to read property notify cookie");
@@ -573,12 +582,11 @@ xcb_atom_t CXWM::mimeToAtom(const std::string& mime) {
573582
if (mime == "text/plain")
574583
return HYPRATOMS["TEXT"];
575584

576-
xcb_intern_atom_cookie_t cookie = xcb_intern_atom(m_connection, 0, mime.length(), mime.c_str());
577-
using ReplyPtr = std::unique_ptr<xcb_intern_atom_reply_t, decltype(&free)>;
578-
ReplyPtr reply(xcb_intern_atom_reply(m_connection, cookie, nullptr), &free);
585+
xcb_intern_atom_cookie_t cookie = xcb_intern_atom(m_connection, 0, mime.length(), mime.c_str());
586+
XCBReplyPtr<xcb_intern_atom_reply_t> reply(xcb_intern_atom_reply(m_connection, cookie, nullptr));
579587
if (!reply.get())
580588
return XCB_ATOM_NONE;
581-
xcb_atom_t atom = reply.get()->atom;
589+
xcb_atom_t atom = reply->atom;
582590

583591
return atom;
584592
}
@@ -589,9 +597,8 @@ std::string CXWM::mimeFromAtom(xcb_atom_t atom) {
589597
if (atom == HYPRATOMS["TEXT"])
590598
return "text/plain";
591599

592-
xcb_get_atom_name_cookie_t cookie = xcb_get_atom_name(m_connection, atom);
593-
using ReplyPtr = std::unique_ptr<xcb_get_atom_name_reply_t, decltype(&free)>;
594-
ReplyPtr reply(xcb_get_atom_name_reply(m_connection, cookie, nullptr), &free);
600+
xcb_get_atom_name_cookie_t cookie = xcb_get_atom_name(m_connection, atom);
601+
XCBReplyPtr<xcb_get_atom_name_reply_t> reply(xcb_get_atom_name_reply(m_connection, cookie, nullptr));
595602
if (!reply)
596603
return "INVALID";
597604
size_t len = xcb_get_atom_name_name_length(reply.get());
@@ -839,9 +846,8 @@ void CXWM::gatherResources() {
839846
xcb_prefetch_extension_data(m_connection, &xcb_res_id);
840847

841848
for (auto& ATOM : HYPRATOMS) {
842-
xcb_intern_atom_cookie_t cookie = xcb_intern_atom(m_connection, 0, ATOM.first.length(), ATOM.first.c_str());
843-
using ReplyPtr = std::unique_ptr<xcb_intern_atom_reply_t, decltype(&free)>;
844-
ReplyPtr reply(xcb_intern_atom_reply(m_connection, cookie, nullptr), &free);
849+
xcb_intern_atom_cookie_t cookie = xcb_intern_atom(m_connection, 0, ATOM.first.length(), ATOM.first.c_str());
850+
XCBReplyPtr<xcb_intern_atom_reply_t> reply(xcb_intern_atom_reply(m_connection, cookie, nullptr));
845851

846852
if (!reply) {
847853
Debug::log(ERR, "[xwm] Atom failed: {}", ATOM.first);
@@ -856,29 +862,27 @@ void CXWM::gatherResources() {
856862
if (!m_xfixes || !m_xfixes->present)
857863
Debug::log(WARN, "XFixes not available");
858864

859-
xcb_xfixes_query_version_cookie_t xfixes_cookie;
860-
using ReplyPtr = std::unique_ptr<xcb_xfixes_query_version_reply_t, decltype(&free)>;
865+
auto xfixes_cookie = xcb_xfixes_query_version(m_connection, XCB_XFIXES_MAJOR_VERSION, XCB_XFIXES_MINOR_VERSION);
866+
XCBReplyPtr<xcb_xfixes_query_version_reply_t> xfixes_reply(xcb_xfixes_query_version_reply(m_connection, xfixes_cookie, nullptr));
861867

862-
xfixes_cookie = xcb_xfixes_query_version(m_connection, XCB_XFIXES_MAJOR_VERSION, XCB_XFIXES_MINOR_VERSION);
863-
ReplyPtr xfixes_reply(xcb_xfixes_query_version_reply(m_connection, xfixes_cookie, nullptr), &free);
864-
865-
Debug::log(LOG, "xfixes version: {}.{}", xfixes_reply->major_version, xfixes_reply->minor_version);
866-
m_xfixesMajor = xfixes_reply->major_version;
868+
if (xfixes_reply) {
869+
Debug::log(LOG, "xfixes version: {}.{}", xfixes_reply->major_version, xfixes_reply->minor_version);
870+
m_xfixesMajor = xfixes_reply->major_version;
871+
}
867872

868-
const xcb_query_extension_reply_t* xresReply1 = xcb_get_extension_data(m_connection, &xcb_res_id);
873+
const auto* xresReply1 = xcb_get_extension_data(m_connection, &xcb_res_id);
869874
if (!xresReply1 || !xresReply1->present)
870875
return;
871876

872-
xcb_res_query_version_cookie_t xres_cookie = xcb_res_query_version(m_connection, XCB_RES_MAJOR_VERSION, XCB_RES_MINOR_VERSION);
873-
xcb_res_query_version_reply_t* xres_reply = xcb_res_query_version_reply(m_connection, xres_cookie, nullptr);
874-
if (xres_reply == nullptr)
877+
auto xres_cookie = xcb_res_query_version(m_connection, XCB_RES_MAJOR_VERSION, XCB_RES_MINOR_VERSION);
878+
XCBReplyPtr<xcb_res_query_version_reply_t> xres_reply(xcb_res_query_version_reply(m_connection, xres_cookie, nullptr));
879+
if (!xres_reply)
875880
return;
876881

877882
Debug::log(LOG, "xres version: {}.{}", xres_reply->server_major, xres_reply->server_minor);
878883
if (xres_reply->server_major > 1 || (xres_reply->server_major == 1 && xres_reply->server_minor >= 2)) {
879884
m_xres = xresReply1;
880885
}
881-
free(xres_reply);
882886
}
883887

884888
void CXWM::getVisual() {
@@ -909,16 +913,16 @@ void CXWM::getVisual() {
909913
}
910914

911915
void CXWM::getRenderFormat() {
912-
xcb_render_query_pict_formats_cookie_t cookie = xcb_render_query_pict_formats(m_connection);
913-
using ReplyPtr = std::unique_ptr<xcb_render_query_pict_formats_reply_t, decltype(&free)>;
914-
ReplyPtr reply(xcb_render_query_pict_formats_reply(m_connection, cookie, nullptr), &free);
916+
auto cookie = xcb_render_query_pict_formats(m_connection);
917+
XCBReplyPtr<xcb_render_query_pict_formats_reply_t> reply(xcb_render_query_pict_formats_reply(m_connection, cookie, nullptr));
915918

916919
if (!reply) {
917920
Debug::log(LOG, "xwm: No xcb_render_query_pict_formats_reply_t reply");
918921
return;
919922
}
920-
xcb_render_pictforminfo_iterator_t iter = xcb_render_query_pict_formats_formats_iterator(reply.get());
921-
xcb_render_pictforminfo_t* format = nullptr;
923+
924+
auto iter = xcb_render_query_pict_formats_formats_iterator(reply.get());
925+
xcb_render_pictforminfo_t* format = nullptr;
922926
while (iter.rem > 0) {
923927
if (iter.data->depth == 32) {
924928
format = iter.data;
@@ -1105,9 +1109,8 @@ void CXWM::readWindowData(SP<CXWaylandSurface> surf) {
11051109
};
11061110

11071111
for (size_t i = 0; i < interestingProps.size(); i++) {
1108-
xcb_get_property_cookie_t cookie = xcb_get_property(m_connection, 0, surf->m_xID, interestingProps[i], XCB_ATOM_ANY, 0, 2048);
1109-
using ReplyPtr = std::unique_ptr<xcb_get_property_reply_t, decltype(&free)>;
1110-
ReplyPtr reply(xcb_get_property_reply(m_connection, cookie, nullptr), &free);
1112+
xcb_get_property_cookie_t cookie = xcb_get_property(m_connection, 0, surf->m_xID, interestingProps[i], XCB_ATOM_ANY, 0, 2048);
1113+
XCBReplyPtr<xcb_get_property_reply_t> reply(xcb_get_property_reply(m_connection, cookie, nullptr));
11111114
if (!reply) {
11121115
Debug::log(ERR, "[xwm] Failed to get window property");
11131116
continue;

0 commit comments

Comments
 (0)