diff --git a/include/utils/memory.hpp b/include/utils/memory.hpp index 547400ef..c5af2765 100644 --- a/include/utils/memory.hpp +++ b/include/utils/memory.hpp @@ -8,9 +8,9 @@ namespace memory_util { /** * Create a shared pointer using malloc/free */ - template - inline auto make_malloc_ptr(size_t size = sizeof(T)) { - return shared_ptr(static_cast(malloc(size)), free); + template + inline auto make_malloc_ptr(size_t size = sizeof(T), Deleter deleter = free) { + return shared_ptr(static_cast(malloc(size)), deleter); } /** diff --git a/include/x11/ewmh.hpp b/include/x11/ewmh.hpp index 64a9898b..4b75b9ef 100644 --- a/include/x11/ewmh.hpp +++ b/include/x11/ewmh.hpp @@ -15,7 +15,6 @@ namespace ewmh_util { extern ewmh_connection_t g_ewmh_connection; ewmh_connection_t initialize(); - void dealloc(); bool supports(xcb_ewmh_connection_t* ewmh, xcb_atom_t atom, int screen = 0); diff --git a/src/x11/ewmh.cpp b/src/x11/ewmh.cpp index aaa5e126..8c579223 100644 --- a/src/x11/ewmh.cpp +++ b/src/x11/ewmh.cpp @@ -1,5 +1,5 @@ -#include "components/types.hpp" #include "x11/ewmh.hpp" +#include "components/types.hpp" #include "x11/xutils.hpp" POLYBAR_NS @@ -9,19 +9,16 @@ namespace ewmh_util { ewmh_connection_t initialize() { if (!g_ewmh_connection) { - g_ewmh_connection = memory_util::make_malloc_ptr(); + g_ewmh_connection = memory_util::make_malloc_ptr( + sizeof(xcb_ewmh_connection_t), bind(xcb_ewmh_connection_wipe, std::placeholders::_1)); + auto* xconn = xutils::get_connection(); auto* conn = g_ewmh_connection.get(); + xcb_ewmh_init_atoms_replies(conn, xcb_ewmh_init_atoms(xconn, conn), nullptr); } - return g_ewmh_connection; - } - void dealloc() { - if (g_ewmh_connection) { - xcb_ewmh_connection_wipe(g_ewmh_connection.get()); - g_ewmh_connection.reset(); - } + return g_ewmh_connection; } bool supports(xcb_ewmh_connection_t* ewmh, xcb_atom_t atom, int screen) { @@ -98,7 +95,8 @@ namespace ewmh_util { } for (size_t n = 0; n < reply.desktop_viewport_len; n++) { - viewports.emplace_back(position{static_cast(reply.desktop_viewport[n].x), static_cast(reply.desktop_viewport[n].y)}); + viewports.emplace_back(position{ + static_cast(reply.desktop_viewport[n].x), static_cast(reply.desktop_viewport[n].y)}); } return viewports;