From b05b3a4c74f41d0bc65abc26ae40d7d56809ca85 Mon Sep 17 00:00:00 2001
From: patrick96
Date: Sun, 20 Mar 2022 14:27:05 +0100
Subject: [PATCH] xworkspaces: Deal with disappearing windows
Because the X server is asynchronous, there is no guarantee that after
reading _NET_CLIENT_LIST, all windows still exist.
For that reason we need to handle XCB_WINDOW errors appropriately.
---
CHANGELOG.md | 1 +
src/modules/xworkspaces.cpp | 14 ++++++++++++--
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a8d03049..7228f259 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `format-offset` being ignored ([`#2643`](https://github.com/polybar/polybar/pull/2643))
- Negative struts (`margin-bottom`, `margin-top`) being ignored ([`#2642`](https://github.com/polybar/polybar/issues/2642), [`#2644`](https://github.com/polybar/polybar/pull/2644))
- Positioning in awesomeWM ([`#2651`](https://github.com/polybar/polybar/pull/2651))
+- `internal/xworkspaces`: The module sometimes crashed polybar when windows were closed. ([`#2655`](https://github.com/polybar/polybar/pull/2655))
## [3.6.1] - 2022-03-05
### Build
diff --git a/src/modules/xworkspaces.cpp b/src/modules/xworkspaces.cpp
index 467e7c16..1e4dd50a 100644
--- a/src/modules/xworkspaces.cpp
+++ b/src/modules/xworkspaces.cpp
@@ -138,8 +138,18 @@ namespace modules {
for (auto&& client : newclients) {
if (m_clients.count(client) == 0) {
- // new client: listen for changes (wm_hint or desktop)
- m_connection.ensure_event_mask(client, XCB_EVENT_MASK_PROPERTY_CHANGE);
+ try {
+ // new client: listen for changes (wm_hint or desktop)
+ m_connection.ensure_event_mask(client, XCB_EVENT_MASK_PROPERTY_CHANGE);
+ } catch (const xpp::x::error::window& e) {
+ /*
+ * The "new client" may have already disappeared between reading the
+ * client list and setting the event mask.
+ * This is not a severe issue and it will eventually correct itself
+ * when a new _NET_CLIENT_LIST value is set.
+ */
+ m_log.info("%s: New client window no longer exists, ignoring...");
+ }
}
}