From cba62e7b8e1e50383b27253b2df3870fc1050bbb Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Wed, 12 Oct 2016 04:14:06 +0200 Subject: [PATCH] feat(i3): Added option to sort by workspaces by index --- README.md | 5 +++++ include/modules/i3.hpp | 14 +++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) 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;