2016-11-02 19:22:45 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <X11/X.h>
|
|
|
|
#include <X11/Xlib-xcb.h>
|
|
|
|
#include <xcb/xcb.h>
|
2016-11-25 07:42:31 +00:00
|
|
|
#include <boost/optional.hpp>
|
2016-11-02 19:22:45 +00:00
|
|
|
#include <iomanip>
|
|
|
|
#include <xpp/xpp.hpp>
|
|
|
|
|
|
|
|
#include "common.hpp"
|
|
|
|
#include "x11/types.hpp"
|
|
|
|
|
2016-11-26 14:42:48 +00:00
|
|
|
#if ENABLE_DAMAGE_EXT
|
2016-11-20 22:04:31 +00:00
|
|
|
#include "x11/damage.hpp"
|
|
|
|
#endif
|
2016-11-26 14:42:48 +00:00
|
|
|
#if ENABLE_RENDER_EXT
|
2016-11-20 22:04:31 +00:00
|
|
|
#include "x11/render.hpp"
|
|
|
|
#endif
|
2016-11-26 14:42:48 +00:00
|
|
|
#if ENABLE_RANDR_EXT
|
2016-11-26 05:13:20 +00:00
|
|
|
#include "x11/randr.hpp"
|
|
|
|
#endif
|
2016-11-26 14:42:48 +00:00
|
|
|
#if ENABLE_SYNC_EXT
|
|
|
|
#include "x11/sync.hpp"
|
|
|
|
#endif
|
|
|
|
#if ENABLE_COMPOSITE_EXT
|
|
|
|
#include "x11/composite.hpp"
|
|
|
|
#endif
|
2016-11-20 22:04:31 +00:00
|
|
|
|
2016-11-19 05:22:44 +00:00
|
|
|
POLYBAR_NS
|
2016-11-02 19:22:45 +00:00
|
|
|
|
|
|
|
using xpp_connection = xpp::connection<
|
2016-11-26 14:42:48 +00:00
|
|
|
#if ENABLE_DAMAGE_EXT
|
2016-11-02 19:22:45 +00:00
|
|
|
xpp::damage::extension
|
|
|
|
#endif
|
2016-11-26 14:42:48 +00:00
|
|
|
#if ENABLE_RANDR_EXT
|
|
|
|
#if ENABLE_DAMAGE_EXT
|
2016-11-02 19:22:45 +00:00
|
|
|
,
|
|
|
|
#endif
|
|
|
|
xpp::randr::extension
|
|
|
|
#endif
|
2016-11-26 14:42:48 +00:00
|
|
|
#if ENABLE_RENDER_EXT
|
|
|
|
#if (ENABLE_RANDR_EXT || ENABLE_DAMAGE_EXT)
|
2016-11-02 19:22:45 +00:00
|
|
|
,
|
|
|
|
#endif
|
|
|
|
xpp::render::extension
|
2016-11-26 14:42:48 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLE_SYNC_EXT
|
|
|
|
#if (ENABLE_RANDR_EXT || ENABLE_DAMAGE_EXT || ENABLE_RENDER_EXT)
|
|
|
|
,
|
|
|
|
#endif
|
|
|
|
xpp::sync::extension
|
|
|
|
#endif
|
|
|
|
#if ENABLE_COMPOSITE_EXT
|
|
|
|
#if (ENABLE_RANDR_EXT || ENABLE_DAMAGE_EXT || ENABLE_RENDER_EXT || ENABLE_SYNC_EXT)
|
|
|
|
,
|
|
|
|
#endif
|
|
|
|
xpp::composite::extension
|
2016-11-02 19:22:45 +00:00
|
|
|
#endif
|
|
|
|
>;
|
|
|
|
|
|
|
|
class connection : public xpp_connection {
|
|
|
|
public:
|
|
|
|
explicit connection() {}
|
|
|
|
explicit connection(xcb_connection_t* conn) : xpp_connection(conn) {}
|
|
|
|
|
|
|
|
connection& operator=(const connection&) {
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~connection() {}
|
|
|
|
|
2016-11-26 23:46:41 +00: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 19:22:45 +00:00
|
|
|
void preload_atoms();
|
|
|
|
|
|
|
|
void query_extensions();
|
|
|
|
|
|
|
|
string id(xcb_window_t w) const;
|
|
|
|
|
|
|
|
xcb_screen_t* screen();
|
|
|
|
|
2016-11-26 23:46:41 +00:00
|
|
|
void ensure_event_mask(xcb_window_t win, uint32_t event);
|
|
|
|
void clear_event_mask(xcb_window_t win);
|
|
|
|
|
2016-11-25 07:42:31 +00:00
|
|
|
shared_ptr<xcb_client_message_event_t> make_client_message(xcb_atom_t type, xcb_window_t target) const;
|
2016-11-02 19:22:45 +00:00
|
|
|
|
2016-11-25 12:55:15 +00:00
|
|
|
void send_client_message(const shared_ptr<xcb_client_message_event_t>& message, xcb_window_t target,
|
2016-11-02 19:22:45 +00:00
|
|
|
uint32_t event_mask = 0xFFFFFF, bool propagate = false) const;
|
|
|
|
|
2016-11-25 12:55:15 +00:00
|
|
|
void send_dummy_event(xcb_window_t target, uint32_t event = XCB_EVENT_MASK_STRUCTURE_NOTIFY) const;
|
2016-11-02 19:22:45 +00:00
|
|
|
|
2016-11-20 22:04:31 +00:00
|
|
|
boost::optional<xcb_visualtype_t*> visual_type(xcb_screen_t* screen, int match_depth = 32);
|
2016-11-02 19:22:45 +00: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};
|
|
|
|
xcb_screen_t* m_screen = nullptr;
|
|
|
|
};
|
|
|
|
|
2016-11-20 22:04:31 +00:00
|
|
|
di::injector<connection&> configure_connection();
|
2016-11-02 19:22:45 +00:00
|
|
|
|
2016-11-19 05:22:44 +00:00
|
|
|
POLYBAR_NS_END
|