diff --git a/src/modules/bspwm.cpp b/src/modules/bspwm.cpp index 4e85eb6f..f78dde5d 100644 --- a/src/modules/bspwm.cpp +++ b/src/modules/bspwm.cpp @@ -1,14 +1,14 @@ +#include "modules/bspwm.hpp" + #include #include "drawtypes/iconset.hpp" #include "drawtypes/label.hpp" -#include "modules/bspwm.hpp" +#include "modules/meta/base.inl" #include "utils/factory.hpp" #include "utils/file.hpp" #include "utils/string.hpp" -#include "modules/meta/base.inl" - POLYBAR_NS namespace { @@ -35,7 +35,7 @@ namespace { } return (base & mask) == mask; } -} +} // namespace namespace modules { template class module; @@ -396,13 +396,13 @@ namespace modules { size_t workspace_n{0U}; if (m_scroll) { - builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_PREV, ""); - builder->action(mousebtn::SCROLL_UP, *this, EVENT_NEXT, ""); + builder->action(mousebtn::SCROLL_DOWN, *this, m_revscroll ? EVENT_NEXT : EVENT_PREV, ""); + builder->action(mousebtn::SCROLL_UP, *this, m_revscroll ? EVENT_PREV : EVENT_NEXT, ""); } for (auto&& ws : m_monitors[m_index]->workspaces) { if (ws.second.get()) { - if(workspace_n != 0 && *m_labelseparator) { + if (workspace_n != 0 && *m_labelseparator) { builder->node(m_labelseparator); } @@ -476,9 +476,9 @@ namespace modules { string scrolldir; if (action == EVENT_NEXT) { - scrolldir = m_revscroll ? "prev" : "next"; + scrolldir = "next"; } else if (action == EVENT_PREV) { - scrolldir = m_revscroll ? "next" : "prev"; + scrolldir = "prev"; } else { return false; } @@ -495,11 +495,10 @@ namespace modules { } } - send_command("desktop -f " + scrolldir + modifier, "Sending desktop " + scrolldir + " command to ipc handler"); return true; } -} +} // namespace modules POLYBAR_NS_END diff --git a/src/modules/i3.cpp b/src/modules/i3.cpp index f7d970c6..43d175cb 100644 --- a/src/modules/i3.cpp +++ b/src/modules/i3.cpp @@ -1,13 +1,13 @@ +#include "modules/i3.hpp" + #include #include "drawtypes/iconset.hpp" #include "drawtypes/label.hpp" -#include "modules/i3.hpp" +#include "modules/meta/base.inl" #include "utils/factory.hpp" #include "utils/file.hpp" -#include "modules/meta/base.inl" - POLYBAR_NS namespace modules { @@ -183,8 +183,8 @@ namespace modules { builder->node(m_modelabel); } else if (tag == TAG_LABEL_STATE && !m_workspaces.empty()) { if (m_scroll) { - builder->action(mousebtn::SCROLL_DOWN, *this, EVENT_PREV, ""); - builder->action(mousebtn::SCROLL_UP, *this, EVENT_NEXT, ""); + builder->action(mousebtn::SCROLL_DOWN, *this, m_revscroll ? EVENT_NEXT : EVENT_PREV, ""); + builder->action(mousebtn::SCROLL_UP, *this, m_revscroll ? EVENT_PREV : EVENT_NEXT, ""); } bool first = true; @@ -193,10 +193,9 @@ namespace modules { * The separator should only be inserted in between the workspaces, so * we insert it in front of all workspaces except the first one. */ - if(first) { + if (first) { first = false; - } - else if (*m_labelseparator) { + } else if (*m_labelseparator) { builder->node(m_labelseparator); } @@ -228,33 +227,28 @@ namespace modules { return true; } - string scrolldir; - - if (action == EVENT_NEXT) { - scrolldir = m_revscroll ? "prev" : "next"; - } else if (action == EVENT_PREV) { - scrolldir = m_revscroll ? "next" : "prev"; - } else { + if (action != EVENT_NEXT && action != EVENT_PREV) { return false; } + bool next = action == EVENT_NEXT; + auto workspaces = i3_util::workspaces(conn, m_bar.monitor->name); - auto current_ws = find_if(workspaces.begin(), workspaces.end(), - [](auto ws) { return ws->visible; }); + auto current_ws = std::find_if(workspaces.begin(), workspaces.end(), [](auto ws) { return ws->visible; }); if (current_ws == workspaces.end()) { m_log.warn("%s: Current workspace not found", name()); return false; } - if (scrolldir == "next" && (m_wrap || next(current_ws) != workspaces.end())) { + if (next && (m_wrap || std::next(current_ws) != workspaces.end())) { if (!(*current_ws)->focused) { m_log.info("%s: Sending workspace focus command to ipc handler", name()); conn.send_command(make_workspace_command((*current_ws)->name)); } m_log.info("%s: Sending workspace next_on_output command to ipc handler", name()); conn.send_command("workspace next_on_output"); - } else if (scrolldir == "prev" && (m_wrap || current_ws != workspaces.begin())) { + } else if (!next && (m_wrap || current_ws != workspaces.begin())) { if (!(*current_ws)->focused) { m_log.info("%s: Sending workspace focus command to ipc handler", name()); conn.send_command(make_workspace_command((*current_ws)->name));