Do not use reverse-scroll for prev/next actions

The next action should always select the next workspace, the same for
prev.

reverse-scroll should be directly used when setting the scroll actions.

This changes the behavior of `prev` and `next` actions in the i3 and
bspwm module.
But I don't think the impact will be significant and the old behavior
was misleading anyway.
This commit is contained in:
patrick96 2020-11-20 00:16:39 +01:00 committed by Patrick Ziegler
parent 5e64361ed8
commit 658ed6974d
2 changed files with 23 additions and 30 deletions

View File

@ -1,14 +1,14 @@
#include "modules/bspwm.hpp"
#include <sys/socket.h>
#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<bspwm_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

View File

@ -1,13 +1,13 @@
#include "modules/i3.hpp"
#include <sys/socket.h>
#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));