From f7a755799cfa850bf5f4c2e0b8dc2fc5d63c692a Mon Sep 17 00:00:00 2001 From: Tony Zorman Date: Tue, 28 Feb 2023 21:12:35 +0100 Subject: [PATCH] feat(xworkspaces): Add group-by-monitor flag MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By default, we group workspaces by monitor with the help of _NET_DESKTOP_VIEWPORT. However, some users may experience this as an unpredictable "shuffling" of workspaces. While WMs could disable advertising the property itself, it seems more sensible to handle this at the level of polybar. Hence, introduce a new group-by-monitor flag—defaulting to true—which can be used to disable this behaviour. Closes: https://github.com/polybar/polybar/issues/2603 Related: https://github.com/xmonad/xmonad-contrib/pull/791 Related: https://github.com/qtile/qtile/issues/3375 Co-authored-by: scaramangado --- CHANGELOG.md | 1 + include/modules/xworkspaces.hpp | 1 + src/modules/xworkspaces.cpp | 10 ++++++++-- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fee042b..396540c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `wm-restack`: - `bottom`: lowers polybar to the bottom of the window stack (same as the previous behavior of `generic`) ([`#2961`](https://github.com/polybar/polybar/pull/2961)) - `ewmh`: Tries to use the `_NET_SUPPORTING_WM_CHECK` hint to position the bar ([`#2961`](https://github.com/polybar/polybar/pull/2961)) +- `internal/xworkspaces`: `group-by-monitor` setting to decide whether `_NET_DESKTOP_VIEWPORT` should be used to group workspaces by monitor; ([`#2603`](https://github.com/polybar/polybar/issues/2603), [`#2926`](https://github.com/polybar/polybar/pull/2926)) by [@slotThe](https://github.com/slotThe/). ### Changed - `custom/script`: diff --git a/include/modules/xworkspaces.hpp b/include/modules/xworkspaces.hpp index 578f5337..cc261784 100644 --- a/include/modules/xworkspaces.hpp +++ b/include/modules/xworkspaces.hpp @@ -105,6 +105,7 @@ namespace modules { bool m_click{true}; bool m_scroll{true}; bool m_revscroll{false}; + bool m_group_by_monitor{true}; size_t m_index{0}; }; } // namespace modules diff --git a/src/modules/xworkspaces.cpp b/src/modules/xworkspaces.cpp index 85037835..57a6fef2 100644 --- a/src/modules/xworkspaces.cpp +++ b/src/modules/xworkspaces.cpp @@ -40,12 +40,16 @@ namespace modules { m_click = m_conf.get(name(), "enable-click", m_click); m_scroll = m_conf.get(name(), "enable-scroll", m_scroll); m_revscroll = m_conf.get(name(), "reverse-scroll", m_revscroll); + m_group_by_monitor = m_conf.get(name(), "group-by-monitor", m_group_by_monitor); // Add formats and elements m_formatter->add(DEFAULT_FORMAT, TAG_LABEL_STATE, {TAG_LABEL_STATE, TAG_LABEL_MONITOR}); if (m_formatter->has(TAG_LABEL_MONITOR)) { m_monitorlabel = load_optional_label(m_conf, name(), "label-monitor", DEFAULT_LABEL_MONITOR); + if (m_monitorlabel && !m_group_by_monitor) { + throw module_error("Cannot use label-monitor when not grouping by monitor"); + } } if (m_formatter->has(TAG_LABEL_STATE)) { @@ -188,7 +192,9 @@ namespace modules { /* * Stores the _NET_DESKTOP_VIEWPORT hint * - * For WMs that don't support that hint, we store an empty vector + * For WMs that don't support that hint, or if the user explicitly + * disables support via the configuration file, we store an empty + * vector. * * The vector will be padded/reduced to _NET_NUMBER_OF_DESKTOPS. * All desktops which aren't explicitly assigned a postion will be @@ -197,7 +203,7 @@ namespace modules { * We use this to map workspaces to viewports, desktop i is at position * ws_positions[i]. */ - vector ws_positions = ewmh_util::get_desktop_viewports(); + vector ws_positions = m_group_by_monitor ? ewmh_util::get_desktop_viewports() : vector(); auto num_desktops = m_desktop_names.size();