mirror of https://github.com/polybar/polybar.git
refactor(connection): Listen for property notify by default
This commit is contained in:
parent
9479b5abe2
commit
d4e3891ab6
|
@ -48,9 +48,14 @@ screen::screen(connection& conn, signal_emitter& emitter, const logger& logger,
|
||||||
<< cw_flush(true);
|
<< cw_flush(true);
|
||||||
// clang-format on
|
// 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
|
// Receive randr events
|
||||||
m_connection.randr().select_input(m_proxy, XCB_RANDR_NOTIFY_MASK_SCREEN_CHANGE);
|
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
|
// Create window used as event proxy
|
||||||
m_connection.map_window(m_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
|
// Wait until the proxy window has been mapped
|
||||||
using evt = xcb_map_notify_event_t;
|
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.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
|
// Finally attach the sink the process randr events
|
||||||
m_connection.attach_sink(this, SINK_PRIORITY_SCREEN);
|
m_connection.attach_sink(this, SINK_PRIORITY_SCREEN);
|
||||||
|
|
|
@ -47,7 +47,7 @@ int main(int argc, char** argv) {
|
||||||
XInitThreads();
|
XInitThreads();
|
||||||
|
|
||||||
// Store the xcb connection pointer with a disconnect deleter
|
// 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) {
|
if (!xcbconn) {
|
||||||
logger.err("A connection to X could not be established... ");
|
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)};
|
connection& conn{connection::make(&*xcbconn)};
|
||||||
conn.preload_atoms();
|
conn.preload_atoms();
|
||||||
conn.query_extensions();
|
conn.query_extensions();
|
||||||
|
conn.ensure_event_mask(conn.root(), XCB_EVENT_MASK_PROPERTY_CHANGE);
|
||||||
|
|
||||||
//==================================================
|
//==================================================
|
||||||
// Parse command line arguments
|
// Parse command line arguments
|
||||||
|
|
|
@ -87,11 +87,8 @@ xcb_screen_t* connection::screen(bool realloc) {
|
||||||
*/
|
*/
|
||||||
void connection::ensure_event_mask(xcb_window_t win, uint32_t event) {
|
void connection::ensure_event_mask(xcb_window_t win, uint32_t event) {
|
||||||
auto attributes = get_window_attributes(win);
|
auto attributes = get_window_attributes(win);
|
||||||
uint32_t mask{attributes->your_event_mask | event};
|
attributes->your_event_mask = attributes->your_event_mask | event;
|
||||||
|
change_window_attributes(win, XCB_CW_EVENT_MASK, &attributes->your_event_mask);
|
||||||
if (!(attributes->your_event_mask & event)) {
|
|
||||||
change_window_attributes(win, XCB_CW_EVENT_MASK, &mask);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue