refactor(connection): Listen for property notify by default

This commit is contained in:
Michael Carlberg 2016-12-23 01:05:36 +01:00
parent 9479b5abe2
commit d4e3891ab6
3 changed files with 13 additions and 8 deletions

View File

@ -48,9 +48,14 @@ screen::screen(connection& conn, signal_emitter& emitter, const logger& logger,
<< cw_flush(true);
// clang-format on
// Update the root windows event mask
auto attributes = m_connection.get_window_attributes(m_root);
auto root_mask = attributes->your_event_mask;
attributes->your_event_mask = attributes->your_event_mask | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY;
m_connection.change_window_attributes(m_root, XCB_CW_EVENT_MASK, &attributes->your_event_mask);
// Receive randr events
m_connection.randr().select_input(m_proxy, XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE);
m_connection.ensure_event_mask(m_root, XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY);
// Create window used as event proxy
m_connection.map_window(m_proxy);
@ -59,7 +64,9 @@ screen::screen(connection& conn, signal_emitter& emitter, const logger& logger,
// Wait until the proxy window has been mapped
using evt = xcb_map_notify_event_t;
m_connection.wait_for_response<evt, XCB_MAP_NOTIFY>([&](const evt* evt) -> bool { return evt->window == m_proxy; });
m_connection.clear_event_mask(m_root);
// Restore the root windows event mask
m_connection.change_window_attributes(m_root, XCB_CW_EVENT_MASK, &root_mask);
// Finally attach the sink the process randr events
m_connection.attach_sink(this, SINK_PRIORITY_SCREEN);

View File

@ -47,7 +47,7 @@ int main(int argc, char** argv) {
XInitThreads();
// Store the xcb connection pointer with a disconnect deleter
shared_ptr<xcb_connection_t> xcbconn{xutils::get_connection(), xutils::xcb_connection_deleter{}};
unique_ptr<xcb_connection_t, xutils::xcb_connection_deleter> xcbconn{xutils::get_connection()};
if (!xcbconn) {
logger.err("A connection to X could not be established... ");
@ -57,6 +57,7 @@ int main(int argc, char** argv) {
connection& conn{connection::make(&*xcbconn)};
conn.preload_atoms();
conn.query_extensions();
conn.ensure_event_mask(conn.root(), XCB_EVENT_MASK_PROPERTY_CHANGE);
//==================================================
// Parse command line arguments

View File

@ -87,11 +87,8 @@ xcb_screen_t* connection::screen(bool realloc) {
*/
void connection::ensure_event_mask(xcb_window_t win, uint32_t event) {
auto attributes = get_window_attributes(win);
uint32_t mask{attributes->your_event_mask | event};
if (!(attributes->your_event_mask & event)) {
change_window_attributes(win, XCB_CW_EVENT_MASK, &mask);
}
attributes->your_event_mask = attributes->your_event_mask | event;
change_window_attributes(win, XCB_CW_EVENT_MASK, &attributes->your_event_mask);
}
/**