diff --git a/src/components/screen.cpp b/src/components/screen.cpp index 4f2bb1df..dbbddc06 100644 --- a/src/components/screen.cpp +++ b/src/components/screen.cpp @@ -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([&](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); diff --git a/src/main.cpp b/src/main.cpp index 4a5c86b1..85c902f3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -47,7 +47,7 @@ int main(int argc, char** argv) { XInitThreads(); // Store the xcb connection pointer with a disconnect deleter - shared_ptr xcbconn{xutils::get_connection(), xutils::xcb_connection_deleter{}}; + unique_ptr 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 diff --git a/src/x11/connection.cpp b/src/x11/connection.cpp index 7034466b..fae4ec7c 100644 --- a/src/x11/connection.cpp +++ b/src/x11/connection.cpp @@ -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); } /**