fix(i3): Handle scrolling internally #503
This commit is contained in:
parent
f6ff8a0ca2
commit
db0ab78d62
@ -198,18 +198,20 @@ namespace modules {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
using namespace i3_util;
|
const i3_util::connection_t conn{};
|
||||||
|
|
||||||
string scrolldir;
|
|
||||||
const connection_t conn{};
|
|
||||||
|
|
||||||
if (cmd.compare(0, strlen(EVENT_CLICK), EVENT_CLICK) == 0) {
|
if (cmd.compare(0, strlen(EVENT_CLICK), EVENT_CLICK) == 0) {
|
||||||
cmd.erase(0, strlen(EVENT_CLICK));
|
cmd.erase(0, strlen(EVENT_CLICK));
|
||||||
if (focused_workspace(conn)->num != atoi(cmd.c_str())) {
|
if (i3_util::focused_workspace(conn)->num != atoi(cmd.c_str())) {
|
||||||
m_log.info("%s: Sending workspace focus command to ipc handler", name());
|
m_log.info("%s: Sending workspace focus command to ipc handler", name());
|
||||||
conn.send_command("workspace number " + cmd);
|
conn.send_command("workspace number " + cmd);
|
||||||
}
|
}
|
||||||
} else if (cmd.compare(0, strlen(EVENT_SCROLL_UP), EVENT_SCROLL_UP) == 0) {
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
string scrolldir;
|
||||||
|
|
||||||
|
if (cmd.compare(0, strlen(EVENT_SCROLL_UP), EVENT_SCROLL_UP) == 0) {
|
||||||
scrolldir = m_revscroll ? "prev" : "next";
|
scrolldir = m_revscroll ? "prev" : "next";
|
||||||
} else if (cmd.compare(0, strlen(EVENT_SCROLL_DOWN), EVENT_SCROLL_DOWN) == 0) {
|
} else if (cmd.compare(0, strlen(EVENT_SCROLL_DOWN), EVENT_SCROLL_DOWN) == 0) {
|
||||||
scrolldir = m_revscroll ? "next" : "prev";
|
scrolldir = m_revscroll ? "next" : "prev";
|
||||||
@ -217,15 +219,30 @@ namespace modules {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const string& mon_name{m_bar.monitor->name};
|
auto workspaces = i3_util::workspaces(conn, m_bar.monitor->name);
|
||||||
|
auto current_ws_iter = find_if(workspaces.begin(), workspaces.end(),
|
||||||
|
[](auto ws) { return ws->focused || ws->visible; });
|
||||||
|
auto target_ws_iter = current_ws_iter;
|
||||||
|
|
||||||
if (scrolldir == "next" && (m_wrap || *workspaces(conn, mon_name).back() != *focused_workspace(conn))) {
|
if (scrolldir == "next") {
|
||||||
m_log.info("%s: Sending workspace next command to ipc handler", name());
|
if (*current_ws_iter == workspaces.back() && m_wrap) {
|
||||||
conn.send_command("workspace next_on_output");
|
target_ws_iter = workspaces.begin();
|
||||||
} else if (scrolldir == "prev" && (m_wrap || *workspaces(conn, mon_name).front() != *focused_workspace(conn))) {
|
} else if (*current_ws_iter != workspaces.back()) {
|
||||||
m_log.info("%s: Sending workspace prev command to ipc handler", name());
|
target_ws_iter = std::next(current_ws_iter);
|
||||||
conn.send_command("workspace prev_on_output");
|
|
||||||
}
|
}
|
||||||
|
} else if (scrolldir == "prev") {
|
||||||
|
if (*current_ws_iter == workspaces.front() && m_wrap) {
|
||||||
|
target_ws_iter = std::prev(workspaces.end());
|
||||||
|
} else if (*current_ws_iter != workspaces.front()) {
|
||||||
|
target_ws_iter = std::prev(current_ws_iter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current_ws_iter != target_ws_iter) {
|
||||||
|
m_log.info("%s: Sending workspace focus command to ipc handler", name());
|
||||||
|
conn.send_command("workspace " + (*target_ws_iter)->name);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (const exception& err) {
|
} catch (const exception& err) {
|
||||||
m_log.err("%s: %s", name(), err.what());
|
m_log.err("%s: %s", name(), err.what());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user