fix(xworkspaces): Segfault for wrong _NET_CURRENT_DESKTOP

While it shouldn't happen with compliant WMs, it was possibe to crash
polybar with _NET_CURRENT_DESKTOP >= _NET_NUMBER_OF_DESKTOPS and this
should not be possible.

Includes polybar/xpp#31
Fixes #2398
This commit is contained in:
patrick96 2021-03-03 21:55:43 +01:00 committed by Patrick Ziegler
parent c197cff511
commit 2fd6d20999
3 changed files with 13 additions and 5 deletions

View File

@ -71,6 +71,7 @@ namespace modules {
void rebuild_urgent_hints();
void rebuild_desktops();
void rebuild_desktop_states();
void update_current_desktop();
void action_focus(const string& data);
void action_next();

@ -1 +1 @@
Subproject commit 4d67025cdbcc7f3c65d1a620c97a8443e0a08129
Subproject commit 7a9960bbb912f0ed66929c978aaeb1c30acf4bfd

View File

@ -95,8 +95,7 @@ namespace modules {
// Get desktop details
m_desktop_names = get_desktop_names();
m_current_desktop = ewmh_util::get_current_desktop();
m_current_desktop_name = m_desktop_names[m_current_desktop];
update_current_desktop();
rebuild_desktops();
@ -105,6 +104,15 @@ namespace modules {
rebuild_desktop_states();
}
void xworkspaces_module::update_current_desktop() {
m_current_desktop = ewmh_util::get_current_desktop();
if (m_current_desktop < m_desktop_names.size()) {
m_current_desktop_name = m_desktop_names[m_current_desktop];
} else {
throw module_error("The current desktop is outside of the number of desktops reported by the WM");
}
}
/**
* Handler for XCB_PROPERTY_NOTIFY events
*/
@ -120,8 +128,7 @@ namespace modules {
rebuild_clientlist();
rebuild_desktop_states();
} else if (evt->atom == m_ewmh->_NET_CURRENT_DESKTOP) {
m_current_desktop = ewmh_util::get_current_desktop();
m_current_desktop_name = m_desktop_names[m_current_desktop];
update_current_desktop();
rebuild_desktop_states();
} else if (evt->atom == WM_HINTS) {
rebuild_urgent_hints();