Cleanup xcb stuff
This commit is contained in:
parent
8db3e04727
commit
b66f920308
@ -83,7 +83,7 @@ namespace modules {
|
||||
static constexpr const char* TAG_LABEL_STATE{"<label-state>"};
|
||||
|
||||
connection& m_connection;
|
||||
ewmh_connection_t m_ewmh;
|
||||
ewmh_util::ewmh_connection& m_ewmh;
|
||||
|
||||
vector<monitor_t> m_monitors;
|
||||
|
||||
@ -106,6 +106,6 @@ namespace modules {
|
||||
bool m_revscroll{false};
|
||||
size_t m_index{0};
|
||||
};
|
||||
} // namespace modules
|
||||
} // namespace modules
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
@ -9,31 +9,7 @@ POLYBAR_NS
|
||||
template <typename T>
|
||||
using malloc_ptr_t = shared_ptr<T>;
|
||||
|
||||
namespace memory_util {
|
||||
/**
|
||||
* Create a shared pointer using malloc/free
|
||||
*
|
||||
* Generates a noexcept-type warning because the mangled name for
|
||||
* malloc_ptr_t will change in C++17. This doesn't affect use because we have
|
||||
* no public ABI, so we ignore it here.
|
||||
* See also this SO answer: https://stackoverflow.com/a/46857525/5363071
|
||||
*/
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wnoexcept-type"
|
||||
template <typename T, size_t Size = sizeof(T), typename Deleter = decltype(std::free)>
|
||||
inline malloc_ptr_t<T> make_malloc_ptr(Deleter deleter = std::free) {
|
||||
return malloc_ptr_t<T>(static_cast<T*>(calloc(1, Size)), deleter);
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
/**
|
||||
* Get the number of elements in T
|
||||
*/
|
||||
template <typename T>
|
||||
inline auto countof(T& p) {
|
||||
return sizeof(p) / sizeof(p[0]);
|
||||
}
|
||||
} // namespace memory_util
|
||||
template <typename T>
|
||||
using malloc_unique_ptr = unique_ptr<T, decltype(free)*>;
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
@ -2,13 +2,15 @@
|
||||
|
||||
#include <xcb/xcb_atom.h>
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
|
||||
struct cached_atom {
|
||||
const char* name;
|
||||
size_t len;
|
||||
xcb_atom_t* atom;
|
||||
const std::string name;
|
||||
xcb_atom_t& atom;
|
||||
};
|
||||
|
||||
extern cached_atom ATOMS[36];
|
||||
extern std::array<cached_atom, 36> ATOMS;
|
||||
|
||||
extern xcb_atom_t _NET_SUPPORTED;
|
||||
extern xcb_atom_t _NET_CURRENT_DESKTOP;
|
||||
|
@ -66,7 +66,7 @@ namespace detail {
|
||||
} catch (const shared_ptr<xcb_generic_error_t>& error) {
|
||||
check<xpp::x::extension, Extensions...>(error);
|
||||
}
|
||||
throw; // re-throw exception
|
||||
throw; // re-throw exception
|
||||
}
|
||||
|
||||
shared_ptr<xcb_generic_event_t> wait_for_special_event(xcb_special_event_t* se) const override {
|
||||
@ -75,7 +75,7 @@ namespace detail {
|
||||
} catch (const shared_ptr<xcb_generic_error_t>& error) {
|
||||
check<xpp::x::extension, Extensions...>(error);
|
||||
}
|
||||
throw; // re-throw exception
|
||||
throw; // re-throw exception
|
||||
}
|
||||
|
||||
private:
|
||||
@ -94,7 +94,7 @@ namespace detail {
|
||||
dispatcher(error);
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
} // namespace detail
|
||||
|
||||
class connection : public detail::connection_base<connection&, XPP_EXTENSION_LIST> {
|
||||
public:
|
||||
@ -122,8 +122,8 @@ class connection : public detail::connection_base<connection&, XPP_EXTENSION_LIS
|
||||
void ensure_event_mask(xcb_window_t win, unsigned int event);
|
||||
void clear_event_mask(xcb_window_t win);
|
||||
|
||||
shared_ptr<xcb_client_message_event_t> make_client_message(xcb_atom_t type, xcb_window_t target) const;
|
||||
void send_client_message(const shared_ptr<xcb_client_message_event_t>& message, xcb_window_t target,
|
||||
xcb_client_message_event_t make_client_message(xcb_atom_t type, xcb_window_t target) const;
|
||||
void send_client_message(const xcb_client_message_event_t& message, xcb_window_t target,
|
||||
unsigned int event_mask = 0xFFFFFF, bool propagate = false) const;
|
||||
|
||||
xcb_visualtype_t* visual_type(xcb_screen_t* screen, int match_depth = 32);
|
||||
|
@ -4,15 +4,25 @@
|
||||
|
||||
#include "common.hpp"
|
||||
#include "utils/memory.hpp"
|
||||
#include "utils/mixins.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
struct position;
|
||||
|
||||
using ewmh_connection_t = malloc_ptr_t<xcb_ewmh_connection_t>;
|
||||
|
||||
namespace ewmh_util {
|
||||
ewmh_connection_t initialize();
|
||||
class ewmh_connection : public non_copyable_mixin, public non_movable_mixin {
|
||||
public:
|
||||
ewmh_connection();
|
||||
~ewmh_connection();
|
||||
|
||||
xcb_ewmh_connection_t* get();
|
||||
|
||||
private:
|
||||
xcb_ewmh_connection_t c;
|
||||
};
|
||||
|
||||
ewmh_connection& initialize();
|
||||
|
||||
bool supports(xcb_atom_t atom, int screen = 0);
|
||||
|
||||
@ -42,6 +52,6 @@ namespace ewmh_util {
|
||||
void set_wm_window_opacity(xcb_window_t win, unsigned long int values);
|
||||
|
||||
vector<xcb_window_t> get_client_list(int screen = 0);
|
||||
}
|
||||
} // namespace ewmh_util
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
@ -170,8 +170,8 @@ void controller::conn_cb() {
|
||||
return;
|
||||
}
|
||||
|
||||
shared_ptr<xcb_generic_event_t> evt{};
|
||||
while ((evt = shared_ptr<xcb_generic_event_t>(xcb_poll_for_event(m_connection), free)) != nullptr) {
|
||||
malloc_ptr_t<xcb_generic_event_t> evt{};
|
||||
while ((evt = malloc_ptr_t<xcb_generic_event_t>(xcb_poll_for_event(m_connection), free)) != nullptr) {
|
||||
try {
|
||||
m_connection.dispatch_event(evt);
|
||||
} catch (xpp::connection_error& err) {
|
||||
|
@ -63,9 +63,7 @@ namespace modules {
|
||||
xwindow_module::xwindow_module(const bar_settings& bar, string name_)
|
||||
: static_module<xwindow_module>(bar, move(name_)), m_connection(connection::make()) {
|
||||
// Initialize ewmh atoms
|
||||
if ((ewmh_util::initialize()) == nullptr) {
|
||||
throw module_error("Failed to initialize ewmh atoms");
|
||||
}
|
||||
ewmh_util::initialize();
|
||||
|
||||
// Check if the WM supports _NET_ACTIVE_WINDOW
|
||||
if (!ewmh_util::supports(_NET_ACTIVE_WINDOW)) {
|
||||
@ -133,6 +131,6 @@ namespace modules {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace modules
|
||||
} // namespace modules
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
@ -18,7 +18,7 @@ namespace {
|
||||
inline bool operator==(const position& a, const position& b) {
|
||||
return a.x + a.y == b.x + b.y;
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
/**
|
||||
* Defines a lexicographical order on position
|
||||
@ -34,7 +34,9 @@ namespace modules {
|
||||
* Construct module
|
||||
*/
|
||||
xworkspaces_module::xworkspaces_module(const bar_settings& bar, string name_)
|
||||
: static_module<xworkspaces_module>(bar, move(name_)), m_connection(connection::make()) {
|
||||
: static_module<xworkspaces_module>(bar, move(name_))
|
||||
, m_connection(connection::make())
|
||||
, m_ewmh(ewmh_util::initialize()) {
|
||||
m_router->register_action_with_data(EVENT_FOCUS, [this](const std::string& data) { action_focus(data); });
|
||||
m_router->register_action(EVENT_NEXT, [this]() { action_next(); });
|
||||
m_router->register_action(EVENT_PREV, [this]() { action_prev(); });
|
||||
@ -45,11 +47,6 @@ namespace modules {
|
||||
m_scroll = m_conf.get(name(), "enable-scroll", m_scroll);
|
||||
m_revscroll = m_conf.get(name(), "reverse-scroll", m_revscroll);
|
||||
|
||||
// Initialize ewmh atoms
|
||||
if ((m_ewmh = ewmh_util::initialize()) == nullptr) {
|
||||
throw module_error("Failed to initialize ewmh atoms");
|
||||
}
|
||||
|
||||
// Add formats and elements
|
||||
m_formatter->add(DEFAULT_FORMAT, TAG_LABEL_STATE, {TAG_LABEL_STATE, TAG_LABEL_MONITOR});
|
||||
|
||||
@ -79,7 +76,8 @@ namespace modules {
|
||||
if (vec.size() == 2) {
|
||||
m_icons->add(vec[0], std::make_shared<label>(vec[1]));
|
||||
} else {
|
||||
m_log.err("%s: Ignoring icon-%d because it has %s semicolons", name(), i, vec.size() > 2? "too many" : "too few");
|
||||
m_log.err(
|
||||
"%s: Ignoring icon-%d because it has %s semicolons", name(), i, vec.size() > 2 ? "too many" : "too few");
|
||||
}
|
||||
|
||||
i++;
|
||||
@ -107,15 +105,15 @@ namespace modules {
|
||||
* Handler for XCB_PROPERTY_NOTIFY events
|
||||
*/
|
||||
void xworkspaces_module::handle(const evt::property_notify& evt) {
|
||||
if (evt->atom == m_ewmh->_NET_CLIENT_LIST || evt->atom == m_ewmh->_NET_WM_DESKTOP) {
|
||||
if (evt->atom == m_ewmh.get()->_NET_CLIENT_LIST || evt->atom == m_ewmh.get()->_NET_WM_DESKTOP) {
|
||||
rebuild_clientlist();
|
||||
rebuild_desktop_states();
|
||||
} else if (evt->atom == m_ewmh->_NET_DESKTOP_NAMES || evt->atom == m_ewmh->_NET_NUMBER_OF_DESKTOPS) {
|
||||
} else if (evt->atom == m_ewmh.get()->_NET_DESKTOP_NAMES || evt->atom == m_ewmh.get()->_NET_NUMBER_OF_DESKTOPS) {
|
||||
m_desktop_names = get_desktop_names();
|
||||
rebuild_desktops();
|
||||
rebuild_clientlist();
|
||||
rebuild_desktop_states();
|
||||
} else if (evt->atom == m_ewmh->_NET_CURRENT_DESKTOP) {
|
||||
} else if (evt->atom == m_ewmh.get()->_NET_CURRENT_DESKTOP) {
|
||||
update_current_desktop();
|
||||
rebuild_desktop_states();
|
||||
} else if (evt->atom == WM_HINTS) {
|
||||
@ -417,6 +415,6 @@ namespace modules {
|
||||
m_log.info("%s: Ignoring change to current desktop", name());
|
||||
}
|
||||
}
|
||||
} // namespace modules
|
||||
} // namespace modules
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
@ -41,42 +41,42 @@ xcb_atom_t _NET_WM_WINDOW_OPACITY;
|
||||
xcb_atom_t WM_HINTS;
|
||||
|
||||
// clang-format off
|
||||
cached_atom ATOMS[36] = {
|
||||
{"_NET_SUPPORTED", sizeof("_NET_SUPPORTED") - 1, &_NET_SUPPORTED},
|
||||
{"_NET_CURRENT_DESKTOP", sizeof("_NET_CURRENT_DESKTOP") - 1, &_NET_CURRENT_DESKTOP},
|
||||
{"_NET_ACTIVE_WINDOW", sizeof("_NET_ACTIVE_WINDOW") - 1, &_NET_ACTIVE_WINDOW},
|
||||
{"_NET_WM_NAME", sizeof("_NET_WM_NAME") - 1, &_NET_WM_NAME},
|
||||
{"_NET_WM_DESKTOP", sizeof("_NET_WM_DESKTOP") - 1, &_NET_WM_DESKTOP},
|
||||
{"_NET_WM_VISIBLE_NAME", sizeof("_NET_WM_VISIBLE_NAME") - 1, &_NET_WM_VISIBLE_NAME},
|
||||
{"_NET_WM_WINDOW_TYPE", sizeof("_NET_WM_WINDOW_TYPE") - 1, &_NET_WM_WINDOW_TYPE},
|
||||
{"_NET_WM_WINDOW_TYPE_DOCK", sizeof("_NET_WM_WINDOW_TYPE_DOCK") - 1, &_NET_WM_WINDOW_TYPE_DOCK},
|
||||
{"_NET_WM_WINDOW_TYPE_NORMAL", sizeof("_NET_WM_WINDOW_TYPE_NORMAL") - 1, &_NET_WM_WINDOW_TYPE_NORMAL},
|
||||
{"_NET_WM_PID", sizeof("_NET_WM_PID") - 1, &_NET_WM_PID},
|
||||
{"_NET_WM_STATE", sizeof("_NET_WM_STATE") - 1, &_NET_WM_STATE},
|
||||
{"_NET_WM_STATE_STICKY", sizeof("_NET_WM_STATE_STICKY") - 1, &_NET_WM_STATE_STICKY},
|
||||
{"_NET_WM_STATE_SKIP_TASKBAR", sizeof("_NET_WM_STATE_SKIP_TASKBAR") - 1, &_NET_WM_STATE_SKIP_TASKBAR},
|
||||
{"_NET_WM_STATE_ABOVE", sizeof("_NET_WM_STATE_ABOVE") - 1, &_NET_WM_STATE_ABOVE},
|
||||
{"_NET_WM_STATE_MAXIMIZED_VERT", sizeof("_NET_WM_STATE_MAXIMIZED_VERT") - 1, &_NET_WM_STATE_MAXIMIZED_VERT},
|
||||
{"_NET_WM_STRUT", sizeof("_NET_WM_STRUT") - 1, &_NET_WM_STRUT},
|
||||
{"_NET_WM_STRUT_PARTIAL", sizeof("_NET_WM_STRUT_PARTIAL") - 1, &_NET_WM_STRUT_PARTIAL},
|
||||
{"WM_PROTOCOLS", sizeof("WM_PROTOCOLS") - 1, &WM_PROTOCOLS},
|
||||
{"WM_DELETE_WINDOW", sizeof("WM_DELETE_WINDOW") - 1, &WM_DELETE_WINDOW},
|
||||
{"_XEMBED", sizeof("_XEMBED") - 1, &_XEMBED},
|
||||
{"_XEMBED_INFO", sizeof("_XEMBED_INFO") - 1, &_XEMBED_INFO},
|
||||
{"MANAGER", sizeof("MANAGER") - 1, &MANAGER},
|
||||
{"WM_STATE", sizeof("WM_STATE") - 1, &WM_STATE},
|
||||
{"_NET_SYSTEM_TRAY_OPCODE", sizeof("_NET_SYSTEM_TRAY_OPCODE") - 1, &_NET_SYSTEM_TRAY_OPCODE},
|
||||
{"_NET_SYSTEM_TRAY_ORIENTATION", sizeof("_NET_SYSTEM_TRAY_ORIENTATION") - 1, &_NET_SYSTEM_TRAY_ORIENTATION},
|
||||
{"_NET_SYSTEM_TRAY_VISUAL", sizeof("_NET_SYSTEM_TRAY_VISUAL") - 1, &_NET_SYSTEM_TRAY_VISUAL},
|
||||
{"_NET_SYSTEM_TRAY_COLORS", sizeof("_NET_SYSTEM_TRAY_COLORS") - 1, &_NET_SYSTEM_TRAY_COLORS},
|
||||
{"WM_TAKE_FOCUS", sizeof("WM_TAKE_FOCUS") - 1, &WM_TAKE_FOCUS},
|
||||
{"Backlight", sizeof("Backlight") - 1, &Backlight},
|
||||
{"BACKLIGHT", sizeof("BACKLIGHT") - 1, &BACKLIGHT},
|
||||
{"_XROOTPMAP_ID", sizeof("_XROOTPMAP_ID") - 1, &_XROOTPMAP_ID},
|
||||
{"_XSETROOT_ID", sizeof("_XSETROOT_ID") - 1, &_XSETROOT_ID},
|
||||
{"ESETROOT_PMAP_ID", sizeof("ESETROOT_PMAP_ID") - 1, &ESETROOT_PMAP_ID},
|
||||
{"_COMPTON_SHADOW", sizeof("_COMPTON_SHADOW") - 1, &_COMPTON_SHADOW},
|
||||
{"_NET_WM_WINDOW_OPACITY", sizeof("_NET_WM_WINDOW_OPACITY") - 1, &_NET_WM_WINDOW_OPACITY},
|
||||
{"WM_HINTS", sizeof("WM_HINTS") - 1, &WM_HINTS},
|
||||
};
|
||||
std::array<cached_atom, 36> ATOMS = {{
|
||||
{"_NET_SUPPORTED", _NET_SUPPORTED},
|
||||
{"_NET_CURRENT_DESKTOP", _NET_CURRENT_DESKTOP},
|
||||
{"_NET_ACTIVE_WINDOW", _NET_ACTIVE_WINDOW},
|
||||
{"_NET_WM_NAME", _NET_WM_NAME},
|
||||
{"_NET_WM_DESKTOP", _NET_WM_DESKTOP},
|
||||
{"_NET_WM_VISIBLE_NAME", _NET_WM_VISIBLE_NAME},
|
||||
{"_NET_WM_WINDOW_TYPE", _NET_WM_WINDOW_TYPE},
|
||||
{"_NET_WM_WINDOW_TYPE_DOCK", _NET_WM_WINDOW_TYPE_DOCK},
|
||||
{"_NET_WM_WINDOW_TYPE_NORMAL", _NET_WM_WINDOW_TYPE_NORMAL},
|
||||
{"_NET_WM_PID", _NET_WM_PID},
|
||||
{"_NET_WM_STATE", _NET_WM_STATE},
|
||||
{"_NET_WM_STATE_STICKY", _NET_WM_STATE_STICKY},
|
||||
{"_NET_WM_STATE_SKIP_TASKBAR", _NET_WM_STATE_SKIP_TASKBAR},
|
||||
{"_NET_WM_STATE_ABOVE", _NET_WM_STATE_ABOVE},
|
||||
{"_NET_WM_STATE_MAXIMIZED_VERT", _NET_WM_STATE_MAXIMIZED_VERT},
|
||||
{"_NET_WM_STRUT", _NET_WM_STRUT},
|
||||
{"_NET_WM_STRUT_PARTIAL", _NET_WM_STRUT_PARTIAL},
|
||||
{"WM_PROTOCOLS", WM_PROTOCOLS},
|
||||
{"WM_DELETE_WINDOW", WM_DELETE_WINDOW},
|
||||
{"_XEMBED", _XEMBED},
|
||||
{"_XEMBED_INFO", _XEMBED_INFO},
|
||||
{"MANAGER", MANAGER},
|
||||
{"WM_STATE", WM_STATE},
|
||||
{"_NET_SYSTEM_TRAY_OPCODE", _NET_SYSTEM_TRAY_OPCODE},
|
||||
{"_NET_SYSTEM_TRAY_ORIENTATION", _NET_SYSTEM_TRAY_ORIENTATION},
|
||||
{"_NET_SYSTEM_TRAY_VISUAL", _NET_SYSTEM_TRAY_VISUAL},
|
||||
{"_NET_SYSTEM_TRAY_COLORS", _NET_SYSTEM_TRAY_COLORS},
|
||||
{"WM_TAKE_FOCUS", WM_TAKE_FOCUS},
|
||||
{"Backlight", Backlight},
|
||||
{"BACKLIGHT", BACKLIGHT},
|
||||
{"_XROOTPMAP_ID", _XROOTPMAP_ID},
|
||||
{"_XSETROOT_ID", _XSETROOT_ID},
|
||||
{"ESETROOT_PMAP_ID", ESETROOT_PMAP_ID},
|
||||
{"_COMPTON_SHADOW", _COMPTON_SHADOW},
|
||||
{"_NET_WM_WINDOW_OPACITY", _NET_WM_WINDOW_OPACITY},
|
||||
{"WM_HINTS", WM_HINTS},
|
||||
}};
|
||||
// clang-format on
|
||||
|
@ -1,3 +1,5 @@
|
||||
#include "x11/connection.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iomanip>
|
||||
|
||||
@ -6,7 +8,6 @@
|
||||
#include "utils/memory.hpp"
|
||||
#include "utils/string.hpp"
|
||||
#include "x11/atoms.hpp"
|
||||
#include "x11/connection.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
@ -19,25 +20,21 @@ connection::make_type connection::make(xcb_connection_t* conn, int default_scree
|
||||
}
|
||||
|
||||
connection::connection(xcb_connection_t* c, int default_screen) : base_type(c, default_screen) {
|
||||
// Preload required xcb atoms {{{
|
||||
|
||||
vector<xcb_intern_atom_cookie_t> cookies(memory_util::countof(ATOMS));
|
||||
xcb_intern_atom_reply_t* reply{nullptr};
|
||||
// Preload required xcb atoms
|
||||
vector<xcb_intern_atom_cookie_t> cookies(ATOMS.size());
|
||||
|
||||
for (size_t i = 0; i < cookies.size(); i++) {
|
||||
cookies[i] = xcb_intern_atom_unchecked(*this, false, ATOMS[i].len, ATOMS[i].name);
|
||||
cookies[i] = xcb_intern_atom_unchecked(*this, false, ATOMS[i].name.size(), ATOMS[i].name.data());
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < cookies.size(); i++) {
|
||||
if ((reply = xcb_intern_atom_reply(*this, cookies[i], nullptr)) != nullptr) {
|
||||
*ATOMS[i].atom = reply->atom;
|
||||
malloc_unique_ptr<xcb_intern_atom_reply_t> reply(xcb_intern_atom_reply(*this, cookies[i], nullptr), free);
|
||||
if (reply) {
|
||||
ATOMS[i].atom = reply->atom;
|
||||
}
|
||||
|
||||
free(reply);
|
||||
}
|
||||
|
||||
// }}}
|
||||
// Query for X extensions {{{
|
||||
// Query for X extensions
|
||||
#if WITH_XRANDR
|
||||
randr_util::query_extension(*this);
|
||||
#endif
|
||||
@ -47,7 +44,6 @@ connection::connection(xcb_connection_t* c, int default_screen) : base_type(c, d
|
||||
#if WITH_XKB
|
||||
xkb_util::query_extension(*this);
|
||||
#endif
|
||||
// }}}
|
||||
}
|
||||
|
||||
connection::~connection() {
|
||||
@ -108,20 +104,19 @@ void connection::clear_event_mask(xcb_window_t win) {
|
||||
/**
|
||||
* Creates an instance of shared_ptr<xcb_client_message_event_t>
|
||||
*/
|
||||
shared_ptr<xcb_client_message_event_t> connection::make_client_message(xcb_atom_t type, xcb_window_t target) const {
|
||||
auto client_message = memory_util::make_malloc_ptr<xcb_client_message_event_t, 32_z>();
|
||||
xcb_client_message_event_t connection::make_client_message(xcb_atom_t type, xcb_window_t target) const {
|
||||
xcb_client_message_event_t client_message;
|
||||
client_message.response_type = XCB_CLIENT_MESSAGE;
|
||||
client_message.format = 32;
|
||||
client_message.type = type;
|
||||
client_message.window = target;
|
||||
|
||||
client_message->response_type = XCB_CLIENT_MESSAGE;
|
||||
client_message->format = 32;
|
||||
client_message->type = type;
|
||||
client_message->window = target;
|
||||
|
||||
client_message->sequence = 0;
|
||||
client_message->data.data32[0] = 0;
|
||||
client_message->data.data32[1] = 0;
|
||||
client_message->data.data32[2] = 0;
|
||||
client_message->data.data32[3] = 0;
|
||||
client_message->data.data32[4] = 0;
|
||||
client_message.sequence = 0;
|
||||
client_message.data.data32[0] = 0;
|
||||
client_message.data.data32[1] = 0;
|
||||
client_message.data.data32[2] = 0;
|
||||
client_message.data.data32[3] = 0;
|
||||
client_message.data.data32[4] = 0;
|
||||
|
||||
return client_message;
|
||||
}
|
||||
@ -129,9 +124,9 @@ shared_ptr<xcb_client_message_event_t> connection::make_client_message(xcb_atom_
|
||||
/**
|
||||
* Send client message event
|
||||
*/
|
||||
void connection::send_client_message(const shared_ptr<xcb_client_message_event_t>& message, xcb_window_t target,
|
||||
unsigned int event_mask, bool propagate) const {
|
||||
send_event(propagate, target, event_mask, reinterpret_cast<const char*>(&*message));
|
||||
void connection::send_client_message(
|
||||
const xcb_client_message_event_t& message, xcb_window_t target, unsigned int event_mask, bool propagate) const {
|
||||
send_event(propagate, target, event_mask, reinterpret_cast<const char*>(&message));
|
||||
flush();
|
||||
}
|
||||
|
||||
@ -156,13 +151,13 @@ xcb_visualtype_t* connection::visual_type(xcb_screen_t* screen, int match_depth)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
xcb_visualtype_t* connection::visual_type_for_id(xcb_screen_t* screen, xcb_visualid_t visual_id) {
|
||||
xcb_depth_iterator_t depth_iter = xcb_screen_allowed_depths_iterator(screen);
|
||||
if (depth_iter.data) {
|
||||
for (; depth_iter.rem; xcb_depth_next(&depth_iter)) {
|
||||
for (auto it = xcb_depth_visuals_iterator(depth_iter.data); it.rem; xcb_visualtype_next(&it)) {
|
||||
if(it.data->visual_id == visual_id) return it.data;
|
||||
if (it.data->visual_id == visual_id)
|
||||
return it.data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,31 @@
|
||||
#include "x11/ewmh.hpp"
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "components/types.hpp"
|
||||
#include "utils/string.hpp"
|
||||
#include "x11/atoms.hpp"
|
||||
#include "x11/connection.hpp"
|
||||
#include "x11/ewmh.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
namespace ewmh_util {
|
||||
ewmh_connection_t g_connection{nullptr};
|
||||
ewmh_connection_t initialize() {
|
||||
if (!g_connection) {
|
||||
g_connection = memory_util::make_malloc_ptr<xcb_ewmh_connection_t>(
|
||||
[=](xcb_ewmh_connection_t* c) { xcb_ewmh_connection_wipe(c); });
|
||||
xcb_ewmh_init_atoms_replies(&*g_connection, xcb_ewmh_init_atoms(connection::make(), &*g_connection), nullptr);
|
||||
}
|
||||
return g_connection;
|
||||
|
||||
ewmh_connection::ewmh_connection() {
|
||||
xcb_ewmh_init_atoms_replies(&c, xcb_ewmh_init_atoms(connection::make(), &c), nullptr);
|
||||
}
|
||||
|
||||
ewmh_connection::~ewmh_connection() {
|
||||
xcb_ewmh_connection_wipe(&c);
|
||||
}
|
||||
|
||||
xcb_ewmh_connection_t* ewmh_connection::get() {
|
||||
return &c;
|
||||
}
|
||||
|
||||
ewmh_connection& initialize() {
|
||||
static ewmh_connection c;
|
||||
return c;
|
||||
}
|
||||
|
||||
bool supports(xcb_atom_t atom, int screen) {
|
||||
@ -180,6 +189,6 @@ namespace ewmh_util {
|
||||
}
|
||||
return {};
|
||||
}
|
||||
}
|
||||
} // namespace ewmh_util
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
@ -105,20 +105,20 @@ void tray_client::reconfigure(int x, int y) const {
|
||||
* Respond to client resize requests
|
||||
*/
|
||||
void tray_client::configure_notify(int x, int y) const {
|
||||
auto notify = memory_util::make_malloc_ptr<xcb_configure_notify_event_t, 32_z>();
|
||||
notify->response_type = XCB_CONFIGURE_NOTIFY;
|
||||
notify->event = m_window;
|
||||
notify->window = m_window;
|
||||
notify->override_redirect = false;
|
||||
notify->above_sibling = 0;
|
||||
notify->x = x;
|
||||
notify->y = y;
|
||||
notify->width = m_width;
|
||||
notify->height = m_height;
|
||||
notify->border_width = 0;
|
||||
xcb_configure_notify_event_t notify;
|
||||
notify.response_type = XCB_CONFIGURE_NOTIFY;
|
||||
notify.event = m_window;
|
||||
notify.window = m_window;
|
||||
notify.override_redirect = false;
|
||||
notify.above_sibling = 0;
|
||||
notify.x = x;
|
||||
notify.y = y;
|
||||
notify.width = m_width;
|
||||
notify.height = m_height;
|
||||
notify.border_width = 0;
|
||||
|
||||
unsigned int mask{XCB_EVENT_MASK_STRUCTURE_NOTIFY};
|
||||
m_connection.send_event_checked(false, m_window, mask, reinterpret_cast<const char*>(notify.get()));
|
||||
m_connection.send_event_checked(false, m_window, mask, reinterpret_cast<const char*>(¬ify));
|
||||
}
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
@ -702,9 +702,9 @@ void tray_manager::notify_clients() {
|
||||
if (m_activated) {
|
||||
m_log.info("Notifying pending tray clients");
|
||||
auto message = m_connection.make_client_message(MANAGER, m_connection.root());
|
||||
message->data.data32[0] = XCB_CURRENT_TIME;
|
||||
message->data.data32[1] = m_atom;
|
||||
message->data.data32[2] = m_tray;
|
||||
message.data.data32[0] = XCB_CURRENT_TIME;
|
||||
message.data.data32[1] = m_atom;
|
||||
message.data.data32[2] = m_tray;
|
||||
m_connection.send_client_message(message, m_connection.root());
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "x11/xembed.hpp"
|
||||
|
||||
#include "errors.hpp"
|
||||
#include "x11/atoms.hpp"
|
||||
|
||||
@ -46,11 +47,11 @@ namespace xembed {
|
||||
*/
|
||||
void send_message(connection& conn, xcb_window_t target, long message, long d1, long d2, long d3) {
|
||||
auto msg = conn.make_client_message(_XEMBED, target);
|
||||
msg->data.data32[0] = XCB_CURRENT_TIME;
|
||||
msg->data.data32[1] = message;
|
||||
msg->data.data32[2] = d1;
|
||||
msg->data.data32[3] = d2;
|
||||
msg->data.data32[4] = d3;
|
||||
msg.data.data32[0] = XCB_CURRENT_TIME;
|
||||
msg.data.data32[1] = message;
|
||||
msg.data.data32[2] = d1;
|
||||
msg.data.data32[3] = d2;
|
||||
msg.data.data32[4] = d3;
|
||||
conn.send_client_message(msg, target);
|
||||
}
|
||||
|
||||
@ -59,8 +60,8 @@ namespace xembed {
|
||||
*/
|
||||
void send_focus_event(connection& conn, xcb_window_t target) {
|
||||
auto msg = conn.make_client_message(WM_PROTOCOLS, target);
|
||||
msg->data.data32[0] = WM_TAKE_FOCUS;
|
||||
msg->data.data32[1] = XCB_CURRENT_TIME;
|
||||
msg.data.data32[0] = WM_TAKE_FOCUS;
|
||||
msg.data.data32[1] = XCB_CURRENT_TIME;
|
||||
conn.send_client_message(msg, target);
|
||||
}
|
||||
|
||||
@ -110,6 +111,6 @@ namespace xembed {
|
||||
// invalid window
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace xembed
|
||||
|
||||
POLYBAR_NS_END
|
||||
|
@ -52,7 +52,6 @@ add_unit_test(utils/color)
|
||||
add_unit_test(utils/command)
|
||||
add_unit_test(utils/env)
|
||||
add_unit_test(utils/math)
|
||||
add_unit_test(utils/memory)
|
||||
add_unit_test(utils/scope)
|
||||
add_unit_test(utils/string)
|
||||
add_unit_test(utils/file)
|
||||
|
@ -1,23 +0,0 @@
|
||||
#include "common/test.hpp"
|
||||
#include "utils/memory.hpp"
|
||||
|
||||
using namespace polybar;
|
||||
|
||||
struct mytype {
|
||||
int x, y, z;
|
||||
};
|
||||
|
||||
TEST(Memory, makeMallocPtr) {
|
||||
auto ptr = memory_util::make_malloc_ptr<mytype>();
|
||||
EXPECT_EQ(sizeof(mytype*), sizeof(ptr.get()));
|
||||
ptr.reset();
|
||||
EXPECT_EQ(nullptr, ptr.get());
|
||||
}
|
||||
|
||||
TEST(Memory, countof) {
|
||||
mytype A[3]{{}, {}, {}};
|
||||
mytype B[8]{{}, {}, {}, {}, {}, {}, {}, {}};
|
||||
|
||||
EXPECT_EQ(memory_util::countof(A), size_t{3});
|
||||
EXPECT_EQ(memory_util::countof(B), size_t{8});
|
||||
}
|
Loading…
Reference in New Issue
Block a user