2016-11-02 15:22:45 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xlib-xcb.h>
|
|
|
|
#include <xcb/xcb.h>
|
|
|
|
#include <iomanip>
|
|
|
|
|
|
|
|
#include "common.hpp"
|
2016-12-05 14:41:00 -05:00
|
|
|
#include "utils/factory.hpp"
|
2016-11-30 04:06:16 -05:00
|
|
|
#include "x11/extensions.hpp"
|
|
|
|
#include "x11/registry.hpp"
|
2016-11-02 15:22:45 -04:00
|
|
|
#include "x11/types.hpp"
|
2016-12-05 14:41:00 -05:00
|
|
|
#include "x11/xutils.hpp"
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-11-19 00:22:44 -05:00
|
|
|
POLYBAR_NS
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-11-30 04:06:16 -05:00
|
|
|
using xpp_connection = xpp::connection<XPP_EXTENSION_LIST>;
|
2016-11-02 15:22:45 -04:00
|
|
|
|
|
|
|
class connection : public xpp_connection {
|
|
|
|
public:
|
2016-12-09 03:40:46 -05:00
|
|
|
using make_type = connection&;
|
|
|
|
static make_type make();
|
2016-12-09 03:02:47 -05:00
|
|
|
|
2016-12-05 14:41:00 -05:00
|
|
|
explicit connection(xcb_connection_t* conn) : connection(conn, 0) {}
|
2016-12-03 10:44:08 -05:00
|
|
|
explicit connection(xcb_connection_t* conn, int connection_fd)
|
|
|
|
: xpp_connection(conn), m_connection_fd(connection_fd) {}
|
2016-11-02 15:22:45 -04:00
|
|
|
|
|
|
|
connection& operator=(const connection&) {
|
|
|
|
return *this;
|
|
|
|
}
|
2016-12-14 21:30:41 -05:00
|
|
|
connection(const connection& o) = delete;
|
2016-11-02 15:22:45 -04:00
|
|
|
|
|
|
|
virtual ~connection() {}
|
|
|
|
|
2016-11-26 18:46:41 -05:00
|
|
|
template <typename Event, uint32_t ResponseType>
|
|
|
|
void wait_for_response(function<bool(const Event&)> check_event) {
|
|
|
|
auto fd = get_file_descriptor();
|
|
|
|
fd_set fds;
|
|
|
|
FD_ZERO(&fds);
|
|
|
|
FD_SET(fd, &fds);
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
if (select(fd + 1, &fds, nullptr, nullptr, nullptr) > 0) {
|
|
|
|
shared_ptr<xcb_generic_event_t> evt;
|
|
|
|
|
|
|
|
if ((evt = poll_for_event()) && evt->response_type == ResponseType) {
|
|
|
|
if (check_event(reinterpret_cast<const xcb_map_notify_event_t&>(*(evt.get())))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (connection_has_error()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-02 15:22:45 -04:00
|
|
|
void preload_atoms();
|
|
|
|
void query_extensions();
|
|
|
|
|
|
|
|
string id(xcb_window_t w) const;
|
|
|
|
|
2016-12-03 10:44:31 -05:00
|
|
|
xcb_screen_t* screen(bool realloc = false);
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-11-26 18:46:41 -05:00
|
|
|
void ensure_event_mask(xcb_window_t win, uint32_t event);
|
|
|
|
void clear_event_mask(xcb_window_t win);
|
|
|
|
|
2016-11-25 02:42:31 -05:00
|
|
|
shared_ptr<xcb_client_message_event_t> make_client_message(xcb_atom_t type, xcb_window_t target) const;
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-11-25 07:55:15 -05:00
|
|
|
void send_client_message(const shared_ptr<xcb_client_message_event_t>& message, xcb_window_t target,
|
2016-11-02 15:22:45 -04:00
|
|
|
uint32_t event_mask = 0xFFFFFF, bool propagate = false) const;
|
|
|
|
|
2016-11-25 07:55:15 -05:00
|
|
|
void send_dummy_event(xcb_window_t target, uint32_t event = XCB_EVENT_MASK_STRUCTURE_NOTIFY) const;
|
2016-11-02 15:22:45 -04:00
|
|
|
|
2016-12-15 11:13:15 -05:00
|
|
|
xcb_visualtype_t* visual_type(xcb_screen_t* screen, int match_depth = 32);
|
2016-11-02 15:22:45 -04:00
|
|
|
|
|
|
|
static string error_str(int error_code);
|
|
|
|
|
|
|
|
void dispatch_event(const shared_ptr<xcb_generic_event_t>& evt) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attach sink to the registry */
|
|
|
|
template <typename Sink>
|
|
|
|
void attach_sink(Sink&& sink, registry::priority prio = 0) {
|
|
|
|
m_registry.attach(prio, forward<Sink>(sink));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Detach sink from the registry
|
|
|
|
*/
|
|
|
|
template <typename Sink>
|
|
|
|
void detach_sink(Sink&& sink, registry::priority prio = 0) {
|
|
|
|
m_registry.detach(prio, forward<Sink>(sink));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
registry m_registry{*this};
|
2016-12-03 10:44:08 -05:00
|
|
|
xcb_screen_t* m_screen{nullptr};
|
|
|
|
int m_connection_fd{0};
|
2016-11-02 15:22:45 -04:00
|
|
|
};
|
|
|
|
|
2016-11-19 00:22:44 -05:00
|
|
|
POLYBAR_NS_END
|