diff --git a/README.md b/README.md index 8eb51aad..2cf2ba00 100644 --- a/README.md +++ b/README.md @@ -698,6 +698,11 @@ See [the bspwm module](#module-internalbspwm) for details on `label-dimmed`. ; Limit the amount of chars to output for each workspace name ; Default: 0 wsname-maxlen = 2 + + ; Sort the workspaces by index instead of the default + ; sorting that groups the workspaces by output + ; Default: false + index-sort = true ~~~ ##### Extra formatting (example) diff --git a/include/modules/i3.hpp b/include/modules/i3.hpp index 3d4fa778..5231c570 100644 --- a/include/modules/i3.hpp +++ b/include/modules/i3.hpp @@ -59,6 +59,7 @@ namespace modules { void setup() { // Load configuration values {{{ + GET_CONFIG_VALUE(name(), m_indexsort, "index-sort"); GET_CONFIG_VALUE(name(), m_pinworkspaces, "pin-workspaces"); GET_CONFIG_VALUE(name(), m_wsname_maxlen, "wsname-maxlen"); @@ -127,6 +128,7 @@ namespace modules { try { auto workspaces = ipc.get_workspaces(); + vector> sorted = workspaces; string focused_output; bool output_unfocused = false; @@ -139,7 +141,16 @@ namespace modules { if (focused_output != m_bar.monitor->name) output_unfocused = true; - for (auto&& workspace : workspaces) { + if (m_indexsort) { + using ws_t = shared_ptr; + // clang-format off + sort(sorted.begin(), sorted.end(), [](ws_t ws1, ws_t ws2){ + return ws1->num < ws2->num; + }); + // clang-format on + } + + for (auto&& workspace : sorted) { if (m_pinworkspaces && workspace->output != m_bar.monitor->name) continue; @@ -226,6 +237,7 @@ namespace modules { vector m_workspaces; iconset_t m_icons; + bool m_indexsort = false; bool m_pinworkspaces = false; size_t m_wsname_maxlen = 0;