Add support for %nwin% in xworkspaces label (#2329)

%nwin% tells the number of windows in a workspace
This commit is contained in:
Bruno Cooper 2021-01-04 03:17:27 -06:00 committed by GitHub
parent f7c2d83ef2
commit 7521da900f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 0 deletions

View File

@ -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

View File

@ -99,6 +99,7 @@ namespace modules {
* Maps an xcb window to its desktop number
*/
map<xcb_window_t, unsigned int> m_clients;
map<unsigned int, unsigned int> m_windows;
vector<unique_ptr<viewport>> m_viewports;
map<desktop_state, label_t> m_labels;
label_t m_monitorlabel;

View File

@ -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());
}
}