20
20
#include " ../managers/ANRManager.hpp"
21
21
#include " ../protocols/XWaylandShell.hpp"
22
22
#include " ../protocols/core/Compositor.hpp"
23
+ using Hyprutils::Memory::CUniquePointer;
24
+
23
25
using namespace Hyprutils ::OS;
24
26
25
27
#define XCB_EVENT_RESPONSE_TYPE_MASK 0x7f
@@ -29,6 +31,15 @@ static int onX11Event(int fd, uint32_t mask, void* data) {
29
31
return g_pXWayland->m_wm ->onEvent (fd, mask);
30
32
}
31
33
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
+
32
43
SP<CXWaylandSurface> CXWM::windowForXID (xcb_window_t wid) {
33
44
for (auto const & s : m_surfaces) {
34
45
if (s->m_xID == wid)
@@ -182,9 +193,8 @@ std::string CXWM::getAtomName(uint32_t atom) {
182
193
}
183
194
184
195
// 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 ));
188
198
189
199
if (!reply)
190
200
return " Unknown" ;
@@ -332,9 +342,8 @@ void CXWM::handlePropertyNotify(xcb_property_notify_event_t* e) {
332
342
if (!XSURF)
333
343
return ;
334
344
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 ));
338
347
339
348
if (!reply) {
340
349
Debug::log (ERR, " [xwm] Failed to read property notify cookie" );
@@ -573,12 +582,11 @@ xcb_atom_t CXWM::mimeToAtom(const std::string& mime) {
573
582
if (mime == " text/plain" )
574
583
return HYPRATOMS[" TEXT" ];
575
584
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 ));
579
587
if (!reply.get ())
580
588
return XCB_ATOM_NONE;
581
- xcb_atom_t atom = reply. get () ->atom ;
589
+ xcb_atom_t atom = reply->atom ;
582
590
583
591
return atom;
584
592
}
@@ -589,9 +597,8 @@ std::string CXWM::mimeFromAtom(xcb_atom_t atom) {
589
597
if (atom == HYPRATOMS[" TEXT" ])
590
598
return " text/plain" ;
591
599
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 ));
595
602
if (!reply)
596
603
return " INVALID" ;
597
604
size_t len = xcb_get_atom_name_name_length (reply.get ());
@@ -839,9 +846,8 @@ void CXWM::gatherResources() {
839
846
xcb_prefetch_extension_data (m_connection, &xcb_res_id);
840
847
841
848
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 ));
845
851
846
852
if (!reply) {
847
853
Debug::log (ERR, " [xwm] Atom failed: {}" , ATOM.first );
@@ -856,29 +862,27 @@ void CXWM::gatherResources() {
856
862
if (!m_xfixes || !m_xfixes->present )
857
863
Debug::log (WARN, " XFixes not available" );
858
864
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 )) ;
861
867
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
+ }
867
872
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);
869
874
if (!xresReply1 || !xresReply1->present )
870
875
return ;
871
876
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)
875
880
return ;
876
881
877
882
Debug::log (LOG, " xres version: {}.{}" , xres_reply->server_major , xres_reply->server_minor );
878
883
if (xres_reply->server_major > 1 || (xres_reply->server_major == 1 && xres_reply->server_minor >= 2 )) {
879
884
m_xres = xresReply1;
880
885
}
881
- free (xres_reply);
882
886
}
883
887
884
888
void CXWM::getVisual () {
@@ -909,16 +913,16 @@ void CXWM::getVisual() {
909
913
}
910
914
911
915
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 ));
915
918
916
919
if (!reply) {
917
920
Debug::log (LOG, " xwm: No xcb_render_query_pict_formats_reply_t reply" );
918
921
return ;
919
922
}
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 ;
922
926
while (iter.rem > 0 ) {
923
927
if (iter.data ->depth == 32 ) {
924
928
format = iter.data ;
@@ -1105,9 +1109,8 @@ void CXWM::readWindowData(SP<CXWaylandSurface> surf) {
1105
1109
};
1106
1110
1107
1111
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 ));
1111
1114
if (!reply) {
1112
1115
Debug::log (ERR, " [xwm] Failed to get window property" );
1113
1116
continue ;
0 commit comments