polybar/src/x11/xutils.cpp

74 lines
2.2 KiB
C++
Raw Normal View History

2016-11-26 05:13:20 +00:00
#include <xcb/xcb.h>
#include "components/config.hpp"
#include "utils/memory.hpp"
2016-11-25 07:42:31 +00:00
#include "x11/atoms.hpp"
2016-11-04 17:54:33 +00:00
#include "x11/connection.hpp"
2016-11-02 19:22:45 +00:00
#include "x11/xlib.hpp"
2016-11-26 05:13:20 +00:00
#include "x11/xutils.hpp"
2016-06-15 03:32:35 +00:00
2016-11-19 05:22:44 +00:00
POLYBAR_NS
2016-06-15 03:32:35 +00:00
namespace xutils {
2016-12-03 15:44:08 +00:00
shared_ptr<int> g_connection_fd;
shared_ptr<xcb_connection_t> g_connection_ptr;
shared_ptr<xcb_connection_t> get_connection() {
2016-12-03 15:44:08 +00:00
if (!g_connection_ptr) {
shared_ptr<Display> dsp{xlib::get_display()};
2016-12-03 15:44:08 +00:00
if (dsp) {
XSetEventQueueOwner(dsp.get(), XCBOwnsEventQueue);
g_connection_ptr = shared_ptr<xcb_connection_t>(XGetXCBConnection(dsp.get()), factory_util::null_deleter);
2016-11-25 12:55:15 +00:00
}
2016-06-15 03:32:35 +00:00
}
2016-12-03 15:44:08 +00:00
return g_connection_ptr;
2016-12-03 15:44:08 +00:00
}
int get_connection_fd() {
if (!g_connection_fd) {
auto fd = xcb_get_file_descriptor(get_connection().get());
g_connection_fd = shared_ptr<int>(new int{fd}, factory_util::fd_deleter);
2016-12-03 15:44:08 +00:00
}
return *g_connection_fd.get();
2016-06-15 03:32:35 +00:00
}
2016-11-02 19:22:45 +00:00
void pack_values(uint32_t mask, const uint32_t* src, uint32_t* dest) {
2016-11-04 17:54:33 +00:00
for (; mask; mask >>= 1, src++) {
if (mask & 1) {
2016-06-15 03:32:35 +00:00
*dest++ = *src;
2016-11-04 17:54:33 +00:00
}
}
2016-06-15 03:32:35 +00:00
}
2016-11-02 19:22:45 +00:00
void pack_values(uint32_t mask, const xcb_params_cw_t* src, uint32_t* dest) {
xutils::pack_values(mask, reinterpret_cast<const uint32_t*>(src), dest);
}
void pack_values(uint32_t mask, const xcb_params_gc_t* src, uint32_t* dest) {
2016-06-15 03:32:35 +00:00
xutils::pack_values(mask, reinterpret_cast<const uint32_t*>(src), dest);
}
2016-11-04 17:54:33 +00:00
void pack_values(uint32_t mask, const xcb_params_configure_window_t* src, uint32_t* dest) {
2016-06-15 03:32:35 +00:00
xutils::pack_values(mask, reinterpret_cast<const uint32_t*>(src), dest);
}
2016-11-04 17:54:33 +00:00
void visibility_notify(connection& conn, const xcb_window_t& win, xcb_visibility_t state) {
auto notify = memory_util::make_malloc_ptr<xcb_visibility_notify_event_t>(32);
notify->response_type = XCB_VISIBILITY_NOTIFY;
notify->window = win;
notify->state = state;
const char* data = reinterpret_cast<const char*>(notify.get());
conn.send_event(true, win, XCB_EVENT_MASK_NO_EVENT, data);
}
void compton_shadow_exclude(connection& conn, const xcb_window_t& win) {
2016-11-26 05:13:20 +00:00
const uint32_t shadow{0};
conn.change_property(XCB_PROP_MODE_REPLACE, win, _COMPTON_SHADOW, XCB_ATOM_CARDINAL, 32, 1, &shadow);
}
2016-06-15 03:32:35 +00:00
}
2016-11-19 05:22:44 +00:00
POLYBAR_NS_END