Repository: hyprwm/Hyprland
File: src/xwayland/XWM.cpp (C++)

Code before:
}

void CXWM::selectionSendNotify(xcb_selection_request_event_t* e, bool success) {
    xcb_selection_notify_event_t selection_notify = {
        .response_type = XCB_SELECTION_NOTIFY,
        .sequence      = 0,
        .time          = e->time,
        .requestor     = e->requestor,
        .selection     = e->selection,
        .target        = e->target,
        .property      = success ? e->property : (uint32_t)XCB_ATOM_NONE,
    };

    xcb_send_event(m_connection, 0, e->requestor, XCB_EVENT_MASK_NO_EVENT, (const char*)&selection_notify);
    xcb_flush(m_connection);
}

xcb_atom_t CXWM::mimeToAtom(const std::string& mime) {
    if (mime == "text/plain;charset=utf-8")
        return HYPRATOMS["UTF8_STRING"];
    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<xcb_intern_atom_reply_t, decltype(&free)>;
    ReplyPtr reply(xcb_intern_atom_reply(m_connection, cookie, nullptr), &free);
    if (!reply.get())
        return XCB_ATOM_NONE;
    xcb_atom_t atom = reply->atom;

    return atom;
}

std::string CXWM::mimeFromAtom(xcb_atom_t atom) {
    if (atom == HYPRATOMS["UTF8_STRING"])
        return "text/plain;charset=utf-8";
    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<xcb_get_atom_name_reply_t, decltype(&free)>;
    ReplyPtr reply(xcb_get_atom_name_reply(m_connection, cookie, nullptr), &free);
    if (!reply)
        return "INVALID";
    size_t      len = xcb_get_atom_name_name_length(reply.get());
    char*       buf = xcb_get_atom_name_name(reply.get()); // not a C string
    std::string SZNAME{buf, len};
    return SZNAME;
}

void CXWM::handleSelectionNotify(xcb_selection_notify_event_t* e) {

Review comment (suggestion):
By the way, you don't have to store pointer to 'free' in the unique_ptr if you use own deleter type.

Like this
```cpp
#include <cstdlib>
#include <iostream>
#include <memory>

struct CFree {
  void operator()(void *ptr) { std::free(ptr); }
};

int main(int argc, char *argv[]) {
  std::unique_ptr<int, CFree> reply(static_cast<int *>(malloc(sizeof(int))));

  std::cout << sizeof(std::unique_ptr<int, CFree>) << '\n';                // 8
  std::cout << sizeof(std::unique_ptr<int, decltype(&std::free)>) << '\n'; // 16

  return 0;
}
```

Code after:
    if (!error_name) {
        Debug::log(ERR, "xcb error happened, but could not get error name");
        return;
    }

    Debug::log(ERR, "[xwm] xcb error: {} ({}), code {} ({}), seq {}, val {}", major_name, minor_name ? minor_name : "no minor", error_name, extension ? extension : "no extension",
               e->sequence, e->bad_value);
}

void CXWM::selectionSendNotify(xcb_selection_request_event_t* e, bool success) {
    xcb_selection_notify_event_t selection_notify = {
        .response_type = XCB_SELECTION_NOTIFY,
        .sequence      = 0,
        .time          = e->time,
        .requestor     = e->requestor,
        .selection     = e->selection,
        .target        = e->target,
        .property      = success ? e->property : (uint32_t)XCB_ATOM_NONE,
    };

    xcb_send_event(m_connection, 0, e->requestor, XCB_EVENT_MASK_NO_EVENT, (const char*)&selection_notify);
    xcb_flush(m_connection);
}

xcb_atom_t CXWM::mimeToAtom(const std::string& mime) {
    if (mime == "text/plain;charset=utf-8")
        return HYPRATOMS["UTF8_STRING"];
    if (mime == "text/plain")
        return HYPRATOMS["TEXT"];

    xcb_intern_atom_cookie_t             cookie = xcb_intern_atom(m_connection, 0, mime.length(), mime.c_str());
    XCBReplyPtr<xcb_intern_atom_reply_t> reply(xcb_intern_atom_reply(m_connection, cookie, nullptr));
    if (!reply.get())
        return XCB_ATOM_NONE;
    xcb_atom_t atom = reply->atom;

    return atom;
}

std::string CXWM::mimeFromAtom(xcb_atom_t atom) {
    if (atom == HYPRATOMS["UTF8_STRING"])
        return "text/plain;charset=utf-8";
    if (atom == HYPRATOMS["TEXT"])
        return "text/plain";

    xcb_get_atom_name_cookie_t             cookie = xcb_get_atom_name(m_connection, atom);
    XCBReplyPtr<xcb_get_atom_name_reply_t> 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());
    char*       buf = xcb_get_atom_name_name(reply.get()); // not a C string