From 7521da900fd2b463ffa0282206e8625d93f9cd54 Mon Sep 17 00:00:00 2001 From: Bruno Cooper Date: Mon, 4 Jan 2021 03:17:27 -0600 Subject: [PATCH] Add support for %nwin% in xworkspaces label (#2329) %nwin% tells the number of windows in a workspace --- CHANGELOG.md | 3 +++ include/modules/xworkspaces.hpp | 1 + src/modules/xworkspaces.cpp | 3 +++ 3 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c89f3b37..53b72a20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -70,6 +70,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `internal/network`: `interface-type` may be used in place of `interface` to automatically select a network interface ([`#2025`](https://github.com/polybar/polybar/pull/2025)) +- `internal/xworkspaces`: `%nwin%` can be used to display the number of open + windows per workspace + ([`#604`](https://github.com/polybar/polybar/issues/604)) ### Changed - Slight changes to the value ranges the different ramp levels are responsible diff --git a/include/modules/xworkspaces.hpp b/include/modules/xworkspaces.hpp index 3a32f131..97a42dbf 100644 --- a/include/modules/xworkspaces.hpp +++ b/include/modules/xworkspaces.hpp @@ -99,6 +99,7 @@ namespace modules { * Maps an xcb window to its desktop number */ map m_clients; + map m_windows; vector> m_viewports; map m_labels; label_t m_monitorlabel; diff --git a/src/modules/xworkspaces.cpp b/src/modules/xworkspaces.cpp index 7a6cc954..29b0101e 100644 --- a/src/modules/xworkspaces.cpp +++ b/src/modules/xworkspaces.cpp @@ -144,9 +144,11 @@ namespace modules { // rebuild entire mapping of clients to desktops m_clients.clear(); + m_windows.clear(); for (auto&& client : newclients) { auto desk = ewmh_util::get_desktop_from_window(client); m_clients[client] = desk; + m_windows[desk]++; } rebuild_urgent_hints(); @@ -270,6 +272,7 @@ namespace modules { d->label->reset_tokens(); d->label->replace_token("%index%", to_string(d->index + 1)); d->label->replace_token("%name%", m_desktop_names[d->index]); + d->label->replace_token("%nwin%", to_string(m_windows[d->index])); d->label->replace_token("%icon%", m_icons->get(m_desktop_names[d->index], DEFAULT_ICON)->get()); } }